You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need function to serialize and deserialize etna objects to dict for experiments, cli and platform.
For now we can generate etna objects with hydra_slayer.get_from_params but we can't reverse that transformation.
Proposal
Add to_dict method to BaseMixin, which will save etna object in hydra-core, hydra-slayer format.
In some cases for example ChangePointsTrendTransform we have external objects as input parameters:
For sklearn BaseEstimator we can get parameters with BaseEstimator.get_parameters
For other cases: we should leave knowledge of _target_ class only and raise warning with the name of field.
For inspiration you can look at __repr__ implementation or at to_json:
def to_json(self):
"""Library objects to json representation.
Returns
-------
Dict with object allenai-common representation.
"""
class_to_name = {}
self.reversed_index(Registrable._registry, class_to_name)
json_config = {}
init_args = inspect.signature(self.__init__).parameters
json_config["type"] = class_to_name[self.__class__]
for arg, param in init_args.items():
if param.kind == param.VAR_POSITIONAL:
continue
value = self.__dict__[arg]
if param.kind == param.VAR_KEYWORD:
json_config.update(value)
elif getattr(value, "to_json", None) is not None:
json_config[arg] = value.to_json()
elif value.__class__ in class_to_name:
json_config[arg] = {"type": class_to_name[value.__class__]}
elif isinstance(value, tuple) or isinstance(value, list):
json_config[arg] = [item if not isinstance(item, BaseMixin) else item.to_json() for item in value]
else:
json_config[arg] = value
return json_config
Test cases
Pipeline, model, metrics, transforms (choose some not trivial cases: ChangePointsTrendTransform for example) with to_dict and hydra_slayer.get_from_params initialize the same object
check that ensembles are working with to_dict correctly
check that warning is arised in case of non etna-sklearn models.
🚀 Feature Request
We need function to serialize and deserialize etna objects to dict for experiments, cli and platform.
For now we can generate etna objects with
hydra_slayer.get_from_params
but we can't reverse that transformation.Proposal
to_dict
method toBaseMixin
, which will save etna object in hydra-core, hydra-slayer format.ChangePointsTrendTransform
we have external objects as input parameters:BaseEstimator.get_parameters
_target_
class only and raise warning with the name of field.__repr__
implementation or atto_json
:Test cases
Pipeline
,model
,metrics
,transforms
(choose some not trivial cases: ChangePointsTrendTransform for example) with to_dict and hydra_slayer.get_from_params initialize the same objectto_dict
correctlyAdditional context
Example of Pipeline:
The text was updated successfully, but these errors were encountered: