Functionality for saving and loading of complete Mpacts simulations.

This module provides two main functions: and for saving and loading a full mpacts simulation tree. Doing so will normally ensure that the complete state of the simulation will be serialized.

Example usage:

import as sl
import mpacts.core.simulation as sim

name = 'example_simulation'
oldsim = sim.Simulation(name, timestep=1.0) oldsim, name+".mpacts" )

newsim = sl.load(name+".mpacts")



Although similar in behavior, the functionality of save_load is completely different than the functionality of The latter provides an efficient and convenient format to save the simulated data (arrays, properties, ...) during and after a simulation, for post-processing purposes.

save_load is a much more elaborate (and also computationally more costly) tool that reconstructs a full dependency tree of the simulation, and stores everything that can be stored including arrays, properties and contact states.


save() only stores whatever is in the simulation tree. Of course it cannot know everything that is defined in your local Python script. Make sure that parameters or important data are saved for example as mpacts.core.valueproperties.Variable to ensure their persistence when re-loading.

One particular exception which is NOT saved but still is in the simulation tree is a local PythonCommand, i.e. a PythonCommand that is not defined somewhere in the Mpacts API, but in the local script for running the simulation itself. If you want to re-introduce such a command when reloading, it is important that the resuming script redefines this command.

In order to be able to use this module import it like this:

#or assign it to a shorter name
import as sav


class, gate, filename, allowZip64=False)

Bases: mpacts.core.command.PythonCommand

SaveCommand(name, parent, **kwargs)
execute(), dicts, zf), dicts, zf), dicts), state, adict), constr_def), verbose=True, allowZip64=False, parent=None)

Function to read in a given file and from it reconstruct (load) an Mpacts simulation tree

  • filename (str) – Name of the file that is to be loaded
  • verbose (bool) – If True, the loading will report its progress
  • parent (obj) – If given, the loaded object will be made as a child of the given parent

An Mpacts tree of whatever was saved (for example an mpacts.core.simulation.Simulation), adict), filename, allowZip64=False)

Function to save a given simulation tree as a file with a given name.

  • rootnode (instance of mpacts.core.baseobject.BaseObject) – Root node of an Mpacts tree below (and including) which everything will be saved
  • filename (str) – Full name of the save file., name, oldid, dicts)