Serialize

load

The deserializer entrypoint for objects saved with the save method.

save

Save a serialized set of data to file for later deserialization.

load

mrmustard.utils.serialize.load(file, remove_after=False)[source]

The deserializer entrypoint for objects saved with the save method.

Parameters:
  • file (Path) – The json file to load from

  • remove_after (Optional[bool]) – Once load is complete, delete the saved file. Default is False

save

mrmustard.utils.serialize.save(cls, filename=None, do_zip=True, arrays=None, **data)[source]

Save a serialized set of data to file for later deserialization.

This function can serialize any object that implements the MrMustard serialization interface, which is the following:

@classmethod
def deserialize(cls, data: dict) -> cls

Though not required to satisfy the interface, it is conventional for a class to implement an instance method called serialize that takes no arguments, calls this function with its data, and returns the Path result.

Parameters:

cls (type) – The object type being serialized

Keyword Arguments:
  • filename (str) – A custom filename to save the data to

  • do_zip (bool) – If arrays are provided, zip results

  • arrays (Dict[str, NDArray]) – A dict of array-like objects to be serialized

  • data (Dict[Any, Any]) – A JSON-serializable dict of arbitrary data to save

Returns:

the path to the saved object, to be retrieved later with load

Return type:

Path