An Overview of PythonPDEVS
An Overview of PythonPDEVS
[email protected]
[email protected]
Simulated time
realtime
PythonPDEVS supports a wide set of features, 3 (scale = 1)
similar to those found in other high-level DEVS
simulation tools. While there is no graphical 2
front-end, some work has been done on this
scaled realtime
by [7, 8, 11]. Many of the features supported by 1 (scale < 1)
other tools, and more, become available through
the use of these extensions. 0
0 1 2 3 4
Table 1 presents an overview of the features,
Wallclock time
and the cases in which they are supported.
PythonPDEVS supports three modes of ex- Figure 1: Realtime versus as-fast-as-possible
ecution: Sequential As-fast-as-possible (Seq. simulation.
AFAP), Sequential Realtime (Seq. RT), and
Distributed As-fast-as-possible (Dist. AFAP).
Note that distributed realtime is not supported at Table 1: Supported features in each situations.
all. Due to the different characteristics of each
Dist. AFAP
Seq. AFAP
mode of execution, some features are selec-
Seq. RT
tively available. For the not implemented fea-
tures, we could not find a useful enough appli-
cation to warrant the significant effort required.
Classic DEVS Y Y N
For distributed simulation, Time Warp [12] Parallel DEVS Y Y Y
is used to provide optimistic synchronization. Dynamic Structure DEVS Y Y N
With Time Warp, each distributed node will Tracing Y Y Y
simulate ahead in time, in the assumption that Checkpointing Y N Y
no causality errors will occur. Should such an Nested simulation Y Y N
error occur (i.e., a message from the past ar- Termination condition Y Y Y
rives), the simulation state is rolled back to the Livelock detection Y Y Y
point in time where the message was supposed Transfer functions Y Y Y
to arrive. This allows for parallelism, as all
nodes can simulate independently, but incurs as the system allows. Realtime simulation is
two kinds of overhead: a fixed one, to store mainly used when coupling the model with
each intermediate simulation state, and a vari- other realtime components, whereas as-fast-as-
able one, to roll back the simulation state when possible simulation is used when only the sim-
a causality error is detected. ulation results matter.
In realtime simulation, the simulated time is The remainder of this section will briefly de-
coupled with the wall-clock time, as shown in scribe each feature, as well as why it is relevant
Figure 1. This means that in a single sec- for users to have this feature.
ond of wall-clock time, the simulation will also
progress exactly a single second. Scaled vari- Classic DEVS Classic DEVS refers to the origi-
ants of this are possible, for example that each nal DEVS formalism defined by [13]. It is still a
second in wall-clock time causes a progres- viable formalism, and is still preferred by some
sion of four seconds in simulated time. This people due to its simplicity. There is also not
is in contrast to as-fast-as-possible simulation, that much opportunity for parallelism and effi-
where the simulation simply progresses as fast cient execution. For performance reasons, most
tools no longer support Classic DEVS, however. higher the chance that it will be abruptly termi-
Due to difficulty with global synchronization, nated due to hardware failure. Distributed sim-
there is also no distributed variant of Classic ulations are even more prone to hardware fail-
DEVS implemented in PythonPDEVS. ure, as they also introduce network communi-
cation. Especially for such big simulations, it
Parallel DEVS Parallel DEVS [14] is an exten- is important to be able to continue a simulation
sion of Classic DEVS, which, as the name im- after it was abruptly terminated. This is pos-
plies, offers more options for parallel execution. sible through checkpointing, where the current
Apart from the prospect of parallel execution, simulation state is periodically stored. Should
there are also some additional optimizations in simulation terminate abruptly, it is possible to
place that allow for faster execution, even dur- continue simulation, without any loss of infor-
ing sequential execution. It is now becoming mation, by restoring that snapshot. This feature
the default DEVS formalism implemented by is not supported in realtime simulation, as stor-
tools, and is also the default in PythonPDEVS. ing the current simulation state introduces sig-
nificant and unpredictable delays in the simula-
Dynamic Structure DEVS Dynamic Structure tion. Furthermore, it is difficult to conceive the
DEVS [15] is another extension of DEVS (both semantics of restoring a crashed realtime sim-
Classic DEVS and Parallel DEVS), where the ulation: the linear relation between wall-clock
model can be reconfigured at runtime. Some time and simulation time is broken.
models, such as those where entities are created
and destroyed during simulation, lend them- Nested simulation In case the execution of the
selves much better to these cases, and are there- current model depends on the simulation of an-
fore best expressed using Dynamic Structure other model (possibly an abstracted model of
DEVS. PythonPDEVS does not support Dy- the current model), it is useful to allow for
namic Structure DEVS during distributed sim- nested simulation. The currently running sim-
ulation, since this opens up the possibility for ulation is suspended, and the nested simulation
connections to change as well, which can have is started. After simulation, the result of the
catastrophic results in optimistic synchroniza- nested simulation is used to define some aspects
tion if not handled well. of the currently running simulation. Python-
PDEVS supports this feature thanks to a clear
Tracing One of the most important artifacts of design, which avoids the use of global and static
simulation is the simulation trace, which con- variables. For distributed simulation, it is possi-
tains the simulation results. Different users ble to nest a sequential simulation inside a dis-
need different traces: some prefer textual traces, tributed simulation, but it is not possible to nest
whereas others want visual traces (e.g., plots of a distributed simulation in another simulation.
the evolution of a value). In PythonPDEVS, While not impossible to implement, synchro-
multiple tracers can be plugged in, which are in- nization overhead is significant, and would re-
voked at every transition that needs to be traced. quire seperate synchronization algorithms.
Several are provided out-of-the-box, with the
most helpful one being a normal textual trace. Termination condition While most simulation
Visual tracers are provided as well. Users can kernels nowadays support the use of a termi-
easily define their own tracers, which are in- nation time, PythonPDEVS also supports the
voked at every simulation step. use of a termination condition. In this case, a
special function is invoked before each simula-
Checkpointing Simulation of big models can tion step, which determines whether simulation
take a long time, even using a fast simula- should terminate or not. This termination func-
tion kernel. The longer a simulation takes, the tion has access to the current simulation state
and the current simulation time (to allow for PythonPDEVS therefore contains many inter-
time-based termination). This causes a signif- nal optimizations, mainly focused on the use
icant overhead in the general case, but offers of “leaky abstraction”. DEVS models are op-
more possibilities to the user. For example in tionally augmented with domain-specific hints,
design space exploration, we want to quickly which offer domain-specific knowledge about
prune models that don’t fulfill some basic re- the model to the simulation kernel. Normally,
quirements, which is only possible by checking a DEVS simulation kernel is unaware of the
these conditions at simulation time. domain of the model it is simulating, and can
therefore not use more efficient, but less gen-
Livelock detection One of the problems that re- eral, algorithms.
main in the DEVS formalism, is the possibil-
Due to space restrictions, we did not include
ity of a time advance equal to zero. While
performance results here, but we refer to previ-
this is not a fundamental problem, and is neces-
ous work [9, 10]. Using intrusive features (e.g.,
sary for some situations, it is possible that they
tracing, checkpointing) affects performance.
form a loop. In such a loop, simulation live-
locks as the simulation never progresses in sim- Table 2 shows an overview of our applied opti-
ulated time. Since simulation time no longer mizations, and when they are applicable. Some
progresses, simulation of the model will never optimizations are not applicable in all modes
terminate, even though models keep being ex- of execution, as some focus on the problems
ecuted. Static analysis is difficult, if not im- arising from distributed simulation. Again, dis-
possible, since the time advance depends on the tributed realtime simulation is not supported
current simulation state, which is unknown be- and thus not shown.
forehand. PythonPDEVS monitors model ex-
ecution, and aborts execution if the simulation Some of these optimizations are also imple-
time has not increased after a sufficient number mented in other DEVS simulation tools, such
of transitions. This method sometimes marks as direct connection [16].
fine models as erroneous (i.e., allows for false
positives), but will certainly terminate a locked
simulation (i.e., no false negatives).
Table 2: Performance optimizations applied in
Transfer functions Despite the fact that all vari- each situations.
ants of the DEVS formalism define the possi-
Dist. AFAP
Seq. AFAP
Event copy hints When an atomic model creates In future work, we will consider usability of
events, care should be taken not to break mod- our tool, going further in the direction of the
ularity, as these events potentially contain ref- AToMPM DEVSDebugger [8]. We will focus
erences or pointers to the state of other mod- our efforts on five aspects: (1) modelling and
els. The host language (e.g., Python or C++) simulation environment, allowing for easy cre-
has no way of knowing that this is not allowed ation and simulation of models, (2) library of
in DEVS, and will therefore allow these oper- DEVS models, which allows the sharing and
ations. Such tricks, however, are in violation reuse of DEVS models, (3) debugging environ-
with the DEVS formalism, and should be con- ment, which transposes most of the features of
sidered abuse of the host language. In Python- code debugging to the world of model debug-
PDEVS, events are therefore copied by default, ging, (4) experiment design environment, al-
such that each model receives a seperate copy lowing the graphical definition of experiments
of the event. While this is nice to have for peo- as well, and (5) efficient simulation, making the
ple new to DEVS, it causes performance prob- tool applicable in more situations.
lems in both time and space. Therefore, there
Acknowledgments :
are three main options in PythonPDEVS: either This work was partly funded by a PhD fellowship from
the messages are naively copied (default), either the Research Foundation - Flanders (FWO). Partial sup-
port by the Flanders Make strategic research centre for
they are not copied at all (for performance), or the manufacturing industry is also gratefully acknowl-
a user-specified function is invoked to perform edged.
References 2015 Spring Simulation Multiconference,
ser. SpringSim ’15. Society for Com-
[1] J. J. Nutaro, “adevs,” puter Simulation International, 2015, pp.
http://www.ornl.gov/ 1qn/adevs/, 2015. 844–851.
[2] G. Quesnel, R. Duboz, E. Ramat, and [11] B. Barroca, S. Mustafiz, S. Van Mierlo,
M. K. Traoré, “VLE: a multimodeling and and H. Vangheluwe, “Integrating a Neu-
simulation environment,” in Proceedings tral Action Language in a DEVS Mod-
of the 2007 summer computer simulation elling Environment,” in Proceedings of
conference, 2007, pp. 367–374. the 8th International ICST Conference
[3] G. Wainer, “CD++: a toolkit to develop on Simulation Tools and Techniques, ser.
DEVS models,” Software: Practice and SIMUTools ’15, 2015.
Experience, vol. 32, no. 13, pp. 1261– [12] R. M. Fujimoto, Parallel and Distribution
1306, 2002. Simulation Systems, 1st ed. John Wiley
[4] J. K. Ousterhout, “Scripting: Higher- & Sons, Inc., 1999.
Level Programming for the 21st Century,” [13] B. P. Zeigler, H. Praehofer, and T. G.
Computer, vol. 31, no. 3, pp. 23–30, 1998. Kim, Theory of Modeling and Simulation,
[5] C. Seo, B. P. Zeigler, R. Coop, and 2nd ed. Academic Press, 2000.
D. Kim, “DEVS modeling and simulation [14] A. C. H. Chow and B. P. Zeigler, “Paral-
methodology with MS4Me software,” in lel DEVS: a parallel, hierarchical, modu-
Symposium on Theory of Modeling and lar, modeling formalism,” in Proceedings
Simulation - DEVS (TMS/DEVS), 2013. of the 26th conference on Winter simula-
[6] M. H. Hwang, “X-S-Y,” tion, 1994, pp. 716–722.
https://code.google.com/p/x-s-y/, 2012. [15] F. J. Barros, “Modeling formalisms for dy-
[7] L. Capocchi, J. F. Santucci, B. Poggi, and namic structure systems,” ACM Transac-
C. Nicolai, “DEVSimPy: A collaborative tions on Modeling and Computer Simula-
python software for modeling and simula- tion, vol. 7, pp. 501–515, 1997.
tion of DEVS systems,” in Workshop on [16] A. Muzy and J. J. Nutaro, “Algorithms
Enabling Technologies: Infrastructure for for efficient implementations of the DEVS
Collaborative Enterprises, 2011, pp. 170– & DSDEVS abstract simulators,” in 1st
175. Open International Conference on Mod-
[8] S. Van Mierlo, Y. Van Tendeloo, B. Bar- eling and Simulation (OICMS), 2005, pp.
roca, S. Mustafiz, and H. Vangheluwe, 273–279.
“Explicit Modelling of a Parallel DEVS [17] B. Chen and H. Vangheluwe, “Symbolic
Experimentation Environment,” in Pro- flattening of DEVS models,” in Sum-
ceedings of the 2015 Spring Simulation mer Simulation Multiconference, 2010,
Multiconference, ser. SpringSim ’15. So- pp. 209–218.
ciety for Computer Simulation Interna- [18] A. C. H. Chow, B. P. Zeigler, and D. H.
tional, 2015, pp. 860–867. Kim, “Abstract simulator for the paral-
[9] Y. Van Tendeloo and H. Vangheluwe, lel DEVS formalism,” in AI, Simulation,
“The modular architecture of the and Planning in High Autonomy Systems,
Python(P)DEVS simulation kernel,” 1994, pp. 157–163.
in Proceedings of the 2014 Symposium [19] Y. Van Tendeloo, “Activity-aware DEVS
on Theory of Modeling and Simulation - simulation,” Master’s thesis, University of
DEVS, 2014, pp. 387–392. Antwerp, Antwerp, Belgium, 2014.
[10] Y. Van Tendeloo and H. Vangheluwe, [20] Y. Van Tendeloo and H. Vangheluwe, “Ac-
“PythonPDEVS: a distributed Parallel tivity in PythonPDEVS,” in Proceedings
DEVS simulator,” in Proceedings of the of ACTIMS 2014, 2014.