simasm 0.3.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simasm-0.3.4/LICENSE +21 -0
- simasm-0.3.4/PKG-INFO +261 -0
- simasm-0.3.4/README.md +220 -0
- simasm-0.3.4/pyproject.toml +69 -0
- simasm-0.3.4/setup.cfg +4 -0
- simasm-0.3.4/simasm/__init__.py +84 -0
- simasm-0.3.4/simasm/api.py +719 -0
- simasm-0.3.4/simasm/complexity/simasm_het_analyzer.py +1154 -0
- simasm-0.3.4/simasm/config/__init__.py +7 -0
- simasm-0.3.4/simasm/config/file_config.py +59 -0
- simasm-0.3.4/simasm/converter/__init__.py +54 -0
- simasm-0.3.4/simasm/converter/acd/__init__.py +23 -0
- simasm-0.3.4/simasm/converter/acd/converter.py +968 -0
- simasm-0.3.4/simasm/converter/acd/converter_x.py +629 -0
- simasm-0.3.4/simasm/converter/acd/schema.py +363 -0
- simasm-0.3.4/simasm/converter/acd/schema_x.py +924 -0
- simasm-0.3.4/simasm/converter/codegen/__init__.py +11 -0
- simasm-0.3.4/simasm/converter/codegen/ast_builder.py +141 -0
- simasm-0.3.4/simasm/converter/codegen/pretty_printer.py +230 -0
- simasm-0.3.4/simasm/converter/dsl_schema.py +33 -0
- simasm-0.3.4/simasm/converter/engine.py +177 -0
- simasm-0.3.4/simasm/converter/event_graph/__init__.py +17 -0
- simasm-0.3.4/simasm/converter/event_graph/converter.py +614 -0
- simasm-0.3.4/simasm/converter/event_graph/converter_x.py +593 -0
- simasm-0.3.4/simasm/converter/event_graph/schema.py +391 -0
- simasm-0.3.4/simasm/converter/event_graph/schema_x.py +433 -0
- simasm-0.3.4/simasm/converter/examples/__init__.py +3 -0
- simasm-0.3.4/simasm/converter/experiment_generator.py +334 -0
- simasm-0.3.4/simasm/converter/grammar.lark +56 -0
- simasm-0.3.4/simasm/converter/parser.py +108 -0
- simasm-0.3.4/simasm/converter/test_converters.py +169 -0
- simasm-0.3.4/simasm/core/__init__.py +51 -0
- simasm-0.3.4/simasm/core/rules.py +1094 -0
- simasm-0.3.4/simasm/core/state.py +549 -0
- simasm-0.3.4/simasm/core/terms.py +757 -0
- simasm-0.3.4/simasm/core/types.py +161 -0
- simasm-0.3.4/simasm/core/update.py +262 -0
- simasm-0.3.4/simasm/experimenter/__init__.py +92 -0
- simasm-0.3.4/simasm/experimenter/ast.py +242 -0
- simasm-0.3.4/simasm/experimenter/cli.py +1085 -0
- simasm-0.3.4/simasm/experimenter/engine.py +1516 -0
- simasm-0.3.4/simasm/experimenter/grammar.lark +177 -0
- simasm-0.3.4/simasm/experimenter/transformer.py +645 -0
- simasm-0.3.4/simasm/input/__init__.py +0 -0
- simasm-0.3.4/simasm/jupyter/__init__.py +37 -0
- simasm-0.3.4/simasm/jupyter/magic.py +615 -0
- simasm-0.3.4/simasm/log/__init__.py +7 -0
- simasm-0.3.4/simasm/log/logger.py +218 -0
- simasm-0.3.4/simasm/output/__init__.py +0 -0
- simasm-0.3.4/simasm/parser/__init__.py +66 -0
- simasm-0.3.4/simasm/parser/ast.py +321 -0
- simasm-0.3.4/simasm/parser/grammar.lark +247 -0
- simasm-0.3.4/simasm/parser/loader.py +414 -0
- simasm-0.3.4/simasm/parser/parser.py +175 -0
- simasm-0.3.4/simasm/parser/transformer.py +575 -0
- simasm-0.3.4/simasm/runtime/__init__.py +39 -0
- simasm-0.3.4/simasm/runtime/random.py +543 -0
- simasm-0.3.4/simasm/runtime/stdlib.py +500 -0
- simasm-0.3.4/simasm/runtime/stepper.py +464 -0
- simasm-0.3.4/simasm/simulation/__init__.py +119 -0
- simasm-0.3.4/simasm/simulation/collector.py +610 -0
- simasm-0.3.4/simasm/simulation/config.py +320 -0
- simasm-0.3.4/simasm/simulation/output.py +637 -0
- simasm-0.3.4/simasm/simulation/plotting.py +517 -0
- simasm-0.3.4/simasm/simulation/runner.py +705 -0
- simasm-0.3.4/simasm/simulation/statistics.py +776 -0
- simasm-0.3.4/simasm/verification/__init__.py +157 -0
- simasm-0.3.4/simasm/verification/kinduction.py +684 -0
- simasm-0.3.4/simasm/verification/label.py +425 -0
- simasm-0.3.4/simasm/verification/phase.py +499 -0
- simasm-0.3.4/simasm/verification/plotting.py +495 -0
- simasm-0.3.4/simasm/verification/product.py +780 -0
- simasm-0.3.4/simasm/verification/run_verification.py +395 -0
- simasm-0.3.4/simasm/verification/run_verification_kinduction.py +382 -0
- simasm-0.3.4/simasm/verification/trace.py +589 -0
- simasm-0.3.4/simasm/verification/ts.py +413 -0
- simasm-0.3.4/simasm.egg-info/PKG-INFO +261 -0
- simasm-0.3.4/simasm.egg-info/SOURCES.txt +103 -0
- simasm-0.3.4/simasm.egg-info/dependency_links.txt +1 -0
- simasm-0.3.4/simasm.egg-info/requires.txt +17 -0
- simasm-0.3.4/simasm.egg-info/top_level.txt +1 -0
- simasm-0.3.4/test/test_001_types_v1.py +334 -0
- simasm-0.3.4/test/test_002_state_v1.py +534 -0
- simasm-0.3.4/test/test_003_asmstate_v1.py +645 -0
- simasm-0.3.4/test/test_004_update_v1.py +721 -0
- simasm-0.3.4/test/test_005_terms_v1.py +911 -0
- simasm-0.3.4/test/test_006_rules_v1.py +1622 -0
- simasm-0.3.4/test/test_007_stdlib_v1.py +713 -0
- simasm-0.3.4/test/test_008_random_v1.py +705 -0
- simasm-0.3.4/test/test_009_stepper_v1.py +686 -0
- simasm-0.3.4/test/test_010_grammar_expr_v1.py +365 -0
- simasm-0.3.4/test/test_011_grammar_stmt_v1.py +342 -0
- simasm-0.3.4/test/test_012_grammar_decl_v1.py +355 -0
- simasm-0.3.4/test/test_013_transform_expr_v1.py +304 -0
- simasm-0.3.4/test/test_014_transform_stmt_v1.py +321 -0
- simasm-0.3.4/test/test_015_transform_decl_v1.py +349 -0
- simasm-0.3.4/test/test_016_parser_api_v1.py +334 -0
- simasm-0.3.4/test/test_017_loader_v1.py +431 -0
- simasm-0.3.4/test/test_matplotlib_backend.py +17 -0
- simasm-0.3.4/test/test_matplotlib_diagnose.py +82 -0
- simasm-0.3.4/test/test_notebook_trace.py +247 -0
- simasm-0.3.4/test/test_plotting_direct.py +32 -0
- simasm-0.3.4/test/test_plotting_experiment.py +145 -0
- simasm-0.3.4/test/test_plotting_parsing.py +71 -0
- simasm-0.3.4/test/test_plotting_with_mm5.py +38 -0
simasm-0.3.4/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Steve Yeo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
simasm-0.3.4/PKG-INFO
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: simasm
|
|
3
|
+
Version: 0.3.4
|
|
4
|
+
Summary: Abstract State Machine Framework for Discrete Event Simulation
|
|
5
|
+
Author: Steve Yeo
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://simasm-project.github.io/
|
|
8
|
+
Project-URL: Documentation, https://simasm-project.github.io/reference/syntax.html/
|
|
9
|
+
Project-URL: Repository, https://github.com/SimASM-Project
|
|
10
|
+
Project-URL: Issues, https://github.com/SimASM-Project/simasm/issues
|
|
11
|
+
Keywords: simulation,discrete-event,state-machine,verification,event-graph,activity-cycle-diagram,stutter-equivalence
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
23
|
+
Classifier: Topic :: Software Development :: Interpreters
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: lark>=1.1.0
|
|
28
|
+
Requires-Dist: pydantic>=2.0
|
|
29
|
+
Requires-Dist: numpy>=1.20
|
|
30
|
+
Requires-Dist: matplotlib>=3.5
|
|
31
|
+
Requires-Dist: scipy>=1.9
|
|
32
|
+
Provides-Extra: jupyter
|
|
33
|
+
Requires-Dist: ipython>=7.0; extra == "jupyter"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
37
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
38
|
+
Requires-Dist: twine>=4.0; extra == "dev"
|
|
39
|
+
Provides-Extra: all
|
|
40
|
+
Requires-Dist: simasm[dev,jupyter]; extra == "all"
|
|
41
|
+
|
|
42
|
+
# SimASM
|
|
43
|
+
|
|
44
|
+
**Abstract State Machine Framework for Discrete Event Simulation**
|
|
45
|
+
|
|
46
|
+
SimASM is a Python package for modeling, simulating, and verifying discrete event systems using Abstract State Machines (ASM) as a common semantic foundation.
|
|
47
|
+
|
|
48
|
+
## Features
|
|
49
|
+
|
|
50
|
+
- **DSL for Simulation Models**: Write discrete event simulation models in a clean, readable syntax
|
|
51
|
+
- **Multiple Formalisms**: Support for Event Graph and Activity Cycle Diagram modeling styles
|
|
52
|
+
- **Stutter Equivalence Verification**: Formally verify that two models produce equivalent observable behavior
|
|
53
|
+
- **Jupyter Integration**: Interactive modeling with `%%simasm` magic commands
|
|
54
|
+
- **Statistics Collection**: Built-in support for time-average, utilization, and count statistics
|
|
55
|
+
- **Automatic Plotting**: Generate publication-quality plots with confidence intervals, box plots, and time series traces
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install simasm
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For Jupyter support:
|
|
64
|
+
```bash
|
|
65
|
+
pip install simasm[jupyter]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Quick Start
|
|
69
|
+
|
|
70
|
+
### In Jupyter/Colab
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import simasm # Auto-registers %%simasm magic
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Define a model:
|
|
77
|
+
```
|
|
78
|
+
%%simasm model --name mm1_queue
|
|
79
|
+
domain Event
|
|
80
|
+
domain Load
|
|
81
|
+
|
|
82
|
+
var sim_clocktime: Real
|
|
83
|
+
var queue: List<Load>
|
|
84
|
+
|
|
85
|
+
// ... model definition
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Run an experiment:
|
|
89
|
+
```
|
|
90
|
+
%%simasm experiment
|
|
91
|
+
experiment MyExperiment:
|
|
92
|
+
model := "mm1_queue"
|
|
93
|
+
|
|
94
|
+
replication:
|
|
95
|
+
count: 10
|
|
96
|
+
warm_up_time: 100.0
|
|
97
|
+
run_length: 1000.0
|
|
98
|
+
endreplication
|
|
99
|
+
|
|
100
|
+
statistics:
|
|
101
|
+
stat AvgQueueLength: time_average
|
|
102
|
+
expression: "lib.length(queue)"
|
|
103
|
+
endstat
|
|
104
|
+
endstatistics
|
|
105
|
+
endexperiment
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### From Python
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from simasm.experimenter.engine import ExperimenterEngine
|
|
112
|
+
|
|
113
|
+
# Run an experiment
|
|
114
|
+
engine = ExperimenterEngine("experiments/my_experiment.simasm")
|
|
115
|
+
result = engine.run()
|
|
116
|
+
|
|
117
|
+
print(f"Average queue length: {result['L_queue']}")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Model Syntax
|
|
121
|
+
|
|
122
|
+
SimASM uses a domain-specific language for defining simulation models:
|
|
123
|
+
|
|
124
|
+
```simasm
|
|
125
|
+
// Domain declarations
|
|
126
|
+
domain Load
|
|
127
|
+
domain Server
|
|
128
|
+
|
|
129
|
+
// Constants and variables
|
|
130
|
+
const server: Server
|
|
131
|
+
var sim_clocktime: Real
|
|
132
|
+
var queue: List<Load>
|
|
133
|
+
|
|
134
|
+
// Random stream variables
|
|
135
|
+
var interarrival_time: rnd.exponential(1.25) as "arrivals"
|
|
136
|
+
var service_time: rnd.exponential(1.0) as "service"
|
|
137
|
+
|
|
138
|
+
// Rules
|
|
139
|
+
rule arrive() =
|
|
140
|
+
let load = new Load
|
|
141
|
+
lib.add(queue, load)
|
|
142
|
+
// Schedule next arrival
|
|
143
|
+
endrule
|
|
144
|
+
|
|
145
|
+
// Main rule
|
|
146
|
+
main rule main =
|
|
147
|
+
if sim_clocktime < sim_end_time then
|
|
148
|
+
run_routine()
|
|
149
|
+
endif
|
|
150
|
+
endrule
|
|
151
|
+
|
|
152
|
+
// Initial state
|
|
153
|
+
init:
|
|
154
|
+
sim_clocktime := 0.0
|
|
155
|
+
queue := []
|
|
156
|
+
endinit
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Automatic Plotting
|
|
160
|
+
|
|
161
|
+
SimASM can automatically generate plots for your experiments with time series traces and statistical analysis:
|
|
162
|
+
|
|
163
|
+
```simasm
|
|
164
|
+
experiment MyExperiment:
|
|
165
|
+
model := "my_model.simasm"
|
|
166
|
+
|
|
167
|
+
replication:
|
|
168
|
+
count: 30
|
|
169
|
+
warm_up_time: 100.0
|
|
170
|
+
run_length: 1000.0
|
|
171
|
+
generate_plots: true // Enable automatic plotting
|
|
172
|
+
trace_interval: 10.0 // Sample traces every 10 time units
|
|
173
|
+
endreplication
|
|
174
|
+
|
|
175
|
+
statistics:
|
|
176
|
+
stat queue_length: time_average
|
|
177
|
+
expression: "lib.length(queue)"
|
|
178
|
+
trace: true // Capture time series data
|
|
179
|
+
endstat
|
|
180
|
+
|
|
181
|
+
stat utilization: time_average
|
|
182
|
+
expression: "busy / capacity"
|
|
183
|
+
trace: true
|
|
184
|
+
endstat
|
|
185
|
+
endstatistics
|
|
186
|
+
endexperiment
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
This automatically generates three types of plots:
|
|
190
|
+
|
|
191
|
+
1. **Summary Statistics** (`summary_statistics.png`)
|
|
192
|
+
- Bar chart showing mean ± 95% confidence intervals
|
|
193
|
+
- Compares all statistics side-by-side
|
|
194
|
+
|
|
195
|
+
2. **Box Plots** (`boxplots.png`)
|
|
196
|
+
- Distribution analysis across replications
|
|
197
|
+
- Shows median, quartiles, and outliers
|
|
198
|
+
|
|
199
|
+
3. **Time Series** (`timeseries.png`)
|
|
200
|
+
- Evolution of statistics over simulation time
|
|
201
|
+
- Mean trace with 95% confidence bands
|
|
202
|
+
- Highlights warmup period
|
|
203
|
+
|
|
204
|
+
Plots are saved to timestamped directories: `simasm/output/YYYY-MM-DD_HH-MM-SS_ExperimentName/`
|
|
205
|
+
|
|
206
|
+
In Jupyter notebooks, plots display inline. From CLI/Python scripts, plots are saved as PNG files.
|
|
207
|
+
|
|
208
|
+
## Verification
|
|
209
|
+
|
|
210
|
+
SimASM can verify stutter equivalence between two models:
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
%%simasm verify
|
|
214
|
+
verification EG_vs_ACD:
|
|
215
|
+
models:
|
|
216
|
+
import EG from "event_graph_model.simasm"
|
|
217
|
+
import ACD from "acd_model.simasm"
|
|
218
|
+
endmodels
|
|
219
|
+
|
|
220
|
+
seed: 42
|
|
221
|
+
|
|
222
|
+
labels:
|
|
223
|
+
label queue_empty for EG: "queue_count() == 0"
|
|
224
|
+
label queue_empty for ACD: "queue_count() == 0"
|
|
225
|
+
endlabels
|
|
226
|
+
|
|
227
|
+
observables:
|
|
228
|
+
observable queue_empty:
|
|
229
|
+
EG -> queue_empty
|
|
230
|
+
ACD -> queue_empty
|
|
231
|
+
endobservable
|
|
232
|
+
endobservables
|
|
233
|
+
|
|
234
|
+
check:
|
|
235
|
+
type: stutter_equivalence
|
|
236
|
+
run_length: 1000.0
|
|
237
|
+
endcheck
|
|
238
|
+
endverification
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Documentation
|
|
242
|
+
|
|
243
|
+
- [Full Documentation](https://github.com/yourusername/simasm)
|
|
244
|
+
- [Examples](https://github.com/yourusername/simasm/tree/main/examples)
|
|
245
|
+
|
|
246
|
+
## License
|
|
247
|
+
|
|
248
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
249
|
+
|
|
250
|
+
## Citation
|
|
251
|
+
|
|
252
|
+
If you use SimASM in your research, please cite:
|
|
253
|
+
|
|
254
|
+
```bibtex
|
|
255
|
+
@software{simasm,
|
|
256
|
+
title = {SimASM: Abstract State Machine Framework for Discrete Event Simulation},
|
|
257
|
+
author = {Steve},
|
|
258
|
+
year = {2024},
|
|
259
|
+
url = {https://github.com/yourusername/simasm}
|
|
260
|
+
}
|
|
261
|
+
```
|
simasm-0.3.4/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# SimASM
|
|
2
|
+
|
|
3
|
+
**Abstract State Machine Framework for Discrete Event Simulation**
|
|
4
|
+
|
|
5
|
+
SimASM is a Python package for modeling, simulating, and verifying discrete event systems using Abstract State Machines (ASM) as a common semantic foundation.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **DSL for Simulation Models**: Write discrete event simulation models in a clean, readable syntax
|
|
10
|
+
- **Multiple Formalisms**: Support for Event Graph and Activity Cycle Diagram modeling styles
|
|
11
|
+
- **Stutter Equivalence Verification**: Formally verify that two models produce equivalent observable behavior
|
|
12
|
+
- **Jupyter Integration**: Interactive modeling with `%%simasm` magic commands
|
|
13
|
+
- **Statistics Collection**: Built-in support for time-average, utilization, and count statistics
|
|
14
|
+
- **Automatic Plotting**: Generate publication-quality plots with confidence intervals, box plots, and time series traces
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install simasm
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For Jupyter support:
|
|
23
|
+
```bash
|
|
24
|
+
pip install simasm[jupyter]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### In Jupyter/Colab
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import simasm # Auto-registers %%simasm magic
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Define a model:
|
|
36
|
+
```
|
|
37
|
+
%%simasm model --name mm1_queue
|
|
38
|
+
domain Event
|
|
39
|
+
domain Load
|
|
40
|
+
|
|
41
|
+
var sim_clocktime: Real
|
|
42
|
+
var queue: List<Load>
|
|
43
|
+
|
|
44
|
+
// ... model definition
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Run an experiment:
|
|
48
|
+
```
|
|
49
|
+
%%simasm experiment
|
|
50
|
+
experiment MyExperiment:
|
|
51
|
+
model := "mm1_queue"
|
|
52
|
+
|
|
53
|
+
replication:
|
|
54
|
+
count: 10
|
|
55
|
+
warm_up_time: 100.0
|
|
56
|
+
run_length: 1000.0
|
|
57
|
+
endreplication
|
|
58
|
+
|
|
59
|
+
statistics:
|
|
60
|
+
stat AvgQueueLength: time_average
|
|
61
|
+
expression: "lib.length(queue)"
|
|
62
|
+
endstat
|
|
63
|
+
endstatistics
|
|
64
|
+
endexperiment
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### From Python
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from simasm.experimenter.engine import ExperimenterEngine
|
|
71
|
+
|
|
72
|
+
# Run an experiment
|
|
73
|
+
engine = ExperimenterEngine("experiments/my_experiment.simasm")
|
|
74
|
+
result = engine.run()
|
|
75
|
+
|
|
76
|
+
print(f"Average queue length: {result['L_queue']}")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Model Syntax
|
|
80
|
+
|
|
81
|
+
SimASM uses a domain-specific language for defining simulation models:
|
|
82
|
+
|
|
83
|
+
```simasm
|
|
84
|
+
// Domain declarations
|
|
85
|
+
domain Load
|
|
86
|
+
domain Server
|
|
87
|
+
|
|
88
|
+
// Constants and variables
|
|
89
|
+
const server: Server
|
|
90
|
+
var sim_clocktime: Real
|
|
91
|
+
var queue: List<Load>
|
|
92
|
+
|
|
93
|
+
// Random stream variables
|
|
94
|
+
var interarrival_time: rnd.exponential(1.25) as "arrivals"
|
|
95
|
+
var service_time: rnd.exponential(1.0) as "service"
|
|
96
|
+
|
|
97
|
+
// Rules
|
|
98
|
+
rule arrive() =
|
|
99
|
+
let load = new Load
|
|
100
|
+
lib.add(queue, load)
|
|
101
|
+
// Schedule next arrival
|
|
102
|
+
endrule
|
|
103
|
+
|
|
104
|
+
// Main rule
|
|
105
|
+
main rule main =
|
|
106
|
+
if sim_clocktime < sim_end_time then
|
|
107
|
+
run_routine()
|
|
108
|
+
endif
|
|
109
|
+
endrule
|
|
110
|
+
|
|
111
|
+
// Initial state
|
|
112
|
+
init:
|
|
113
|
+
sim_clocktime := 0.0
|
|
114
|
+
queue := []
|
|
115
|
+
endinit
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Automatic Plotting
|
|
119
|
+
|
|
120
|
+
SimASM can automatically generate plots for your experiments with time series traces and statistical analysis:
|
|
121
|
+
|
|
122
|
+
```simasm
|
|
123
|
+
experiment MyExperiment:
|
|
124
|
+
model := "my_model.simasm"
|
|
125
|
+
|
|
126
|
+
replication:
|
|
127
|
+
count: 30
|
|
128
|
+
warm_up_time: 100.0
|
|
129
|
+
run_length: 1000.0
|
|
130
|
+
generate_plots: true // Enable automatic plotting
|
|
131
|
+
trace_interval: 10.0 // Sample traces every 10 time units
|
|
132
|
+
endreplication
|
|
133
|
+
|
|
134
|
+
statistics:
|
|
135
|
+
stat queue_length: time_average
|
|
136
|
+
expression: "lib.length(queue)"
|
|
137
|
+
trace: true // Capture time series data
|
|
138
|
+
endstat
|
|
139
|
+
|
|
140
|
+
stat utilization: time_average
|
|
141
|
+
expression: "busy / capacity"
|
|
142
|
+
trace: true
|
|
143
|
+
endstat
|
|
144
|
+
endstatistics
|
|
145
|
+
endexperiment
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
This automatically generates three types of plots:
|
|
149
|
+
|
|
150
|
+
1. **Summary Statistics** (`summary_statistics.png`)
|
|
151
|
+
- Bar chart showing mean ± 95% confidence intervals
|
|
152
|
+
- Compares all statistics side-by-side
|
|
153
|
+
|
|
154
|
+
2. **Box Plots** (`boxplots.png`)
|
|
155
|
+
- Distribution analysis across replications
|
|
156
|
+
- Shows median, quartiles, and outliers
|
|
157
|
+
|
|
158
|
+
3. **Time Series** (`timeseries.png`)
|
|
159
|
+
- Evolution of statistics over simulation time
|
|
160
|
+
- Mean trace with 95% confidence bands
|
|
161
|
+
- Highlights warmup period
|
|
162
|
+
|
|
163
|
+
Plots are saved to timestamped directories: `simasm/output/YYYY-MM-DD_HH-MM-SS_ExperimentName/`
|
|
164
|
+
|
|
165
|
+
In Jupyter notebooks, plots display inline. From CLI/Python scripts, plots are saved as PNG files.
|
|
166
|
+
|
|
167
|
+
## Verification
|
|
168
|
+
|
|
169
|
+
SimASM can verify stutter equivalence between two models:
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
%%simasm verify
|
|
173
|
+
verification EG_vs_ACD:
|
|
174
|
+
models:
|
|
175
|
+
import EG from "event_graph_model.simasm"
|
|
176
|
+
import ACD from "acd_model.simasm"
|
|
177
|
+
endmodels
|
|
178
|
+
|
|
179
|
+
seed: 42
|
|
180
|
+
|
|
181
|
+
labels:
|
|
182
|
+
label queue_empty for EG: "queue_count() == 0"
|
|
183
|
+
label queue_empty for ACD: "queue_count() == 0"
|
|
184
|
+
endlabels
|
|
185
|
+
|
|
186
|
+
observables:
|
|
187
|
+
observable queue_empty:
|
|
188
|
+
EG -> queue_empty
|
|
189
|
+
ACD -> queue_empty
|
|
190
|
+
endobservable
|
|
191
|
+
endobservables
|
|
192
|
+
|
|
193
|
+
check:
|
|
194
|
+
type: stutter_equivalence
|
|
195
|
+
run_length: 1000.0
|
|
196
|
+
endcheck
|
|
197
|
+
endverification
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Documentation
|
|
201
|
+
|
|
202
|
+
- [Full Documentation](https://github.com/yourusername/simasm)
|
|
203
|
+
- [Examples](https://github.com/yourusername/simasm/tree/main/examples)
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
208
|
+
|
|
209
|
+
## Citation
|
|
210
|
+
|
|
211
|
+
If you use SimASM in your research, please cite:
|
|
212
|
+
|
|
213
|
+
```bibtex
|
|
214
|
+
@software{simasm,
|
|
215
|
+
title = {SimASM: Abstract State Machine Framework for Discrete Event Simulation},
|
|
216
|
+
author = {Steve},
|
|
217
|
+
year = {2024},
|
|
218
|
+
url = {https://github.com/yourusername/simasm}
|
|
219
|
+
}
|
|
220
|
+
```
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0,<77.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "simasm"
|
|
7
|
+
version = "0.3.4"
|
|
8
|
+
description = "Abstract State Machine Framework for Discrete Event Simulation"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "Steve Yeo"}
|
|
13
|
+
]
|
|
14
|
+
requires-python = ">=3.9"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Topic :: Scientific/Engineering",
|
|
26
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
27
|
+
"Topic :: Software Development :: Interpreters",
|
|
28
|
+
]
|
|
29
|
+
keywords = ["simulation", "discrete-event", "state-machine", "verification", "event-graph", "activity-cycle-diagram", "stutter-equivalence"]
|
|
30
|
+
|
|
31
|
+
dependencies = [
|
|
32
|
+
"lark>=1.1.0",
|
|
33
|
+
"pydantic>=2.0",
|
|
34
|
+
"numpy>=1.20",
|
|
35
|
+
"matplotlib>=3.5",
|
|
36
|
+
"scipy>=1.9",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
jupyter = [
|
|
41
|
+
"ipython>=7.0",
|
|
42
|
+
]
|
|
43
|
+
dev = [
|
|
44
|
+
"pytest>=7.0",
|
|
45
|
+
"pytest-cov>=4.0",
|
|
46
|
+
"build>=1.0",
|
|
47
|
+
"twine>=4.0",
|
|
48
|
+
]
|
|
49
|
+
all = [
|
|
50
|
+
"simasm[jupyter,dev]",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
[project.urls]
|
|
54
|
+
Homepage = "https://simasm-project.github.io/"
|
|
55
|
+
Documentation = "https://simasm-project.github.io/reference/syntax.html/"
|
|
56
|
+
Repository = "https://github.com/SimASM-Project"
|
|
57
|
+
Issues = "https://github.com/SimASM-Project/simasm/issues"
|
|
58
|
+
|
|
59
|
+
[tool.setuptools.packages.find]
|
|
60
|
+
where = ["."]
|
|
61
|
+
include = ["simasm*"]
|
|
62
|
+
|
|
63
|
+
[tool.setuptools.package-data]
|
|
64
|
+
simasm = ["parser/*.lark", "experimenter/*.lark", "converter/*.lark"]
|
|
65
|
+
|
|
66
|
+
[tool.pytest.ini_options]
|
|
67
|
+
testpaths = ["test"]
|
|
68
|
+
python_files = ["test_*.py"]
|
|
69
|
+
addopts = "-v"
|
simasm-0.3.4/setup.cfg
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SimASM - Abstract State Machine Framework for Discrete Event Simulation
|
|
3
|
+
|
|
4
|
+
A Python package for modeling, simulating, and verifying discrete event
|
|
5
|
+
systems using Abstract State Machines as the common semantic foundation.
|
|
6
|
+
|
|
7
|
+
Usage with Python API (recommended - avoids linter warnings):
|
|
8
|
+
import simasm
|
|
9
|
+
|
|
10
|
+
# Define models as strings
|
|
11
|
+
simasm.register_model("mm1_eg", '''
|
|
12
|
+
domain Object
|
|
13
|
+
...
|
|
14
|
+
''')
|
|
15
|
+
|
|
16
|
+
# Run experiments
|
|
17
|
+
result = simasm.run_experiment('''
|
|
18
|
+
experiment Test:
|
|
19
|
+
model := "mm1_eg"
|
|
20
|
+
...
|
|
21
|
+
endexperiment
|
|
22
|
+
''')
|
|
23
|
+
|
|
24
|
+
# Run verifications
|
|
25
|
+
result = simasm.verify('''
|
|
26
|
+
verification Check:
|
|
27
|
+
models:
|
|
28
|
+
import EG from "mm1_eg"
|
|
29
|
+
...
|
|
30
|
+
endmodels
|
|
31
|
+
...
|
|
32
|
+
endverification
|
|
33
|
+
''')
|
|
34
|
+
|
|
35
|
+
Alternative: Jupyter/Colab cell magics:
|
|
36
|
+
import simasm # Auto-registers %%simasm magic
|
|
37
|
+
|
|
38
|
+
%%simasm model --name mm1_queue
|
|
39
|
+
domain Event
|
|
40
|
+
...
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
__version__ = "0.3.4"
|
|
44
|
+
__author__ = "Steve Yeo"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# Import Python API functions for direct access
|
|
48
|
+
from simasm.api import (
|
|
49
|
+
# Model registry
|
|
50
|
+
register_model,
|
|
51
|
+
get_model,
|
|
52
|
+
list_models,
|
|
53
|
+
clear_models,
|
|
54
|
+
unregister_model,
|
|
55
|
+
# Experiment/verification
|
|
56
|
+
run_experiment,
|
|
57
|
+
verify,
|
|
58
|
+
# Direct execution
|
|
59
|
+
run_model,
|
|
60
|
+
parse_model,
|
|
61
|
+
# Conversion
|
|
62
|
+
convert_model,
|
|
63
|
+
# Display helpers
|
|
64
|
+
display_experiment_result,
|
|
65
|
+
display_verification_result,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# Auto-register Jupyter magics when imported in IPython/Jupyter
|
|
70
|
+
def _register_jupyter_magics():
|
|
71
|
+
"""Auto-register magics if running in IPython/Jupyter."""
|
|
72
|
+
try:
|
|
73
|
+
from IPython import get_ipython
|
|
74
|
+
ipython = get_ipython()
|
|
75
|
+
if ipython is not None:
|
|
76
|
+
from simasm.jupyter.magic import SimASMMagics
|
|
77
|
+
ipython.register_magics(SimASMMagics)
|
|
78
|
+
except ImportError:
|
|
79
|
+
pass # IPython not installed
|
|
80
|
+
except Exception:
|
|
81
|
+
pass # Not in IPython environment or other error
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
_register_jupyter_magics()
|