itwinai.serialization

itwinai.serialization.is_jsonable(x)[source]
itwinai.serialization.fullname(o)[source]
exception itwinai.serialization.SerializationError[source]

Bases: Exception

Serialization error

class itwinai.serialization.Serializable[source]

Bases: object

parameters: Dict[Any, Any] = None

Dictionary storing constructor arguments. Needed to serialize the class to dictionary. Set by self.save_parameters() method.

save_parameters(**kwargs) None[source]

Simplified way to store constructor arguments in as class attributes. Keeps track of the parameters to enable YAML/JSON serialization.

static locals2params(locals: Dict, pop_self: bool = True) Dict[source]

Remove self from the output of locals().

Parameters:
  • locals (Dict) – output of locals() called in the constructor of a class.

  • pop_self (bool, optional) – whether to remove self. Defaults to True.

Returns:

cleaned locals().

Return type:

Dict

update_parameters(**kwargs) None[source]

Updates stored parameters.

to_dict() Dict[source]

Returns a dict serialization of the current object.

to_json(file_path: str | Path, nested_key: str) None[source]

Save a component to JSON file.

Parameters:
  • file_path (Union[str, Path]) – JSON file path.

  • nested_key (str) – root field containing the serialized object.

to_yaml(file_path: str | Path, nested_key: str) None[source]

Save a component to YAML file.

Parameters:
  • file_path (Union[str, Path]) – YAML file path.

  • nested_key (str) – root field containing the serialized object.

class itwinai.serialization.ModelLoader(model_uri: str)[source]

Bases: ABC, Serializable

Loads a machine learning model from somewhere.