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 MyPickler[source]

Bases: ABC

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

abstract pickle(my_object, path)[source]

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

Parameters:
Return type:

None

abstract unpickle(path)[source]

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

Parameters:

path (Path | str)

Return type:

object

_abc_impl = <_abc._abc_data object at 0x73dcd30cd340>
class MyCloudPickler[source]

Bases: MyPickler

Define a MyPickler that can handle modules and lambda functions.

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

__init__()[source]

Import the necessary module.

pickle(my_object, path)[source]

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

Parameters:
Return type:

None

unpickle(path)[source]

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

Parameters:

path (Path | str)

Return type:

object

_abc_impl = <_abc._abc_data object at 0x73dca869ed00>