Simulator¶
-
pypdevs.simulator.
loadCheckpoint
(name)[source]¶ Load a previously created simulation from a saved checkpoint.
- Parameters
name – the name of the model to provide some distinction between different simulation models
- Returns
either None if no recovery was possible, or the Simulator object after simulation
-
pypdevs.simulator.
local
(sim)[source]¶ Test whether or not the simulation is done locally
- Parameters
sim – the simulator with the locations
- Returns
bool – whether or not the simulation is local
-
class
pypdevs.simulator.
Simulator
(model)[source]¶ Associates a hierarchical DEVS model with the simulation engine.
-
__init__
(model)[source]¶ Constructor of the simulator.
- Parameters
model – a valid model (created with the provided functions)
-
drawModelConnections
(outfile, model, colors=None)[source]¶ Draws all necessary connections between the model
- Parameters
outfile – the file to output to
model – a CoupledDEVS model whose children should be drawn
colors – the colors to draw on the connections. Only used when an initial allocator is used.
-
drawModelHierarchy
(outfile, model)[source]¶ Draws the hierarchy by creating a Graphviz Dot file. This merely creates the first part: the hierarchy of all models
- Parameters
outfile – a file handle to write text to
model – the model to draw
-
loadCheckpoint
()[source]¶ Alert the Simulator that it was restored from a checkpoint and thus can take some shortcuts
-
loadLocationsFromFile
(filename)[source]¶ Try to load a file containing the allocation of the nodes. If such a (valid) file is found, True is returned. Otherwise False is returned.
This can thus easily be used in a simulator experiment file as a condition for setting an allocator (e.g. check for an allocation file and if none is found, create one by running the allocator first).
A partially valid file will not be used; a file does not need to specify an allocation for all models, those that aren’t mentioned are simply skipped and their default allocation is used (as specified in the model itself).
- Parameters
filename – the name of the file to use
- Returns
bool – success of the operation
-
modifyAttributes
(model_id, attr, value)[source]¶ Modify an attribute of a specific model.
Do NOT call this method directly, but call it through the simconfig interface
- Parameters
model_id – the model_id of the model to modify the state from
attr – the name of the attribute of the model to modify
value – the value to set as attribute
-
modifyState
(model_id, state)[source]¶ Modify the state of a specific model.
Do NOT call this method directly, but call it through the simconfig interface
- Parameters
model_id – the model_id of the model to modify the state from
state – the state to configure
-
modifyStateAttr
(model_id, attr, value)[source]¶ Modify an attribute of the state of a specific model.
Do NOT call this method directly, but call it through the simconfig interface
- Parameters
model_id – the model_id of the model to modify the state from
attr – the name of the attribute of the state to modify
value – the value to set as attribute
-
real_simulate
()[source]¶ The actual simulation part, this is identical for the ‘start from scratch’ and ‘start from checkpoint’ algorithm, thus it was split up
-
realtime_interrupt
(string)[source]¶ Generate an interrupt for the realtime backend using a method call.
- Parameters
string – the value to interrupt with, should be of the form “port value”
-
reinit
()[source]¶ Reinitialize the model, so that a new simulate() call will restart the simulation anew. This is possible in both local and distributed simulation, though it requires the setAllowLocalReinit method to be called first if you are running local simulation.
The additional method call is required as allowing reinitialisation requires the complete model to be saved twice (a reinit copy and a working copy).
Do NOT call this method directly, but call it through the simconfig file
-
showProgress
(locations)[source]¶ Shows the progress of the simulation by polling all locations that are passed. Should run on a seperate thread as this blocks!
- Parameters
locations – list of all locations to access
-