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:
ABCDefine an object that can save/load arbitrary objects to files.
- abstractmethod unpickle(path)[source]
Unpickle (“load”) the given path to recreate original object.
- _abc_impl = <_abc._abc_data object at 0x76a868ba0f00>
- class MyCloudPickler[source]
Bases:
MyPicklerDefine a
MyPicklerthat can handle modules and lambda functions.This pickler should not raise errors, but all attributes may not be properly re-created.
- _abc_impl = <_abc._abc_data object at 0x76a868b82380>