simpy-ds 0.1.0__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.
- simpy_ds-0.1.0/LICENSE +165 -0
- simpy_ds-0.1.0/NOTICE +9 -0
- simpy_ds-0.1.0/PKG-INFO +242 -0
- simpy_ds-0.1.0/README.md +227 -0
- simpy_ds-0.1.0/pyproject.toml +25 -0
- simpy_ds-0.1.0/setup.cfg +4 -0
- simpy_ds-0.1.0/src/simpy_ds/__init__.py +10 -0
- simpy_ds-0.1.0/src/simpy_ds/_network.py +165 -0
- simpy_ds-0.1.0/src/simpy_ds/blocking/__init__.py +6 -0
- simpy_ds-0.1.0/src/simpy_ds/blocking/network.py +66 -0
- simpy_ds-0.1.0/src/simpy_ds/blocking/process.py +65 -0
- simpy_ds-0.1.0/src/simpy_ds/events/__init__.py +6 -0
- simpy_ds-0.1.0/src/simpy_ds/events/network.py +50 -0
- simpy_ds-0.1.0/src/simpy_ds/events/process.py +69 -0
- simpy_ds-0.1.0/src/simpy_ds/message.py +30 -0
- simpy_ds-0.1.0/src/simpy_ds.egg-info/PKG-INFO +242 -0
- simpy_ds-0.1.0/src/simpy_ds.egg-info/SOURCES.txt +22 -0
- simpy_ds-0.1.0/src/simpy_ds.egg-info/dependency_links.txt +1 -0
- simpy_ds-0.1.0/src/simpy_ds.egg-info/requires.txt +1 -0
- simpy_ds-0.1.0/src/simpy_ds.egg-info/top_level.txt +2 -0
- simpy_ds-0.1.0/src/simpy_ds_extensions/__init__.py +7 -0
- simpy_ds-0.1.0/src/simpy_ds_extensions/duplicating.py +12 -0
- simpy_ds-0.1.0/src/simpy_ds_extensions/duplicating_events.py +12 -0
- simpy_ds-0.1.0/tests/test_network.py +112 -0
simpy_ds-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
simpy_ds-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
SimPy-DS
|
|
2
|
+
|
|
3
|
+
Copyright © 2026 Inria
|
|
4
|
+
Author: Davide Frey
|
|
5
|
+
|
|
6
|
+
This library is free software: you can redistribute it and/or modify it
|
|
7
|
+
under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
simpy_ds-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simpy-ds
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Small distributed-systems simulation helpers on top of SimPy.
|
|
5
|
+
Author-email: Davide Frey <davide.frey@inria.fr>
|
|
6
|
+
License-Expression: LGPL-3.0-or-later
|
|
7
|
+
Project-URL: Source, https://gitlab.inria.fr/dfrey/simpy-ds
|
|
8
|
+
Project-URL: Issues, https://gitlab.inria.fr/dfrey/simpy-ds/-/issues
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Requires-Dist: simpy>=4.1.2
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# SimPy DS
|
|
17
|
+
|
|
18
|
+
`simpy-ds` is a small teaching-oriented layer for writing distributed-system
|
|
19
|
+
simulations on top of SimPy's event-based core.
|
|
20
|
+
|
|
21
|
+
It is intentionally thin: SimPy still provides the scheduler, simulated time,
|
|
22
|
+
timeouts, events, and process execution. This package adds a small message
|
|
23
|
+
passing API that looks closer to distributed-algorithm pseudocode.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
yield network.send("p0", "p1", {"round": 1}, tag="vote")
|
|
27
|
+
message = yield network.recv("p1")
|
|
28
|
+
```
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
SimPy-DS is licensed under the GNU Lesser General Public License,
|
|
32
|
+
version 3.0 or later. See [LICENSE](LICENSE).
|
|
33
|
+
|
|
34
|
+
## Why SimPy?
|
|
35
|
+
|
|
36
|
+
SimPy is a process-based discrete-event simulator. A distributed process can be
|
|
37
|
+
written as a Python generator, and `yield` marks points where it waits for an
|
|
38
|
+
event: a timeout, a message delivery, or a condition over several events.
|
|
39
|
+
|
|
40
|
+
This makes it a good substrate for algorithms with:
|
|
41
|
+
|
|
42
|
+
- asynchronous message delivery
|
|
43
|
+
- timers and timeouts
|
|
44
|
+
- controlled delays
|
|
45
|
+
- optional message loss
|
|
46
|
+
- simple crash-stop or omission faults
|
|
47
|
+
- deterministic replay with a random seed
|
|
48
|
+
|
|
49
|
+
## Layout
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
simpy-ds/
|
|
53
|
+
README.md
|
|
54
|
+
requirements.txt
|
|
55
|
+
src/simpy_ds/
|
|
56
|
+
__init__.py
|
|
57
|
+
blocking/
|
|
58
|
+
network.py
|
|
59
|
+
process.py
|
|
60
|
+
events/
|
|
61
|
+
network.py
|
|
62
|
+
process.py
|
|
63
|
+
message.py
|
|
64
|
+
network.py
|
|
65
|
+
process.py
|
|
66
|
+
src/simpy_ds_extensions/
|
|
67
|
+
__init__.py
|
|
68
|
+
duplicating.py
|
|
69
|
+
examples/
|
|
70
|
+
adapters/
|
|
71
|
+
blocking_on_events.py
|
|
72
|
+
events_on_blocking.py
|
|
73
|
+
blocking/
|
|
74
|
+
bracha_double_echo.py
|
|
75
|
+
ping_pong.py
|
|
76
|
+
broadcast_delivery.py
|
|
77
|
+
broadcast_delivery_2.py
|
|
78
|
+
duplicating_channel.py
|
|
79
|
+
events/
|
|
80
|
+
bracha_double_echo.py
|
|
81
|
+
ping_pong.py
|
|
82
|
+
broadcast_delivery.py
|
|
83
|
+
duplicating_channel.py
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Install
|
|
87
|
+
|
|
88
|
+
From this folder:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
python -m pip install -r requirements.txt
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
To run the examples from a local checkout, install the project in editable
|
|
95
|
+
mode:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
python -m pip install -e .
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Blocking-Style Examples
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
python examples/blocking/ping_pong.py
|
|
105
|
+
python examples/blocking/broadcast_delivery.py
|
|
106
|
+
python examples/blocking/duplicating_channel.py
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
If `yield` or `lambda` are unfamiliar, see
|
|
110
|
+
[`docs/python-yield-and-lambda.md`](docs/python-yield-and-lambda.md).
|
|
111
|
+
|
|
112
|
+
## Two Programming Models
|
|
113
|
+
|
|
114
|
+
The library has two separate sub-libraries:
|
|
115
|
+
|
|
116
|
+
- `simpy_ds.blocking`: mailbox-based processes that wait with `yield recv()`.
|
|
117
|
+
- `simpy_ds.events`: handler-based processes. `EventNetwork` delivers each
|
|
118
|
+
message directly to the one registered `EventProcess` handler for its
|
|
119
|
+
destination. It has no inboxes and no `recv()` operation.
|
|
120
|
+
|
|
121
|
+
The corresponding examples for both styles are under `examples/blocking/` and
|
|
122
|
+
`examples/events/`.
|
|
123
|
+
|
|
124
|
+
## Event-Driven Examples
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
python examples/events/ping_pong.py
|
|
128
|
+
python examples/events/broadcast_delivery.py
|
|
129
|
+
python examples/events/duplicating_channel.py
|
|
130
|
+
python examples/events/bracha_double_echo.py
|
|
131
|
+
|
|
132
|
+
## Layered Interface Samples
|
|
133
|
+
|
|
134
|
+
The modules in `examples/adapters/` show how one programming model can be
|
|
135
|
+
layered over the other:
|
|
136
|
+
|
|
137
|
+
- `blocking_on_events.py` provides a blocking `Network` and `Process` over the
|
|
138
|
+
handler-based implementation.
|
|
139
|
+
- `events_on_blocking.py` provides an `EventNetwork` and `EventProcess` over
|
|
140
|
+
the mailbox-based implementation.
|
|
141
|
+
|
|
142
|
+
Every ordinary example keeps its native import active and includes a commented
|
|
143
|
+
alternative import from the corresponding adapter. Uncomment that line and
|
|
144
|
+
comment the native import to run the same application over the layered API.
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Run Tests
|
|
148
|
+
|
|
149
|
+
The tests use Python's built-in `unittest` module:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
python -m unittest discover -s tests -v
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Blocking API
|
|
156
|
+
|
|
157
|
+
Create an environment and network:
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
import simpy
|
|
161
|
+
from simpy_ds.blocking import Network
|
|
162
|
+
|
|
163
|
+
env = simpy.Environment()
|
|
164
|
+
network = Network(env, nodes=["p0", "p1", "p2"], delay=1.0)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Send a message:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
yield network.send("p0", "p1", "hello", tag="greeting")
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Receive the next message:
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
message = yield network.recv("p1")
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Receive only messages matching a predicate:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
message = yield network.recv("p1", lambda m: m.tag == "ack")
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Broadcast:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
yield network.broadcast("p0", ["p1", "p2"], "value", tag="proposal")
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
This is a network-level convenience method, not a reliable-broadcast protocol.
|
|
192
|
+
It schedules one send per destination. If the network is configured with
|
|
193
|
+
message loss, some destinations may never receive the payload. A real reliable
|
|
194
|
+
broadcast algorithm should be written as a process-level protocol on top of
|
|
195
|
+
`send`, `recv`, and `broadcast`, with explicit validity, agreement, and
|
|
196
|
+
integrity properties.
|
|
197
|
+
|
|
198
|
+
The base network can be configured as lossless by leaving `drop_rate=0.0`, or
|
|
199
|
+
as lossy by setting `drop_rate` above zero. It does not duplicate messages.
|
|
200
|
+
|
|
201
|
+
## Optional Extensions
|
|
202
|
+
|
|
203
|
+
The optional network variants live in `simpy_ds_extensions`. The current
|
|
204
|
+
duplicating variants support both network APIs.
|
|
205
|
+
|
|
206
|
+
For example, `DuplicatingNetwork` extends the blocking network with possible
|
|
207
|
+
duplicate delivery. `DuplicatingEventNetwork` provides the matching
|
|
208
|
+
handler-based variant.
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from simpy_ds_extensions import DuplicatingNetwork
|
|
212
|
+
|
|
213
|
+
network = DuplicatingNetwork(
|
|
214
|
+
env,
|
|
215
|
+
nodes=["p0", "p1"],
|
|
216
|
+
delay=1.0,
|
|
217
|
+
duplicate_rate=0.1,
|
|
218
|
+
)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Use this only when you explicitly want to model a channel that may deliver a
|
|
222
|
+
second copy of an already delivered message.
|
|
223
|
+
|
|
224
|
+
Add a timeout:
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
received = network.recv("p1")
|
|
228
|
+
timeout = env.timeout(5)
|
|
229
|
+
result = yield received | timeout
|
|
230
|
+
|
|
231
|
+
if received in result:
|
|
232
|
+
message = result[received]
|
|
233
|
+
else:
|
|
234
|
+
print("timed out")
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Scope
|
|
238
|
+
|
|
239
|
+
This is a starting point, not a full distributed-systems framework. The current
|
|
240
|
+
library models processes and message passing. Natural next additions are FIFO
|
|
241
|
+
links, partitions, crash-stop nodes, Byzantine nodes, vector clocks, and trace
|
|
242
|
+
export for visualization.
|
simpy_ds-0.1.0/README.md
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# SimPy DS
|
|
2
|
+
|
|
3
|
+
`simpy-ds` is a small teaching-oriented layer for writing distributed-system
|
|
4
|
+
simulations on top of SimPy's event-based core.
|
|
5
|
+
|
|
6
|
+
It is intentionally thin: SimPy still provides the scheduler, simulated time,
|
|
7
|
+
timeouts, events, and process execution. This package adds a small message
|
|
8
|
+
passing API that looks closer to distributed-algorithm pseudocode.
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
yield network.send("p0", "p1", {"round": 1}, tag="vote")
|
|
12
|
+
message = yield network.recv("p1")
|
|
13
|
+
```
|
|
14
|
+
## License
|
|
15
|
+
|
|
16
|
+
SimPy-DS is licensed under the GNU Lesser General Public License,
|
|
17
|
+
version 3.0 or later. See [LICENSE](LICENSE).
|
|
18
|
+
|
|
19
|
+
## Why SimPy?
|
|
20
|
+
|
|
21
|
+
SimPy is a process-based discrete-event simulator. A distributed process can be
|
|
22
|
+
written as a Python generator, and `yield` marks points where it waits for an
|
|
23
|
+
event: a timeout, a message delivery, or a condition over several events.
|
|
24
|
+
|
|
25
|
+
This makes it a good substrate for algorithms with:
|
|
26
|
+
|
|
27
|
+
- asynchronous message delivery
|
|
28
|
+
- timers and timeouts
|
|
29
|
+
- controlled delays
|
|
30
|
+
- optional message loss
|
|
31
|
+
- simple crash-stop or omission faults
|
|
32
|
+
- deterministic replay with a random seed
|
|
33
|
+
|
|
34
|
+
## Layout
|
|
35
|
+
|
|
36
|
+
```text
|
|
37
|
+
simpy-ds/
|
|
38
|
+
README.md
|
|
39
|
+
requirements.txt
|
|
40
|
+
src/simpy_ds/
|
|
41
|
+
__init__.py
|
|
42
|
+
blocking/
|
|
43
|
+
network.py
|
|
44
|
+
process.py
|
|
45
|
+
events/
|
|
46
|
+
network.py
|
|
47
|
+
process.py
|
|
48
|
+
message.py
|
|
49
|
+
network.py
|
|
50
|
+
process.py
|
|
51
|
+
src/simpy_ds_extensions/
|
|
52
|
+
__init__.py
|
|
53
|
+
duplicating.py
|
|
54
|
+
examples/
|
|
55
|
+
adapters/
|
|
56
|
+
blocking_on_events.py
|
|
57
|
+
events_on_blocking.py
|
|
58
|
+
blocking/
|
|
59
|
+
bracha_double_echo.py
|
|
60
|
+
ping_pong.py
|
|
61
|
+
broadcast_delivery.py
|
|
62
|
+
broadcast_delivery_2.py
|
|
63
|
+
duplicating_channel.py
|
|
64
|
+
events/
|
|
65
|
+
bracha_double_echo.py
|
|
66
|
+
ping_pong.py
|
|
67
|
+
broadcast_delivery.py
|
|
68
|
+
duplicating_channel.py
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Install
|
|
72
|
+
|
|
73
|
+
From this folder:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
python -m pip install -r requirements.txt
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
To run the examples from a local checkout, install the project in editable
|
|
80
|
+
mode:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
python -m pip install -e .
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Blocking-Style Examples
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
python examples/blocking/ping_pong.py
|
|
90
|
+
python examples/blocking/broadcast_delivery.py
|
|
91
|
+
python examples/blocking/duplicating_channel.py
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
If `yield` or `lambda` are unfamiliar, see
|
|
95
|
+
[`docs/python-yield-and-lambda.md`](docs/python-yield-and-lambda.md).
|
|
96
|
+
|
|
97
|
+
## Two Programming Models
|
|
98
|
+
|
|
99
|
+
The library has two separate sub-libraries:
|
|
100
|
+
|
|
101
|
+
- `simpy_ds.blocking`: mailbox-based processes that wait with `yield recv()`.
|
|
102
|
+
- `simpy_ds.events`: handler-based processes. `EventNetwork` delivers each
|
|
103
|
+
message directly to the one registered `EventProcess` handler for its
|
|
104
|
+
destination. It has no inboxes and no `recv()` operation.
|
|
105
|
+
|
|
106
|
+
The corresponding examples for both styles are under `examples/blocking/` and
|
|
107
|
+
`examples/events/`.
|
|
108
|
+
|
|
109
|
+
## Event-Driven Examples
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
python examples/events/ping_pong.py
|
|
113
|
+
python examples/events/broadcast_delivery.py
|
|
114
|
+
python examples/events/duplicating_channel.py
|
|
115
|
+
python examples/events/bracha_double_echo.py
|
|
116
|
+
|
|
117
|
+
## Layered Interface Samples
|
|
118
|
+
|
|
119
|
+
The modules in `examples/adapters/` show how one programming model can be
|
|
120
|
+
layered over the other:
|
|
121
|
+
|
|
122
|
+
- `blocking_on_events.py` provides a blocking `Network` and `Process` over the
|
|
123
|
+
handler-based implementation.
|
|
124
|
+
- `events_on_blocking.py` provides an `EventNetwork` and `EventProcess` over
|
|
125
|
+
the mailbox-based implementation.
|
|
126
|
+
|
|
127
|
+
Every ordinary example keeps its native import active and includes a commented
|
|
128
|
+
alternative import from the corresponding adapter. Uncomment that line and
|
|
129
|
+
comment the native import to run the same application over the layered API.
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Run Tests
|
|
133
|
+
|
|
134
|
+
The tests use Python's built-in `unittest` module:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
python -m unittest discover -s tests -v
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Blocking API
|
|
141
|
+
|
|
142
|
+
Create an environment and network:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
import simpy
|
|
146
|
+
from simpy_ds.blocking import Network
|
|
147
|
+
|
|
148
|
+
env = simpy.Environment()
|
|
149
|
+
network = Network(env, nodes=["p0", "p1", "p2"], delay=1.0)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Send a message:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
yield network.send("p0", "p1", "hello", tag="greeting")
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Receive the next message:
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
message = yield network.recv("p1")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Receive only messages matching a predicate:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
message = yield network.recv("p1", lambda m: m.tag == "ack")
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Broadcast:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
yield network.broadcast("p0", ["p1", "p2"], "value", tag="proposal")
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
This is a network-level convenience method, not a reliable-broadcast protocol.
|
|
177
|
+
It schedules one send per destination. If the network is configured with
|
|
178
|
+
message loss, some destinations may never receive the payload. A real reliable
|
|
179
|
+
broadcast algorithm should be written as a process-level protocol on top of
|
|
180
|
+
`send`, `recv`, and `broadcast`, with explicit validity, agreement, and
|
|
181
|
+
integrity properties.
|
|
182
|
+
|
|
183
|
+
The base network can be configured as lossless by leaving `drop_rate=0.0`, or
|
|
184
|
+
as lossy by setting `drop_rate` above zero. It does not duplicate messages.
|
|
185
|
+
|
|
186
|
+
## Optional Extensions
|
|
187
|
+
|
|
188
|
+
The optional network variants live in `simpy_ds_extensions`. The current
|
|
189
|
+
duplicating variants support both network APIs.
|
|
190
|
+
|
|
191
|
+
For example, `DuplicatingNetwork` extends the blocking network with possible
|
|
192
|
+
duplicate delivery. `DuplicatingEventNetwork` provides the matching
|
|
193
|
+
handler-based variant.
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from simpy_ds_extensions import DuplicatingNetwork
|
|
197
|
+
|
|
198
|
+
network = DuplicatingNetwork(
|
|
199
|
+
env,
|
|
200
|
+
nodes=["p0", "p1"],
|
|
201
|
+
delay=1.0,
|
|
202
|
+
duplicate_rate=0.1,
|
|
203
|
+
)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Use this only when you explicitly want to model a channel that may deliver a
|
|
207
|
+
second copy of an already delivered message.
|
|
208
|
+
|
|
209
|
+
Add a timeout:
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
received = network.recv("p1")
|
|
213
|
+
timeout = env.timeout(5)
|
|
214
|
+
result = yield received | timeout
|
|
215
|
+
|
|
216
|
+
if received in result:
|
|
217
|
+
message = result[received]
|
|
218
|
+
else:
|
|
219
|
+
print("timed out")
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Scope
|
|
223
|
+
|
|
224
|
+
This is a starting point, not a full distributed-systems framework. The current
|
|
225
|
+
library models processes and message passing. Natural next additions are FIFO
|
|
226
|
+
links, partitions, crash-stop nodes, Byzantine nodes, vector clocks, and trace
|
|
227
|
+
export for visualization.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "simpy-ds"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Small distributed-systems simulation helpers on top of SimPy."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = ["simpy>=4.1.2"]
|
|
12
|
+
license = "LGPL-3.0-or-later"
|
|
13
|
+
license-files = ["LICENSE","NOTICE"]
|
|
14
|
+
authors = [
|
|
15
|
+
{ name = "Davide Frey", email = "davide.frey@inria.fr" },
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Source = "https://gitlab.inria.fr/dfrey/simpy-ds"
|
|
21
|
+
Issues = "https://gitlab.inria.fr/dfrey/simpy-ds/-/issues"
|
|
22
|
+
|
|
23
|
+
[tool.setuptools.packages.find]
|
|
24
|
+
where = ["src"]
|
|
25
|
+
|
simpy_ds-0.1.0/setup.cfg
ADDED