<
From version < 4.1 >
edited by aas2
on 2017/08/03 13:47
To version < 8.1 >
edited by aas2
on 2017/10/23 16:34
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -4,6 +4,8 @@
4 4  
5 5  {{toc/}}
6 6  
7 +----
8 +
7 7  == Overview ==
8 8  
9 9  After a model has been created, it is reasonable to test if the model does what is expected. This can be achieved by simulating the model. The simulation must
... ... @@ -12,11 +12,11 @@
12 12  * Execute a tick
13 13  * Send generated outputs
14 14  
15 -Thus the simulation can be seen as a black box, which receives a state for the model, somehow computes a reaction, and communicates its new state to the outside. The communication for receiving and sending the state of the model is done using JSON. For example, in KIELER a simulation can be started by starting an executable file. The JSON communication is then done on stdin and stdout of the running process.
17 +Thus the simulation can be seen as a black box, which receives a state for the model, somehow computes a reaction, and communicates its new state to the outside. In KIELER the communication for receiving and sending the state of the model is done using JSON. When starting the executable file of a simulation in KIELER, the JSON communication is done on stdin and stdout of the running process.
16 16  
17 17  Within KIELER a single state of a simulation is represented as a //Data Pool//. A data pool can have multiple models. Each model can have multiple variables. Thus a representation of a complete run of a simulation can be implemented as list of data pools.
18 18  
19 -Executables for simulation are created using the incremental project builder that is part of the project management. The typical steps to create an executable are:
21 +Executables for simulation are created using the incremental project builder that is part of the project management. The typical steps to create an executable for simulation are:
20 20  
21 21  * Compiling a model using the KIELER compiler
22 22  * Generating the simulation wrapper code for the model using template processing
... ... @@ -24,9 +24,11 @@
24 24  
25 25  For more insight of the simulation generation, please take a look at the [[doc:V2 Project Management]].
26 26  
29 +----
30 +
27 27  == Using the Simulation ==
28 28  
29 -Besides the explicit configuration of a simulation using a kisim file, it is possible to start simulations directly on models, executables or trace files. This will start a pre-defined configuration depending on the selected files. The following table shows which files can be started as simulation and what simulation configuration is created for it.
33 +Besides the explicit configuration of a simulation using a kisim file, it is possible to start simulations directly on models, executables or trace files. This will start a pre-defined configuration depending on the selected files. The following table shows which files can be used to start a simulation and what simulation configuration is created for it.
30 30  
31 31  (% class="relative-table wrapped" style="width: 99.9453%;" %)
32 32  |=(((
... ... @@ -39,7 +39,7 @@
39 39  )))
40 40  |(% colspan="1" %)(% colspan="1" %)
41 41  (((
42 -executable
46 +1 executable
43 43  )))|(% colspan="1" %)(% colspan="1" %)
44 44  (((
45 45  Sim_ModelA.exe
... ... @@ -61,7 +61,7 @@
61 61  )))
62 62  |(% colspan="1" %)(% colspan="1" %)
63 63  (((
64 -kisim file
68 +1 kisim file
65 65  )))|(% colspan="1" %)(% colspan="1" %)
66 66  (((
67 67  ComplexSimulation.kisim
... ... @@ -81,7 +81,7 @@
81 81  )))
82 82  |(% colspan="1" %)(% colspan="1" %)
83 83  (((
84 -simin file
88 +1 simin file
85 85  )))|(% colspan="1" %)(% colspan="1" %)
86 86  (((
87 87  process_output.simin
... ... @@ -91,24 +91,24 @@
91 91  )))
92 92  |(% colspan="1" %)(% colspan="1" %)
93 93  (((
94 -simout file
98 +1 simout file
95 95  )))|(% colspan="1" %)(% colspan="1" %)
96 96  (((
97 97  simulation_output.simout
98 98  )))|(% colspan="1" %)(% colspan="1" %)
99 99  (((
100 -The current pool of the simulation is written as JSON object to the simout file.
104 +A model of the simulation is written as JSON object to the simout file.
101 101  )))
102 102  
103 103  === Playing the Simulation ===
104 104  
105 -Besided manually stepping through the simulation tick after tick, it is possible to let the simulation play automatically. In play mode, a macro tick is performed after a given time, which can be defined in the data pool view (e.g. to perform a tick every 200ms).
109 +One can step through the simulation tick after tick. Furthermore it is possible to let the simulation step automatically. This is the //play mode//, in which a macro tick is performed after a given time, which can be defined in the data pool view (e.g. to perform a tick every 200ms).
106 106  
107 107  === Stepping Back in the Simulation ===
108 108  
109 -When clicking the //Step Back// button, the values of a former tick are set in the data pool view as user values, which will be assigned to the model before the next tick is executed.
113 +When clicking the //Step Back// button, the values of a former tick are set in the data pool view as user values, which will be assigned to the model before the next tick is executed. Thus it is possible to revert the simulation to a previous state if all variables that define this state are recorded in the data pool.
110 110  
111 -This it is possible to revert a model to a previous state if all variables that define the current state of this model are recorded in the data pool.
115 +When stepping back and forth in the simulation history, the position in the history is shown next to the current tick count in the Data Pool View. For example, when the simulation is after tick 5 and one steps two ticks back in the simulation history, this will be indicated as the tick **#5 (-2)**. If a tick is performed now using the old state, the values of tick 5 - 2 = 3 are applied and the new outputs are computed so that the simulation is now after tick **#4**.
112 112  
113 113  === The Data Pool View ===
114 114  
... ... @@ -116,20 +116,24 @@
116 116  
117 117  In the view, the variable values can be modified by the user via clicking the column //User Value//. If a user value is specified for a variable, the corresponding row is highlighted and marked with an asterisk ( * ) . The value is applied to the variable and send to the model before the next tick is performed.
118 118  
119 -When using traces in the simulation, a trace mismatch of a variable will be highlighted in the data pool view. A tooltip on the //Current Value// column shows details about the mismatch. The trace mismatch is kept between ticks. To clear a mismatch, use the menu of the view and select //Clear Trace Mismatches//.
123 +When using traces in the simulation, a trace mismatch of a variable will be highlighted in the data pool view. A tooltip on the //Current Value// column shows details about the mismatch. The trace mismatch is kept between ticks. To clear a mismatch, use the menu of the view and select //Clear Trace Mismatches// from the view's menu.
120 120  
121 -When the data pool view is selected, stepping through the simulation can be done using the right arrow on the keyboard, which is often more useful than clicking the corresponding button in the toolbar.
125 +When the data pool view is selected, stepping through the simulation can be done using the RIGHT arrow on the keyboard, which is often more useful than clicking the corresponding button in the toolbar. Furthermore the SPACE key will play/pause the simulation and with CTRL+LEFT (respectively CTRL+RIGHT) one can step back (step forward) in the simulation history.
122 122  
127 +----
128 +
123 123  == Data Handlers ==
124 124  
125 -A simulation consists of a list of //data handlers//, that can read or write the current data pool. A macro tick in the simulation then consists of the execution of the read or write actions on these data handlers. Performing a single action on a data handler is called a //sub tick// and typically not necessary but can be useful to see the effect of single data handlers on the data pool.
131 +A simulation consists of a list of //data handlers//. These perform actions on the data pool. When the actions of all data handlers for a simulation have been executed, then this is a single full macro tick. In contrast performing only a single action on one data handler is called a //sub tick// and typically not necessary when using the simulation. However stepping through the data handler actions one by one can be useful to see the effect of each action on the data pool.
126 126  
127 127  Which handlers are available are explained in the following.
128 128  
129 129  === Executable ===
130 130  
131 -For instance, there exists a data handler for the simulation of an executable. The write operation of this data handler will send the inputs of the model as JSON object on stdin of the process. Afterwards the tick is triggered, and finally the data pool is updated with the JSON object received from stdout of the running process.
137 +There is a data handler for the simulation of executables. This data handler will send the inputs of the corresponding model in the simulation as JSON object to stdin of the process. Afterwards the tick is computed by the process. Finally the data pool in the current simulation is updated with the JSON object received from stdout of the running process.
132 132  
139 +Normal executables and executable jar files can be used simply by providing the path to the file. For other file types, e.g., a python script, the shell command to start the process has to be specified explicitly.
140 +
133 133  (% class="wrapped" %)
134 134  |=(((
135 135  Attribute
... ... @@ -155,11 +155,26 @@
155 155  (((
156 156  The path to the executable
157 157  )))
166 +|(% colspan="1" %)(% colspan="1" %)
167 +(((
168 +command
169 +)))|(% colspan="1" %)(% colspan="1" %)
170 +(((
171 +String, the shell command that is used to start the process
172 +)))|(% colspan="1" %)(% colspan="1" %)
173 +(((
174 +python "${executable_path}"
175 +)))|(% colspan="1" %)(% colspan="1" %)
176 +(((
177 +The shell command to start the executable
178 +)))
158 158  
159 159  === Redirect ===
160 160  
161 161  Multiple models may interact with each other as some can have inputs that are generated as outputs of other models. To implement this behaviour in the simulation, the redirect data handler has been created. It sets the inputs of a model to the outputs of some other model in the data pool. Thus the outputs of a some model A can be used as inputs of some model B.
162 162  
184 +Per default inputs and outputs are matched by name. However it is also possible to provide an explicit mapping of which output should be mapped to which input variable.
185 +
163 163  (% class="wrapped" %)
164 164  |=(((
165 165  Attribute
... ... @@ -190,16 +190,41 @@
190 190  )))|(((
191 191  The name of the model of which the inputs are set
192 192  )))
216 +|(% colspan="1" %)(% colspan="1" %)
217 +(((
218 +mapping
219 +)))|(% colspan="1" %)(% colspan="1" %)
220 +(((
221 +Map, The key is an output variable and the value is an input variable
222 +)))|(% colspan="1" %)(% colspan="1" %)
223 +(((
224 +(% class="content-wrapper" %)
225 +(((
226 +configure redirect A_to_B {
227 + from: A
228 + to: B
229 + mapping {
230 + someOutputOfA: someInputOfB
231 + other OutputOfA: otherInputOfB
232 + }
233 +}
234 +)))
235 +)))|(% colspan="1" %)(% colspan="1" %)
236 +(((
237 +Defines which output variables should be mapped to which input variables
238 +)))
193 193  
194 194  === Trace ===
195 195  
196 -A trace data handler can read a trace file, set the inputs of a model with the inputs from the trace file as well as comparing the outputs of a model to the outputs of the trace file. If the outputs of the trace do not match the outputs of the current simulation, an event is fired and the data pool view will display a trace mismatch.
242 +A trace data handler can read a trace file. The inputs of a model can be set to corresponding inputs from the trace and outputs of a model can be compared with corresponding outputs in the trace. Therefore the trace data handler has the methods **write** (inputs), **check** (outputs), **loadNextTick** (to go to the next tick in the trace).
243 +If the outputs of the trace do not match the outputs of the current simulation, an event is fired and the data pool view will display a trace mismatch.
197 197  
198 -The typical setup to use a trace data handler for a model A is:
245 +Thus the typical simulation setup to use a trace data handler for a model A is:
199 199  
200 -* Read inputs for model from trace
247 +* Set the input of the model to the inputs from the trace (write)
201 201  * Perform the tick of the model A
202 -* Compare the outputs of the trace and the model A
249 +* Compare the outputs of the trace and the model A (check)
250 +* Go to the next tick in the trace (loadNextTick)
203 203  
204 204  (% class="wrapped" %)
205 205  |=(((
... ... @@ -214,7 +214,7 @@
214 214  |(((
215 215  file
216 216  )))|(((
217 -String, project relative path
265 +String, absolute workspace path or project relative path
218 218  )))|(((
219 219  MyTrace.eso
220 220  )))|(((
... ... @@ -233,22 +233,21 @@
233 233  )))
234 234  |(% colspan="1" %)(% colspan="1" %)
235 235  (((
236 -checkOutputs
284 +traceNumber
237 237  )))|(% colspan="1" %)(% colspan="1" %)
238 238  (((
239 -Boolean
287 +Integer
240 240  )))|(% colspan="1" %)(% colspan="1" %)
241 241  (((
242 -true
243 -false
290 +0
244 244  )))|(% colspan="1" %)(% colspan="1" %)
245 245  (((
246 -If false, the outputs of the trace and simulation are not compared and the next tick is loaded after inputs have been set.
247 -Use this option when only the //write// method of the data handler is used, but not its //read// method.
293 +In case there are multiple traces in the eso file, determines which trace should be used.
294 +Default is 0
248 248  )))
249 249  |(% colspan="1" %)(% colspan="1" %)
250 250  (((
251 -traceNumber
298 +tickNumber
252 252  )))|(% colspan="1" %)(% colspan="1" %)
253 253  (((
254 254  Integer
... ... @@ -257,22 +257,23 @@
257 257  0
258 258  )))|(% colspan="1" %)(% colspan="1" %)
259 259  (((
260 -In case there are multiple traces in the eso file, determines which trace should be used.
307 +The tick of which the input is set. This can be used to skip some ticks of the trace.
261 261  Default is 0
262 262  )))
263 263  |(% colspan="1" %)(% colspan="1" %)
264 264  (((
265 -tickNumber
312 +checkInterface
266 266  )))|(% colspan="1" %)(% colspan="1" %)
267 267  (((
268 -Integer
315 +Boolean
269 269  )))|(% colspan="1" %)(% colspan="1" %)
270 270  (((
271 -0
318 +true
272 272  )))|(% colspan="1" %)(% colspan="1" %)
273 273  (((
274 -The tick of which the input is set. This can be used to skip some ticks of the trace.
275 -Default is 0
321 +Determines if the interface of the trace and model should be compared.
322 +If this is true and for example there is an additional input or output in the model that is not recored in the trace, a TraceMismatchEvent is fired.
323 +If this is false and for example the trace contains a variable that does not exist in the model, this issue is ignored.
276 276  )))
277 277  
278 278  \\
... ... @@ -298,13 +298,14 @@
298 298  Description
299 299  )))
300 300  |(((
301 -fileLocation
349 +file
302 302  )))|(((
303 -String, absolute file system path
351 +String, absolute file system path or
352 +absolute workspace path or project relative path
304 304  )))|(((
305 305  /home/myuser/process_output.simin
306 306  )))|(((
307 -The file location of the file containing the JSON object
356 +The target file
308 308  )))
309 309  |(((
310 310  modelName
... ... @@ -333,13 +333,14 @@
333 333  Description
334 334  )))
335 335  |(((
336 -fileLocation
385 +file
337 337  )))|(((
338 -String, absolute file system path
387 +String, absolute file system path or
388 +absolute workspace path or project relative path
339 339  )))|(((
340 -/home/myuser/process_output.simout
390 +myFolder/myFile.simout
341 341  )))|(((
342 -The file location of the target file
392 +The target file
343 343  )))
344 344  |(((
345 345  modelName
... ... @@ -351,6 +351,44 @@
351 351  Name of the model in the simulation that will be written as JSON object to the simout file
352 352  )))
353 353  
404 +=== Variable Setter ===
405 +
406 +This data handler is only used for easier debugging and setting up simulations for different test runs. It sets the variables in the data pool to constant values, typically once for the simulation in the initialization part of a kisim file.
407 +
408 +(% class="relative-table wrapped" %)
409 +|=(((
410 +Attribute
411 +)))|=(((
412 +Domain
413 +)))|=(((
414 +Example
415 +)))|=(((
416 +Description
417 +)))
418 +|(((
419 +variables
420 +)))|(((
421 +Map, The key is the variable name, the value is the value for this variable
422 +)))|(((
423 +configure setter S {
424 + variables {
425 + I: true
426 + O: 5
427 + MyModel.MyVar: -1
428 + }
429 +}
430 +)))|(((
431 +Sets the variables in to the given values.
432 +
433 +This way different setters can be defined for different simulation runs or manual testing.
434 +)))
435 +
436 +\\
437 +
438 +\\
439 +
440 +----
441 +
354 354  == KiSim ==
355 355  
356 356  Which data handlers are used and which actions are performed on them for each macro tick can be configured using a DSL, namely **KiSim**.
... ... @@ -450,6 +450,165 @@
450 450  }
451 451  {{/code}}
452 452  
541 +Sets the variables for manual testing:
542 +
543 +{{code}}
544 +configure sim A {
545 + executable: kieler-gen/sim/bin/Sim_Test.exe
546 +}
547 +
548 +configure setter S {
549 + variables {
550 + x: 100
551 + y: 100
552 + }
553 +}
554 +
555 +initialization {
556 + write setter S
557 +}
558 +
559 +execution {
560 + write sim A
561 +}
562 +{{/code}}
563 +
453 453  \\
454 454  
566 +== Implementation Details ==
567 +
568 +The following are details about the implementation of the simulation and the JSON format that is used to communicate the variables in the models.
569 +
570 +As said above the simulation is seen as black box which takes inputs on stdin, computes a reaction, and sends outputs stdout. Thus an executable simulation is a normal program that communicates in a specific JSON format and can also be used from command line.
455 455  \\
572 +
573 +=== The JSON Format ===
574 +
575 +The JSON format is designed to communicate the state of a simulation. In KIELER such a state is saved as a single data pool. This means the JSON format for the communication with running simulations is also the JSON format for data pools.
576 +
577 +It mainly consists of a list of models and a map of models. The models consist mainly of a map of their variables. The most important field of a variable is their value.
578 +
579 +{{code}}
580 +{ "MODEL_NAME0" : {
581 + "VAR0":{"value": "VAR0_VALUE"}, "VAR1":{"value":"VAR1_VALUE"}, ...
582 + }
583 + "MODEL_NAME1" : {
584 + "VAR0":{"value": "VAR0_VALUE"}, "VAR1":{"value":"VAR1_VALUE"}, ...
585 + }
586 + ...
587 + "actionIndex" : "ACTION_INDEX_AFTER_WHICH_THE_DATA_POOL_WAS_CREATED"
588 +}
589 +{{/code}}
590 +
591 +Besides these core informations, an additional field "actionIndex" can be set for the data pool. In the simulation the actions of data handlers are executed to create a macro tick. Therefore the action index takes the task of a program counter. It determines the next action to be executed. Thus in the JSON format the field "actionIndex" can be set to store when the data pool was created in the simulation.
592 +
593 +There are also additional fields for variables than their value. However these only need to be communicated once after the initialization of the model and are explained in the table below.
594 +
595 +|=(((
596 +Field Name
597 +)))|=(((
598 +Example Values
599 +)))|=(((
600 +Description
601 +)))
602 +|(((
603 +type
604 +)))|(((
605 +int
606 +
607 +bool
608 +
609 +pure
610 +
611 +float
612 +
613 +double
614 +
615 +string
616 +)))|(((
617 +The type of the variable in the source model.
618 +
619 +Because this information is lost in general in the compilation (for instance a bool is compiled to a char in C code), the simulation can communicate the intended variable type in the source model.
620 +)))
621 +|(((
622 +interface
623 +)))|(((
624 +0
625 +
626 +1
627 +
628 +2
629 +
630 +3
631 +
632 +4
633 +
634 +5
635 +
636 +6
637 +)))|(((
638 +Bitmask, that determines how the variable is used in the source model's interface (e.g. input, output, internal, other).
639 +A bitmask has been choosen because a mixture of a variables interface types is possible (e.g. input, output, input output)
640 +
641 +|=(((
642 +Interface Type
643 +)))|=(((
644 +Binary Bitmask
645 +)))|=(((
646 +Decimal Number
647 +)))
648 +|(((
649 +Other
650 +)))|(((
651 +0000
652 +)))|(((
653 +0
654 +)))
655 +|(% colspan="1" %)(% colspan="1" %)
656 +(((
657 +Internal
658 +)))|(% colspan="1" %)(% colspan="1" %)
659 +(((
660 +0001
661 +)))|(% colspan="1" %)(% colspan="1" %)
662 +(((
663 +1
664 +)))
665 +|(% colspan="1" %)(% colspan="1" %)
666 +(((
667 +Output
668 +)))|(% colspan="1" %)(% colspan="1" %)
669 +(((
670 +0010
671 +)))|(% colspan="1" %)(% colspan="1" %)
672 +(((
673 +2
674 +)))
675 +|(% colspan="1" %)(% colspan="1" %)
676 +(((
677 +Input
678 +)))|(% colspan="1" %)(% colspan="1" %)
679 +(((
680 +0100
681 +)))|(% colspan="1" %)(% colspan="1" %)
682 +(((
683 +4
684 +)))
685 +|(% colspan="1" %)(% colspan="1" %)
686 +(((
687 +Input Output
688 +)))|(% colspan="1" %)(% colspan="1" %)
689 +(((
690 +0110
691 +)))|(% colspan="1" %)(% colspan="1" %)
692 +(((
693 +6
694 +)))
695 +
696 +Not that internal is intended for variables that are neither input nor output but still part of the source model, in contrast to variables that are created in the compilation (e.g. register flags).
697 +Anyway an input and output is also a internal variable normally.
698 +)))
699 +
700 +=== Python Example ===
701 +
702 +\\
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -31162500
1 +33260063
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/31162500/V2 Simulation
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/KIELER/pages/33260063/V2 Simulation