|
| 1 | + |
| 2 | +safety |
| 3 | +====== |
| 4 | + |
| 5 | +This sample shows how to do safety analysis in PyModel: write |
| 6 | +*invariants* (safety conditions) that describe safe states, then use |
| 7 | +*exploration* to search for unsafe states. Unsafe states are |
| 8 | +indicated in the printed output from *pma* (or *pmv*), and in the |
| 9 | +generated FSM and graphics files. |
| 10 | + |
| 11 | +The example here is a microwave oven. The safety condition is: the |
| 12 | +microwave power can only be on when the oven door is closed. |
| 13 | + |
| 14 | +- *unsafe_oven*: model program for an unsafe oven. The enabling |
| 15 | +conditions and action bodies allow traces that can reach an unsafe |
| 16 | +state. |
| 17 | + |
| 18 | +- *oven*: model program for a safe oven. The enabling conditions and |
| 19 | +action bodies ensure that traces can only reach safe states. |
| 20 | + |
| 21 | +- *test_graphics*: generates FSMs and graphs from both models. When |
| 22 | + you run this script, the *pma* program prints the number of unsafe |
| 23 | + states found in each model. |
| 24 | + |
| 25 | +- *fsmpy*, *svg*: directories of output files from *test_graphics*. |
| 26 | + The unsafe states are indicated in these output files. |
| 27 | + |
| 28 | +Examine the generated FSM files (in the *fsmpy* directory). They are |
| 29 | +Python modules (in plain text). |
| 30 | + |
| 31 | +- *unsafe_ovenFSM.py*: FSM generated from *unsafe_oven*. The comments |
| 32 | + at the top indicate *1 unsafe states*. Further down, the *states* |
| 33 | + dictionary reports each state, along with its state variables and |
| 34 | + their values. Below that, *unsafe* is a list of unsafe states, |
| 35 | + identified by their keys in *states*: *unsafe = [3]* here. |
| 36 | + |
| 37 | +- *ovenFSM.py*: FSM generated from *oven*. The comments at the top |
| 38 | + indicate *0 unsafe states* and the *unsafe* list is empty. |
| 39 | + |
| 40 | +View the generated graphics files (in the *svg* directory) in a browser. |
| 41 | +Hover the pointer over any state bubble to see a tooltip that shows |
| 42 | +the state variables and their values in that state, to confirm whether |
| 43 | +the safety condition is satisfied. Unsafe states are colored red. |
| 44 | + |
| 45 | +- *unsafe_ovenFSM.svg*: graph of *unsafe_oven*. The unsafe state |
| 46 | + appears in red. |
| 47 | + |
| 48 | +- *ovenFSM.svg*: graph of *oven*, confirms there are no unsafe states. |
| 49 | + |
| 50 | +There is no stepper in this sample. |
| 51 | + |
| 52 | + |
| 53 | +Revised Apr 2013 |
0 commit comments