util.pickling module

Define a class to pickle objects.

“pickling” a file comes down to saving it in binary format. It can be loaded and used again later, even with a different Python instance. This is useful when you want to study a Fault that took a long time to be compensated, or a SimulationOutput obtained by a time-consuming TraceWin multiparticle simulation.

Warning

This a very basic pickling. Do not use for long-term storage, but for debug only.

Note

Some attributes such as lambda function in FieldMap or modules in SimulationOutput cannot be pickled by the built-in pickle module. I do not plan to refactor them, so for now we stick with cloudpickle module.

Some objects have built-in pickle and unpickle methods, namely:

class MyCloudPickler

Bases: MyPickler

Define a Pickler that can handle modules and lambda functions.

This pickler should not raise errors, but all attributes may not be properly re-created.

__init__() None

Import the necessary module.

_abc_impl = <_abc._abc_data object>
pickle(my_object: object, path: Path | str) None

Pickle (“save”) the object to a binary file.

unpickle(path: Path | str) object

Unpickle (“load”) the given path to recreate original object.

class MyPickler

Bases: ABC

Define an object that can save/load arbitrary objects to files.

_abc_impl = <_abc._abc_data object>
abstract pickle(my_object: object, path: Path | str) None

Pickle (“save”) the object to a binary file.

abstract unpickle(path: Path | str) object

Unpickle (“load”) the given path to recreate original object.