smolpy 1.11.1.dev5__tar.gz → 1.11.1.dev8__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.
Files changed (161) hide show
  1. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/PKG-INFO +13 -6
  2. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/README.md +12 -5
  3. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/__main__.py +25 -1
  4. smolpy-1.11.1.dev8/benchmarks/closed_loop.py +199 -0
  5. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/loss.py +15 -2
  6. smolpy-1.11.1.dev8/benchmarks/results/2026-11-23-2106-simpy-rust-ns3-jaws-zbook-one-request-in-flight.json +2110 -0
  7. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0004-execution-backends.md +3 -2
  8. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0012-modbus-one-request-in-flight.md +26 -1
  9. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/backends.md +54 -6
  10. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/benchmarks.md +4 -0
  11. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/dsl-reference.md +17 -3
  12. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/examples.md +19 -0
  13. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/index.md +2 -2
  14. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/language-reference.md +15 -1
  15. smolpy-1.11.1.dev8/docs/modbus.md +59 -0
  16. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/roadmap.md +17 -1
  17. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/README.md +16 -1
  18. smolpy-1.11.1.dev8/examples/example_modbus_timeout.smol +50 -0
  19. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/backends.py +14 -2
  20. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/ns3/__init__.py +68 -8
  21. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/ns3/cpp/smol-ns3.cc +176 -14
  22. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_benchmarks.py +40 -0
  23. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_ns3.py +7 -8
  24. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_outstanding.py +120 -1
  25. smolpy-1.11.1.dev5/docs/modbus.md +0 -23
  26. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/.github/workflows/ci.yml +0 -0
  27. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/.github/workflows/dev-build.yml +0 -0
  28. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/.github/workflows/docker-image.yml +0 -0
  29. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/.github/workflows/docs.yml +0 -0
  30. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/.github/workflows/github-release.yml +0 -0
  31. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/.github/workflows/ns3-base.yml +0 -0
  32. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/.github/workflows/publish.yml +0 -0
  33. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/.github/workflows/release.yml +0 -0
  34. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/.github/workflows/rust-wheels.yml +0 -0
  35. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/.gitignore +0 -0
  36. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/LICENSE +0 -0
  37. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/__init__.py +0 -0
  38. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/load.py +0 -0
  39. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/results/2026-11-13-0921-simpy-jaws-zbook-baseline.json +0 -0
  40. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/results/2026-11-13-1527-simpy-jaws-zbook-optimised.json +0 -0
  41. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/results/2026-11-13-2116-simpy-jaws-zbook-research-batch.json +0 -0
  42. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/results/2026-11-13-2119-simpy-jaws-zbook-research-b4.json +0 -0
  43. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/results/2026-11-15-1255-rust-jaws-zbook-stop-criterion.json +0 -0
  44. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/results/2026-11-15-1333-rust-jaws-zbook-research-b4.json +0 -0
  45. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/results/2026-11-15-1346-rust-jaws-zbook-research-batch.json +0 -0
  46. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/results/2026-11-16-1839-simpy-ns3-jaws-zbook-tcp-under-load.json +0 -0
  47. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/results/2026-11-23-1228-simpy-rust-ns3-jaws-zbook-bounded-buffers.json +0 -0
  48. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/runner.py +0 -0
  49. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/scenarios.py +0 -0
  50. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/benchmarks/worker.py +0 -0
  51. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docker/Dockerfile +0 -0
  52. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docker/Dockerfile.dockerignore +0 -0
  53. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docker/Dockerfile.ns3 +0 -0
  54. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docker/Dockerfile.ns3.dockerignore +0 -0
  55. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docker/ns3-base/Dockerfile +0 -0
  56. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docker/ns3-base/smoke.cc +0 -0
  57. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docker/smoke.smol +0 -0
  58. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0001-protocol-package-structure.md +0 -0
  59. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0002-modbus-tcp-implementation.md +0 -0
  60. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0003-smol-external-dsl.md +0 -0
  61. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0005-profinet-rt.md +0 -0
  62. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0006-profiling-and-baseline-benchmark.md +0 -0
  63. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0007-execution-independent-scenario-model.md +0 -0
  64. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0008-rust-des-engine-mvp.md +0 -0
  65. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0009-batch-execution-and-cross-backend-validation.md +0 -0
  66. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0010-ethernet-frames-on-the-wire.md +0 -0
  67. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/adr/0011-bounded-switch-buffers.md +0 -0
  68. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/dashboard.md +0 -0
  69. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/model-semantics.md +0 -0
  70. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/mqtt.md +0 -0
  71. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/profinet.md +0 -0
  72. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/scenario-model.md +0 -0
  73. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/docs/simulation-engine.md +0 -0
  74. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example.py +0 -0
  75. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example.smol +0 -0
  76. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example_10_clients.py +0 -0
  77. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example_12_clients.py +0 -0
  78. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example_20_clients.py +0 -0
  79. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example_bounded_buffer.smol +0 -0
  80. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example_file_transfer.py +0 -0
  81. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example_modbus.py +0 -0
  82. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example_mqtt.py +0 -0
  83. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example_profinet.py +0 -0
  84. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example_profinet.smol +0 -0
  85. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example_staggered_transfer.py +0 -0
  86. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/examples/example_two_tier.py +0 -0
  87. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/mkdocs.yml +0 -0
  88. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/pyproject.toml +0 -0
  89. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/Cargo.lock +0 -0
  90. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/Cargo.toml +0 -0
  91. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smol-engine/Cargo.toml +0 -0
  92. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smol-engine/src/frames.rs +0 -0
  93. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smol-engine/src/lib.rs +0 -0
  94. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smol-engine/src/rng.rs +0 -0
  95. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smol-engine/src/scenario.rs +0 -0
  96. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smol-engine/src/sim.rs +0 -0
  97. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smol-engine/src/timebase.rs +0 -0
  98. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smolpy-engine-rs/Cargo.toml +0 -0
  99. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smolpy-engine-rs/README.md +0 -0
  100. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smolpy-engine-rs/pyproject.toml +0 -0
  101. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smolpy-engine-rs/smoke_test.py +0 -0
  102. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/rust/smolpy-engine-rs/src/lib.rs +0 -0
  103. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/__init__.py +0 -0
  104. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/_worker.py +0 -0
  105. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/batch.py +0 -0
  106. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/cli.py +0 -0
  107. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/core/__init__.py +0 -0
  108. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/core/adapter.py +0 -0
  109. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/core/batch.py +0 -0
  110. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/core/link.py +0 -0
  111. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/core/network.py +0 -0
  112. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/core/node.py +0 -0
  113. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/core/observation.py +0 -0
  114. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/ethernet/__init__.py +0 -0
  115. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/ethernet/switch.py +0 -0
  116. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/lang/__init__.py +0 -0
  117. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/lang/ast.py +0 -0
  118. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/lang/errors.py +0 -0
  119. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/lang/grammar.lark +0 -0
  120. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/lang/interpreter.py +0 -0
  121. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/lang/transformer.py +0 -0
  122. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/modbus/__init__.py +0 -0
  123. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/modbus/slave.py +0 -0
  124. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/model/__init__.py +0 -0
  125. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/model/frames.py +0 -0
  126. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/model/scenario.py +0 -0
  127. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/model/streams.py +0 -0
  128. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/model/timebase.py +0 -0
  129. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/model/validate.py +0 -0
  130. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/mqtt/__init__.py +0 -0
  131. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/mqtt/broker.py +0 -0
  132. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/profinet/__init__.py +0 -0
  133. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/profinet/device.py +0 -0
  134. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/sim/__init__.py +0 -0
  135. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/sim/engine.py +0 -0
  136. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/stats.py +0 -0
  137. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/viz/__init__.py +0 -0
  138. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/viz/dashboard.py +0 -0
  139. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/src/smolpy/viz/text_dashboard.py +0 -0
  140. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/__init__.py +0 -0
  141. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/equivalence/__init__.py +0 -0
  142. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/equivalence/harness.py +0 -0
  143. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/equivalence/scenarios.py +0 -0
  144. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/equivalence/test_equivalence.py +0 -0
  145. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/equivalence/test_rust_timebase.py +0 -0
  146. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_backends.py +0 -0
  147. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_batch.py +0 -0
  148. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_buffers.py +0 -0
  149. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_cli.py +0 -0
  150. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_dsl.py +0 -0
  151. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_engine_ir.py +0 -0
  152. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_lang.py +0 -0
  153. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_model.py +0 -0
  154. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_profinet.py +0 -0
  155. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_semantics.py +0 -0
  156. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_simulation.py +0 -0
  157. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_stats.py +0 -0
  158. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_sweep.py +0 -0
  159. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_timebase.py +0 -0
  160. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/tests/test_validate.py +0 -0
  161. {smolpy-1.11.1.dev5 → smolpy-1.11.1.dev8}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: smolpy
3
- Version: 1.11.1.dev5
3
+ Version: 1.11.1.dev8
4
4
  Summary: Network simulation DSL and discrete-event simulator
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -61,7 +61,7 @@ SMOLPy lets you describe a network topology in pure Python, define traffic flows
61
61
  |---|---|---|---|---|---|
62
62
  | **Ethernet** (generic traffic) | Layer 2 frames | One-way flows: constant, Poisson, bursty, batch | `Adapter.sends()` | `flow` | `throughput`, `latency`, `bytes_sent`, `bytes_received` |
63
63
  | **MQTT** | TCP/IP | Publish / subscribe through a broker, QoS 0 and 1 | `MQTTBroker`, `Adapter.publishes()`, `MQTTBroker.routes()` | `mqtt_broker`, `publish`, `route` | `broker_queue`, `latency` |
64
- | **Modbus TCP** | TCP/IP | Request / response polling (Read Holding Registers, FC 03) | `ModbusSlave`, `Adapter.polls()` | `modbus_slave`, `poll` | `modbus_latency` |
64
+ | **Modbus TCP** | TCP/IP | Request / response polling (Read Holding Registers, FC 03) | `ModbusSlave`, `Adapter.polls()` | `modbus_slave`, `poll` | `modbus_latency`, `modbus_unanswered`, `modbus_timeouts`, `modbus_skipped` |
65
65
  | **PROFINET RT** | Layer 2 (EtherType 0x8892), 802.1Q priority 6 | Cyclic producer / consumer exchange with watchdog | `ProfinetDevice`, `Adapter.controls()` | `profinet_device`, `control` | `pn_latency`, `pn_jitter`, `pn_watchdog_expiries` |
66
66
 
67
67
  Infrastructure: MAC-learning **switches** with 802.1Q strict-priority egress queues (`qos="strict"`, or `qos="fifo"` to disable prioritisation), unbounded or bounded with tail drop (`buffer=` in bytes). One `Adapter` can act in several roles at once — e.g. a PLC that is a Modbus master, an MQTT publisher and a PROFINET controller.
@@ -236,6 +236,8 @@ broker.routes("plant/temp", to=[server])
236
236
  # Modbus TCP poll (master → slave, Read Holding Registers)
237
237
  plc.polls(slave, register=40001, count=10, rate=1.0)
238
238
  plc.polls(slave, register=30001, count=5, rate=2.0, delay_ms=500)
239
+ # ...waiting for each response, with a timeout of 1 s
240
+ plc.polls(meter, register=0, count=10, rate=100, outstanding=1, timeout_ms=1_000)
239
241
 
240
242
  # PROFINET RT cyclic I/O (controller ↔ device), 4 ms update time
241
243
  plc.controls(device, cycle=4, inputs=32, outputs=16, hold=3)
@@ -270,6 +272,8 @@ plc.controls(device, cycle=4, inputs=32, outputs=16, hold=3)
270
272
  | `count` | int | Number of registers to read |
271
273
  | `rate` | float | Polls per second (default 1.0) |
272
274
  | `delay_ms` | float | Simulation time before polling starts (default 0) |
275
+ | `outstanding` | int \| None | `1`: at most one request of the pair awaits a response; `None`: unlimited (default) |
276
+ | `timeout_ms` | float \| None | Response timeout, with `outstanding=1` (default `None`: no timeout) |
273
277
 
274
278
  **`controls()` parameters**
275
279
 
@@ -323,6 +327,8 @@ net.observe(metric, on=node, every=interval_ms)
323
327
  | `frames_sent` | frames | Adapter (sender) |
324
328
  | `frames_received` | frames | Adapter (receiver) |
325
329
  | `modbus_unanswered` | polls | Adapter (master): polls without a response so far, lost or in flight |
330
+ | `modbus_timeouts` | polls | Adapter (master): requests that timed out so far, with `outstanding=1` |
331
+ | `modbus_skipped` | polls | Adapter (master): poll instants skipped so far, because a request was outstanding |
326
332
 
327
333
  ### Simulation
328
334
 
@@ -435,6 +441,7 @@ SMOLPy also models Modbus TCP — a request/response protocol, unlike MQTT's fir
435
441
  - **Each slave** is addressed by its own `unit_id` (1–247); it replies only to requests matching its `unit_id` and ignores everything else. Multiple sensors can share one switch, each polled independently by the same master.
436
442
  - **Every poll is a request/response round trip** — both frames traverse the network and contend for bandwidth, unlike MQTT where only the publisher-to-broker leg carries the payload.
437
443
  - **`modbus_latency`** measures poll round-trip time (RTT): the time from when the master sends a request to when the matching response arrives back. This is the key metric for judging whether a polling interval is achievable on a given network.
444
+ - **One request in flight.** By default a poll is open loop: a request goes out at every instant of its schedule. With `outstanding=1` the master waits for each response, as a usual Modbus TCP master does: an instant that comes while a request is outstanding is skipped (`modbus_skipped`), and `timeout_ms` sets a response timeout (`modbus_timeouts`). On ns-3, with Linux's minimum RTO, a lost response then comes back about 210 ms after its request, as on real hardware ([ADR-0012](https://jwszolek.github.io/SMOLPy/adr/0012-modbus-one-request-in-flight/), [Modbus TCP](https://jwszolek.github.io/SMOLPy/modbus/)).
438
445
 
439
446
  ### Frame size formula
440
447
 
@@ -508,7 +515,7 @@ smolpy run plant.smol --backend rust
508
515
  ```
509
516
 
510
517
  - **The same numbers.** On deterministic scenarios the Rust engine reproduces SimPy's results bit for bit, down to the event count. Random traffic uses its own generator, so there the results agree statistically. ns-3 draws random traffic from SimPy's streams, so its Ethernet and PROFINET RT results are bit for bit with the same seed, random traffic included. CI checks both on every pull request ([ADR-0009](https://jwszolek.github.io/SMOLPy/adr/0009-batch-execution-and-cross-backend-validation/)).
511
- - **ns-3 adds TCP.** Ethernet and PROFINET on ns-3 also give SimPy's results bit for bit. Modbus and MQTT run over ns-3's TCP, so their results differ by what TCP does: under heavy load by up to +43 % in latency. [Execution backends](https://jwszolek.github.io/SMOLPy/backends/) has the details and measurements.
518
+ - **ns-3 adds TCP.** Ethernet and PROFINET on ns-3 also give SimPy's results bit for bit. Modbus and MQTT run over ns-3's TCP, so their results differ by what TCP does: under heavy load by up to +44 % in latency, and under loss by TCP's retransmissions. [Execution backends](https://jwszolek.github.io/SMOLPy/backends/) has the details and measurements.
512
519
  - **Nothing is skipped silently.** A scenario that uses something a backend does not support is rejected before the run with a message naming the element. Asking the Rust engine for a dashboard is an error too.
513
520
 
514
521
  The model every engine implements:
@@ -535,7 +542,7 @@ result = net.simulate(duration=60_000, backend="ns3")
535
542
  ```
536
543
 
537
544
  **What it is for.**
538
- - **A real TCP.** SMOL sizes Modbus TCP and MQTT frames as TCP segments, but SimPy and Rust do not model TCP's behaviour. On ns-3 every Modbus master–slave and MQTT client–broker pair has one persistent connection over ns-3's TCP: the handshake, delayed acknowledgements, CUBIC congestion control and the receiver's window.
545
+ - **A real TCP.** SMOL sizes Modbus TCP and MQTT frames as TCP segments, but SimPy and Rust do not model TCP's behaviour. On ns-3 every Modbus master–slave and MQTT client–broker pair has one persistent connection over ns-3's TCP: the handshake, delayed acknowledgements, CUBIC congestion control, the receiver's window and retransmission. Its minimum RTO, delayed-ACK and SYN timeouts are Linux's (`smolpy.ns3.TcpSettings`).
539
546
  - **A cross-check against an established simulator.** Below the TCP layer, ns-3 runs SMOL's own full-duplex Ethernet device and switch. So Ethernet over UDP and PROFINET RT on layer 2 give SimPy's results **bit for bit**, watchdog expiries and stochastic traffic included. That ties SMOL's reference model to ns-3's event scheduler and IP stack.
540
547
  - **Where TCP matters.** `python -m benchmarks load` runs a plant cell whose Modbus and MQTT traffic shares a 10 Mb/s uplink with a UDP camera, from 50 % to 150 % offered load:
541
548
 
@@ -543,7 +550,7 @@ result = net.simulate(duration=60_000, backend="ns3")
543
550
  |---|---|---|---|
544
551
  | 0.50 – 0.95 | within 0.4 % | within 0.4 % | the same |
545
552
  | 1.00 | +18 % | +25 % | the same |
546
- | 1.50 | 3.2 → 3.4 s (+6 %) | 3.2 → 4.5 s (+43 %) | −41 % |
553
+ | 1.50 | 3.2 → 3.4 s (+6 %) | 3.2 → 4.6 s (+44 %) | −40 % |
547
554
 
548
555
  Below saturation the engines agree. At saturation, TCP's own acknowledgements tip the link over. Heavily overloaded, TCP's windows hold MQTT back while the UDP stream, which does not back off, takes the link. [Execution backends](https://jwszolek.github.io/SMOLPy/backends/#modbus-and-mqtt-over-tcp) has the full table and the mechanism.
549
556
 
@@ -553,7 +560,7 @@ Below saturation the engines agree. At saturation, TCP's own acknowledgements ti
553
560
 
554
561
  ## Examples
555
562
 
556
- See [`examples/README.md`](examples/README.md) for ten ready-to-run scenarios covering single-switch saturation, oversubscription, two-tier access bottlenecks, MQTT publish-subscribe, Modbus TCP polling, and PROFINET RT cyclic I/O.
563
+ See [`examples/README.md`](examples/README.md) for twelve ready-to-run scenarios covering single-switch saturation, oversubscription, two-tier access bottlenecks, MQTT publish-subscribe, Modbus TCP polling, PROFINET RT cyclic I/O, a bounded switch buffer, and a Modbus master that waits for each response.
557
564
 
558
565
  ```bash
559
566
  uv run smolpy run examples/example.py
@@ -33,7 +33,7 @@ SMOLPy lets you describe a network topology in pure Python, define traffic flows
33
33
  |---|---|---|---|---|---|
34
34
  | **Ethernet** (generic traffic) | Layer 2 frames | One-way flows: constant, Poisson, bursty, batch | `Adapter.sends()` | `flow` | `throughput`, `latency`, `bytes_sent`, `bytes_received` |
35
35
  | **MQTT** | TCP/IP | Publish / subscribe through a broker, QoS 0 and 1 | `MQTTBroker`, `Adapter.publishes()`, `MQTTBroker.routes()` | `mqtt_broker`, `publish`, `route` | `broker_queue`, `latency` |
36
- | **Modbus TCP** | TCP/IP | Request / response polling (Read Holding Registers, FC 03) | `ModbusSlave`, `Adapter.polls()` | `modbus_slave`, `poll` | `modbus_latency` |
36
+ | **Modbus TCP** | TCP/IP | Request / response polling (Read Holding Registers, FC 03) | `ModbusSlave`, `Adapter.polls()` | `modbus_slave`, `poll` | `modbus_latency`, `modbus_unanswered`, `modbus_timeouts`, `modbus_skipped` |
37
37
  | **PROFINET RT** | Layer 2 (EtherType 0x8892), 802.1Q priority 6 | Cyclic producer / consumer exchange with watchdog | `ProfinetDevice`, `Adapter.controls()` | `profinet_device`, `control` | `pn_latency`, `pn_jitter`, `pn_watchdog_expiries` |
38
38
 
39
39
  Infrastructure: MAC-learning **switches** with 802.1Q strict-priority egress queues (`qos="strict"`, or `qos="fifo"` to disable prioritisation), unbounded or bounded with tail drop (`buffer=` in bytes). One `Adapter` can act in several roles at once — e.g. a PLC that is a Modbus master, an MQTT publisher and a PROFINET controller.
@@ -208,6 +208,8 @@ broker.routes("plant/temp", to=[server])
208
208
  # Modbus TCP poll (master → slave, Read Holding Registers)
209
209
  plc.polls(slave, register=40001, count=10, rate=1.0)
210
210
  plc.polls(slave, register=30001, count=5, rate=2.0, delay_ms=500)
211
+ # ...waiting for each response, with a timeout of 1 s
212
+ plc.polls(meter, register=0, count=10, rate=100, outstanding=1, timeout_ms=1_000)
211
213
 
212
214
  # PROFINET RT cyclic I/O (controller ↔ device), 4 ms update time
213
215
  plc.controls(device, cycle=4, inputs=32, outputs=16, hold=3)
@@ -242,6 +244,8 @@ plc.controls(device, cycle=4, inputs=32, outputs=16, hold=3)
242
244
  | `count` | int | Number of registers to read |
243
245
  | `rate` | float | Polls per second (default 1.0) |
244
246
  | `delay_ms` | float | Simulation time before polling starts (default 0) |
247
+ | `outstanding` | int \| None | `1`: at most one request of the pair awaits a response; `None`: unlimited (default) |
248
+ | `timeout_ms` | float \| None | Response timeout, with `outstanding=1` (default `None`: no timeout) |
245
249
 
246
250
  **`controls()` parameters**
247
251
 
@@ -295,6 +299,8 @@ net.observe(metric, on=node, every=interval_ms)
295
299
  | `frames_sent` | frames | Adapter (sender) |
296
300
  | `frames_received` | frames | Adapter (receiver) |
297
301
  | `modbus_unanswered` | polls | Adapter (master): polls without a response so far, lost or in flight |
302
+ | `modbus_timeouts` | polls | Adapter (master): requests that timed out so far, with `outstanding=1` |
303
+ | `modbus_skipped` | polls | Adapter (master): poll instants skipped so far, because a request was outstanding |
298
304
 
299
305
  ### Simulation
300
306
 
@@ -407,6 +413,7 @@ SMOLPy also models Modbus TCP — a request/response protocol, unlike MQTT's fir
407
413
  - **Each slave** is addressed by its own `unit_id` (1–247); it replies only to requests matching its `unit_id` and ignores everything else. Multiple sensors can share one switch, each polled independently by the same master.
408
414
  - **Every poll is a request/response round trip** — both frames traverse the network and contend for bandwidth, unlike MQTT where only the publisher-to-broker leg carries the payload.
409
415
  - **`modbus_latency`** measures poll round-trip time (RTT): the time from when the master sends a request to when the matching response arrives back. This is the key metric for judging whether a polling interval is achievable on a given network.
416
+ - **One request in flight.** By default a poll is open loop: a request goes out at every instant of its schedule. With `outstanding=1` the master waits for each response, as a usual Modbus TCP master does: an instant that comes while a request is outstanding is skipped (`modbus_skipped`), and `timeout_ms` sets a response timeout (`modbus_timeouts`). On ns-3, with Linux's minimum RTO, a lost response then comes back about 210 ms after its request, as on real hardware ([ADR-0012](https://jwszolek.github.io/SMOLPy/adr/0012-modbus-one-request-in-flight/), [Modbus TCP](https://jwszolek.github.io/SMOLPy/modbus/)).
410
417
 
411
418
  ### Frame size formula
412
419
 
@@ -480,7 +487,7 @@ smolpy run plant.smol --backend rust
480
487
  ```
481
488
 
482
489
  - **The same numbers.** On deterministic scenarios the Rust engine reproduces SimPy's results bit for bit, down to the event count. Random traffic uses its own generator, so there the results agree statistically. ns-3 draws random traffic from SimPy's streams, so its Ethernet and PROFINET RT results are bit for bit with the same seed, random traffic included. CI checks both on every pull request ([ADR-0009](https://jwszolek.github.io/SMOLPy/adr/0009-batch-execution-and-cross-backend-validation/)).
483
- - **ns-3 adds TCP.** Ethernet and PROFINET on ns-3 also give SimPy's results bit for bit. Modbus and MQTT run over ns-3's TCP, so their results differ by what TCP does: under heavy load by up to +43 % in latency. [Execution backends](https://jwszolek.github.io/SMOLPy/backends/) has the details and measurements.
490
+ - **ns-3 adds TCP.** Ethernet and PROFINET on ns-3 also give SimPy's results bit for bit. Modbus and MQTT run over ns-3's TCP, so their results differ by what TCP does: under heavy load by up to +44 % in latency, and under loss by TCP's retransmissions. [Execution backends](https://jwszolek.github.io/SMOLPy/backends/) has the details and measurements.
484
491
  - **Nothing is skipped silently.** A scenario that uses something a backend does not support is rejected before the run with a message naming the element. Asking the Rust engine for a dashboard is an error too.
485
492
 
486
493
  The model every engine implements:
@@ -507,7 +514,7 @@ result = net.simulate(duration=60_000, backend="ns3")
507
514
  ```
508
515
 
509
516
  **What it is for.**
510
- - **A real TCP.** SMOL sizes Modbus TCP and MQTT frames as TCP segments, but SimPy and Rust do not model TCP's behaviour. On ns-3 every Modbus master–slave and MQTT client–broker pair has one persistent connection over ns-3's TCP: the handshake, delayed acknowledgements, CUBIC congestion control and the receiver's window.
517
+ - **A real TCP.** SMOL sizes Modbus TCP and MQTT frames as TCP segments, but SimPy and Rust do not model TCP's behaviour. On ns-3 every Modbus master–slave and MQTT client–broker pair has one persistent connection over ns-3's TCP: the handshake, delayed acknowledgements, CUBIC congestion control, the receiver's window and retransmission. Its minimum RTO, delayed-ACK and SYN timeouts are Linux's (`smolpy.ns3.TcpSettings`).
511
518
  - **A cross-check against an established simulator.** Below the TCP layer, ns-3 runs SMOL's own full-duplex Ethernet device and switch. So Ethernet over UDP and PROFINET RT on layer 2 give SimPy's results **bit for bit**, watchdog expiries and stochastic traffic included. That ties SMOL's reference model to ns-3's event scheduler and IP stack.
512
519
  - **Where TCP matters.** `python -m benchmarks load` runs a plant cell whose Modbus and MQTT traffic shares a 10 Mb/s uplink with a UDP camera, from 50 % to 150 % offered load:
513
520
 
@@ -515,7 +522,7 @@ result = net.simulate(duration=60_000, backend="ns3")
515
522
  |---|---|---|---|
516
523
  | 0.50 – 0.95 | within 0.4 % | within 0.4 % | the same |
517
524
  | 1.00 | +18 % | +25 % | the same |
518
- | 1.50 | 3.2 → 3.4 s (+6 %) | 3.2 → 4.5 s (+43 %) | −41 % |
525
+ | 1.50 | 3.2 → 3.4 s (+6 %) | 3.2 → 4.6 s (+44 %) | −40 % |
519
526
 
520
527
  Below saturation the engines agree. At saturation, TCP's own acknowledgements tip the link over. Heavily overloaded, TCP's windows hold MQTT back while the UDP stream, which does not back off, takes the link. [Execution backends](https://jwszolek.github.io/SMOLPy/backends/#modbus-and-mqtt-over-tcp) has the full table and the mechanism.
521
528
 
@@ -525,7 +532,7 @@ Below saturation the engines agree. At saturation, TCP's own acknowledgements ti
525
532
 
526
533
  ## Examples
527
534
 
528
- See [`examples/README.md`](examples/README.md) for ten ready-to-run scenarios covering single-switch saturation, oversubscription, two-tier access bottlenecks, MQTT publish-subscribe, Modbus TCP polling, and PROFINET RT cyclic I/O.
535
+ See [`examples/README.md`](examples/README.md) for twelve ready-to-run scenarios covering single-switch saturation, oversubscription, two-tier access bottlenecks, MQTT publish-subscribe, Modbus TCP polling, PROFINET RT cyclic I/O, a bounded switch buffer, and a Modbus master that waits for each response.
529
536
 
530
537
  ```bash
531
538
  uv run smolpy run examples/example.py
@@ -9,6 +9,8 @@ python -m benchmarks load [--loads 0.5 0.9 1.0 1.2] [--duration 20000] [--backen
9
9
  python -m benchmarks load-summary benchmarks/results/<file>.json
10
10
  python -m benchmarks loss [--loads 0.93 0.996] [--duration 30000] [--backend simpy rust ns3]
11
11
  python -m benchmarks loss-summary benchmarks/results/<file>.json
12
+ python -m benchmarks closed-loop [--loads 0.99] [--duration 30000] [--backend simpy rust ns3]
13
+ python -m benchmarks closed-loop-summary benchmarks/results/<file>.json
12
14
  """
13
15
 
14
16
  from __future__ import annotations
@@ -20,7 +22,7 @@ import subprocess
20
22
  import sys
21
23
  from pathlib import Path
22
24
 
23
- from benchmarks import loss
25
+ from benchmarks import closed_loop, loss
24
26
  from benchmarks.load import DURATION_MS, LOADS, run_load, summarize_load
25
27
  from benchmarks.runner import parse_size, run_batch, run_suite, size_label, summarize
26
28
 
@@ -103,6 +105,22 @@ def main() -> None:
103
105
  loss_summ = sub.add_parser("loss-summary", help="markdown table of a loss results file")
104
106
  loss_summ.add_argument("file", type=Path)
105
107
 
108
+ closed = sub.add_parser(
109
+ "closed-loop", help="the testbed of ADR-0012, one Modbus request in flight, every engine"
110
+ )
111
+ closed.add_argument("--loads", nargs="+", type=float, default=list(closed_loop.LOADS))
112
+ closed.add_argument(
113
+ "--duration", type=float, default=closed_loop.DURATION_MS, help="simulated ms"
114
+ )
115
+ closed.add_argument("--backend", nargs="+", default=list(closed_loop.ENGINES))
116
+ closed.add_argument("--label", default="one-request-in-flight")
117
+ closed.add_argument("--out", type=Path, default=None)
118
+
119
+ closed_summ = sub.add_parser(
120
+ "closed-loop-summary", help="markdown tables of a closed-loop results file"
121
+ )
122
+ closed_summ.add_argument("file", type=Path)
123
+
106
124
  a = p.parse_args()
107
125
  if a.cmd == "run":
108
126
  sizes = [parse_size(s) for s in a.frames]
@@ -125,6 +143,12 @@ def main() -> None:
125
143
  print(loss.summarize_loss(out))
126
144
  elif a.cmd == "loss-summary":
127
145
  print(loss.summarize_loss(a.file))
146
+ elif a.cmd == "closed-loop":
147
+ out = closed_loop.run_closed_loop(a.loads, a.duration, a.backend, a.label, a.out)
148
+ print(f"results written to {out}")
149
+ print(closed_loop.summarize_closed_loop(out))
150
+ elif a.cmd == "closed-loop-summary":
151
+ print(closed_loop.summarize_closed_loop(a.file))
128
152
  elif a.cmd == "batch":
129
153
  frames = parse_size(a.frames)
130
154
  r = run_batch(a.scenario, frames, a.metrics, a.runs, a.jobs, a.timeout, a.seed, a.backend)
@@ -0,0 +1,199 @@
1
+ """One Modbus request in flight on the three engines: the testbed of ADR-0012.
2
+
3
+ Scenario T2 is T1 of ``benchmarks.loss`` as the testbed measured it with
4
+ egress buffers of 60 frames (``buffer=91080``): Poisson UDP of 1 518 B
5
+ frames at rho of the laptop's 100 Mb/s port, and the laptop polling the
6
+ Modbus TCP server every 10 ms with one request in flight (``outstanding=1``),
7
+ waiting for each response.
8
+
9
+ On the hardware, 3 of 1 680 polls (0.18 %) lost their response, and TCP
10
+ brought each back after its retransmission timeout: a round trip of about
11
+ 215 ms, Linux's minimum RTO of 200 ms plus the RTT. With one request in
12
+ flight no later segment follows a lost response, so no duplicate ACKs
13
+ trigger a fast retransmit.
14
+
15
+ Each load runs with several seeds, with no timeout and with a timeout of
16
+ 1 s, on every engine:
17
+ - ns-3 runs Modbus over its TCP, set to Linux's (``smolpy.ns3.TcpSettings``):
18
+ a lost response comes back after the RTO. A timeout of 1 s never fires;
19
+ - SimPy and Rust have no TCP: a lost request or response is a timeout, or,
20
+ with none, stops the polling for the rest of the run.
21
+
22
+ The record keeps, per run:
23
+ - the polls sent, and the poll instants skipped while a request was
24
+ outstanding;
25
+ - the round trip's median and p99 of its means over 1 ms windows;
26
+ - every long round trip, over ``LONG_MS``, in ms. Each has a window of its
27
+ own: no other request is in flight while it lasts;
28
+ - the polls affected: long round trips, timeouts, and polls unanswered at
29
+ the end, as a share of the polls sent;
30
+ - the share of frames the switch dropped, of the frames the Pi sent.
31
+
32
+ python -m benchmarks closed-loop [--loads 0.99] [--duration 30000]
33
+ """
34
+
35
+ from __future__ import annotations
36
+
37
+ import datetime as dt
38
+ import json
39
+ import math
40
+ import statistics
41
+ from pathlib import Path
42
+
43
+ from benchmarks import loss
44
+ from benchmarks.runner import RESULTS_DIR, environment
45
+ from smolpy import backends
46
+ from smolpy.model import timebase as tb
47
+
48
+ BUFFER = 60 * loss.FRAME # 91 080 B, as the testbed's switch was measured
49
+ LOADS = (0.985, 0.99, 0.996)
50
+ TIMEOUTS: tuple[float | None, ...] = (None, 1_000.0)
51
+ DURATION_MS = loss.DURATION_MS
52
+ ENGINES = loss.ENGINES
53
+ SEEDS = loss.SEEDS
54
+ LONG_MS = 100.0 # a round trip far over any queueing delay (at most 7.4 ms)
55
+ # the testbed, at rho = 0.985 and 0.996
56
+ MEASURED = {
57
+ "affected": "3 of 1 680 polls (0.18 %)",
58
+ "long_rtt_ms": "about 215",
59
+ }
60
+
61
+
62
+ def _instants(until_ms: float) -> int:
63
+ """The poll instants up to *until_ms*, which falls on none."""
64
+ end = tb.ms_to_ns(until_ms)
65
+ n = 0
66
+ for t in tb.instants(0, tb.interval_ns(loss.POLL_RATE)):
67
+ if t > end:
68
+ return n
69
+ n += 1
70
+ raise AssertionError("unreachable")
71
+
72
+
73
+ def _summary(metrics: dict[str, list[tuple[float, float]]]) -> dict[str, object]:
74
+ rtt = [v / 1_000 for _, v in metrics["modbus_latency:laptop"]] # ms
75
+ last = {k: (s[-1][1] if s else math.nan) for k, s in metrics.items()}
76
+ long = sorted(r for r in rtt if r > LONG_MS)
77
+ timeouts = last["modbus_timeouts:laptop"]
78
+ unanswered = last["modbus_unanswered:laptop"]
79
+ at, skipped = metrics["modbus_skipped:laptop"][-1]
80
+ sent = _instants(at) - skipped
81
+ affected = len(long) + unanswered # timed out or still unanswered at the end
82
+ q = statistics.quantiles(rtt, n=100) if len(rtt) > 1 else [math.nan] * 99
83
+ return {
84
+ "sent": sent,
85
+ "skipped": skipped,
86
+ "rtt_median_ms": q[49],
87
+ "rtt_p99_ms": q[98],
88
+ "long_rtts_ms": long,
89
+ "timeouts": timeouts,
90
+ "unanswered": unanswered,
91
+ "affected": affected / sent if sent else math.nan,
92
+ "dropped": last["drops_total:sw"] / last["frames_sent:pi"],
93
+ }
94
+
95
+
96
+ def run_closed_loop(
97
+ loads: list[float],
98
+ duration_ms: float,
99
+ engines: list[str],
100
+ label: str = "one-request-in-flight",
101
+ out: Path | None = None,
102
+ seeds: tuple[int, ...] = SEEDS,
103
+ timeouts: tuple[float | None, ...] = TIMEOUTS,
104
+ ) -> Path:
105
+ env = environment()
106
+ stamp = dt.datetime.now().strftime("%Y-%m-%d-%H%M")
107
+ out = out or RESULTS_DIR / f"{stamp}-{'-'.join(engines)}-{env['host']}-{label}.json"
108
+ out.parent.mkdir(parents=True, exist_ok=True)
109
+ doc: dict[str, object] = {
110
+ "format": "smolpy-closed-loop",
111
+ "version": 1,
112
+ "label": label,
113
+ "created": dt.datetime.now().isoformat(timespec="seconds"),
114
+ "environment": env,
115
+ "scenario": "T2",
116
+ "buffer_bytes": BUFFER,
117
+ "duration_ms": duration_ms,
118
+ "seeds": list(seeds),
119
+ "measured": MEASURED,
120
+ "runs": [],
121
+ }
122
+ runs: list[dict[str, object]] = []
123
+ doc["runs"] = runs
124
+ for timeout in timeouts:
125
+ for rho in loads:
126
+ for seed in seeds:
127
+ sc = loss.scenario(
128
+ rho, duration_ms, BUFFER, seed, outstanding=1, timeout_ms=timeout
129
+ )
130
+ for engine in engines:
131
+ result = backends.get(engine).run(sc)
132
+ s = _summary(result.metrics)
133
+ runs.append(
134
+ {
135
+ "timeout_ms": timeout,
136
+ "rho": rho,
137
+ "seed": seed,
138
+ "backend": engine,
139
+ "events": result.stats.events,
140
+ "wall_s": result.stats.wall_s,
141
+ "summary": s,
142
+ }
143
+ )
144
+ out.write_text(json.dumps(doc, indent=1)) # keep partial progress
145
+ long = s["long_rtts_ms"]
146
+ assert isinstance(long, list)
147
+ print(
148
+ f"timeout {timeout} rho {rho:5.3f} seed {seed} {engine:6s}"
149
+ f" sent {s['sent']:5.0f} skipped {s['skipped']:5.0f}"
150
+ f" long {[round(r) for r in long]} timeouts {s['timeouts']:3.0f}"
151
+ f" unanswered {s['unanswered']:2.0f} affected {s['affected']:.2%}"
152
+ f" dropped {s['dropped']:.3%} ({runs[-1]['wall_s']:.1f} s)",
153
+ flush=True,
154
+ )
155
+ return out
156
+
157
+
158
+ def summarize_closed_loop(path: Path) -> str:
159
+ """Markdown tables, one per timeout: each load and engine over the seeds."""
160
+ doc = json.loads(path.read_text())
161
+ groups: dict[tuple[float | None, float, str], list[dict]] = {}
162
+ for r in doc["runs"]:
163
+ groups.setdefault((r["timeout_ms"], r["rho"], r["backend"]), []).append(r["summary"])
164
+ lines = [
165
+ f"T2, buffer {doc['buffer_bytes']} B, {doc['duration_ms'] / 1000:g} s per run,"
166
+ f" seeds {doc['seeds']}: sums or means over the seeds. The testbed:"
167
+ f" {doc['measured']['affected']} affected, long RTTs {doc['measured']['long_rtt_ms']} ms."
168
+ ]
169
+ for timeout in dict.fromkeys(t for t, _, _ in groups):
170
+ lines += [
171
+ "",
172
+ f"Timeout: {'none' if timeout is None else f'{timeout:g} ms'}.",
173
+ "",
174
+ "| rho | engine | polls sent | skipped | RTT median (ms) | RTT p99 (ms)"
175
+ " | long RTTs (ms): n, min, median, max | timeouts | unanswered | affected"
176
+ " | dropped |",
177
+ "|---|---|---|---|---|---|---|---|---|---|---|",
178
+ ]
179
+ for (t, rho, engine), runs in groups.items():
180
+ if t != timeout:
181
+ continue
182
+ long = sorted(r for s in runs for r in s["long_rtts_ms"])
183
+ spread = (
184
+ f"{len(long)}, {long[0]:.1f}, {statistics.median(long):.1f}, {long[-1]:.1f}"
185
+ if long
186
+ else "0"
187
+ )
188
+ sent = sum(s["sent"] for s in runs)
189
+ affected = sum(s["affected"] * s["sent"] for s in runs)
190
+ lines.append(
191
+ f"| {rho:.3f} | {engine} | {sent:.0f} | {sum(s['skipped'] for s in runs):.0f}"
192
+ f" | {statistics.fmean(s['rtt_median_ms'] for s in runs):.3f}"
193
+ f" | {statistics.fmean(s['rtt_p99_ms'] for s in runs):.3f}"
194
+ f" | {spread} | {sum(s['timeouts'] for s in runs):.0f}"
195
+ f" | {sum(s['unanswered'] for s in runs):.0f}"
196
+ f" | {affected / sent:.2%} ({affected:.0f})"
197
+ f" | {statistics.fmean(s['dropped'] for s in runs):.3%} |"
198
+ )
199
+ return "\n".join(lines)
@@ -65,8 +65,11 @@ def scenario(
65
65
  duration_ms: float = DURATION_MS,
66
66
  buffer: int | None = BUFFER,
67
67
  seed: int = SEEDS[0],
68
+ outstanding: int | None = None,
69
+ timeout_ms: float | None = None,
68
70
  ) -> Scenario:
69
- """T1 with the UDP stream at *rho* of the laptop's port."""
71
+ """T1 with the UDP stream at *rho* of the laptop's port; its polls open
72
+ loop, or with one request in flight (ADR-0012, ``benchmarks.closed_loop``)."""
70
73
  net = Network("T1")
71
74
  sw = net.switch("sw", ports=3, buffer=buffer)
72
75
  pi = net.adapter("pi", ip="10.0.0.1")
@@ -77,10 +80,20 @@ def scenario(
77
80
  net.link(laptop, sw, speed=LAPTOP_MBPS, length=2)
78
81
  rate = rho * LAPTOP_MBPS * 1e6 / ((FRAME + WIRE_OVERHEAD_BYTES) * 8)
79
82
  pi.sends(laptop, rate=rate, size=FRAME, pattern="poisson")
80
- laptop.polls(server, register=0, count=REGISTERS, rate=POLL_RATE)
83
+ laptop.polls(
84
+ server,
85
+ register=0,
86
+ count=REGISTERS,
87
+ rate=POLL_RATE,
88
+ outstanding=outstanding,
89
+ timeout_ms=timeout_ms,
90
+ )
81
91
  net.observe("modbus_latency", on=laptop, every=1)
82
92
  end = duration_ms - 1 # the last sample, at the end of the run
83
93
  net.observe("modbus_unanswered", on=laptop, every=end)
94
+ if outstanding is not None:
95
+ net.observe("modbus_timeouts", on=laptop, every=end)
96
+ net.observe("modbus_skipped", on=laptop, every=end)
84
97
  net.observe("frames_sent", on=pi, every=end)
85
98
  net.observe("drops_total", on=sw, every=end)
86
99
  return net.to_scenario(duration=duration_ms, seed=seed)