View in #questions on Slack
@Osama_Abu_Hamdan: Hello,
I am trying to return a List[int|float] of collected metrics from a client to the server when get_properties is called.
I get this error
TypeError: There is not a 1:1 mapping between `common.Scalar` types and those supported in `common.ConfigRecordValues` or `common.ConfigRecordValues`. Consider casting your values to a type supported by the `common.RecordDict` infrastructure. You used type: <class 'list'>
I checked the code and it only accepts scalars to be in return values. Any other way to pass metrics from client to server?
Best
@Chong_Shen: @Javier Can you please help with this question?
@Javier: Hi @Osama_Abu_Hamdan, returing a list is not supported. Only those types of type Scalar are supported. If you want to communicate a list I’d recommend you serialize it as a JSON for instance. Like this:
import json
def get_properties(self, config):
# Original list of integers
original_list = [1, 2, 3, 4, 5]
# Serialize to string
json_string = json.dumps(original_list)
return {'my_property': json_string}
Then, on the receiving end (likely in your strategy) you just need to deserialize it:
# Deserialize back to list
restored_list = json.loads(json_string)
I hope this helps!!!