Serialization

pathsim.utils.serialization.serialize_callable(func)[source]

Serialize a callable with priority for human-readable formats

Parameters:

func (callable) – function to serialize into dict

Returns:

serialized function

Return type:

dict

pathsim.utils.serialization.serialize_object(obj)[source]

Serialize any object by capturing its module and class

Parameters:

obj (object) – object to serialize into dict

Returns:

serialized object

Return type:

dict

pathsim.utils.serialization.deserialize(data)[source]

Deserialize an object from dictionary representation

Parameters:

data (dict) – dict to deserialize into object

Returns:

python object recovered from dict

Return type:

object

class pathsim.utils.serialization.Serializable[source]

Bases: object

Mixin that provides automatic serialization based on __init__ parameters and loading/saving to json formatted readable files

save(path='', **metadata)[source]

Save the dictionary representation of object to an external file

Parameters:
  • path (str) – filepath to save data to

  • metadata (dict) – metadata for the object

classmethod load(path='', **kwargs)[source]

Load and instantiate an object from an external file in json format

Parameters:
  • path (str) – filepath to load data from

  • kwargs (dict) – additional kwargs for object reconstruction

Returns:

out – reconstructed object from dict representation

Return type:

obj

classmethod from_dict(data, **kwargs)[source]

Create block instance from dictionary representation.

Parameters:
  • data (dict) – representation of object

  • kwargs (dict) – additional kwargs for object reconstruction

Returns:

out – reconstructed object from dict representation

Return type:

obj

to_dict(**metadata)[source]

Convert object to dictionary representation