smolpy 1.13.1.dev2__tar.gz → 1.14.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.
Files changed (170) hide show
  1. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/PKG-INFO +7 -3
  2. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/README.md +6 -2
  3. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/__main__.py +20 -1
  4. smolpy-1.14.0/benchmarks/cells.py +360 -0
  5. smolpy-1.14.0/benchmarks/results/2026-11-24-1006-simpy-rust-ns3-jaws-zbook-buffer-cells.json +3085 -0
  6. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0004-execution-backends.md +2 -2
  7. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0011-bounded-switch-buffers.md +1 -1
  8. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0013-ingress-buffer-accounting.md +2 -0
  9. smolpy-1.14.0/docs/adr/0014-buffer-cells-and-hysteresis.md +336 -0
  10. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/backends.md +48 -0
  11. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/benchmarks.md +4 -0
  12. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/dsl-reference.md +19 -1
  13. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/examples.md +12 -12
  14. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/language-reference.md +13 -2
  15. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/model-semantics.md +23 -6
  16. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/roadmap.md +17 -0
  17. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/scenario-model.md +2 -2
  18. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/README.md +7 -3
  19. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_ingress_buffer.smol +23 -12
  20. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/mkdocs.yml +1 -0
  21. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smol-engine/src/scenario.rs +102 -24
  22. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smol-engine/src/sim.rs +135 -30
  23. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smolpy-engine-rs/README.md +1 -1
  24. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/__init__.py +2 -1
  25. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/backends.py +16 -3
  26. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/core/network.py +6 -0
  27. smolpy-1.14.0/src/smolpy/ethernet/switch.py +129 -0
  28. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/lang/ast.py +3 -0
  29. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/lang/interpreter.py +3 -0
  30. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/lang/transformer.py +11 -7
  31. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/model/frames.py +6 -0
  32. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/model/scenario.py +32 -11
  33. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/model/validate.py +70 -14
  34. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/ns3/__init__.py +25 -8
  35. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/ns3/cpp/smol-ns3.cc +119 -15
  36. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/sim/engine.py +116 -16
  37. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/equivalence/scenarios.py +111 -1
  38. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_benchmarks.py +51 -0
  39. smolpy-1.14.0/tests/test_hysteresis.py +588 -0
  40. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_ingress.py +6 -6
  41. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_ns3.py +2 -2
  42. smolpy-1.13.1.dev2/src/smolpy/ethernet/switch.py +0 -87
  43. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/.github/workflows/ci.yml +0 -0
  44. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/.github/workflows/dev-build.yml +0 -0
  45. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/.github/workflows/docker-image.yml +0 -0
  46. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/.github/workflows/docs.yml +0 -0
  47. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/.github/workflows/github-release.yml +0 -0
  48. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/.github/workflows/ns3-base.yml +0 -0
  49. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/.github/workflows/publish.yml +0 -0
  50. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/.github/workflows/release.yml +0 -0
  51. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/.github/workflows/rust-wheels.yml +0 -0
  52. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/.gitignore +0 -0
  53. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/LICENSE +0 -0
  54. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/__init__.py +0 -0
  55. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/closed_loop.py +0 -0
  56. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/ingress.py +0 -0
  57. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/load.py +0 -0
  58. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/loss.py +0 -0
  59. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/results/2026-11-13-0921-simpy-jaws-zbook-baseline.json +0 -0
  60. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/results/2026-11-13-1527-simpy-jaws-zbook-optimised.json +0 -0
  61. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/results/2026-11-13-2116-simpy-jaws-zbook-research-batch.json +0 -0
  62. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/results/2026-11-13-2119-simpy-jaws-zbook-research-b4.json +0 -0
  63. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/results/2026-11-15-1255-rust-jaws-zbook-stop-criterion.json +0 -0
  64. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/results/2026-11-15-1333-rust-jaws-zbook-research-b4.json +0 -0
  65. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/results/2026-11-15-1346-rust-jaws-zbook-research-batch.json +0 -0
  66. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/results/2026-11-16-1839-simpy-ns3-jaws-zbook-tcp-under-load.json +0 -0
  67. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/results/2026-11-23-1228-simpy-rust-ns3-jaws-zbook-bounded-buffers.json +0 -0
  68. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/results/2026-11-23-2106-simpy-rust-ns3-jaws-zbook-one-request-in-flight.json +0 -0
  69. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/results/2026-11-24-0836-simpy-rust-ns3-jaws-zbook-ingress-buffers.json +0 -0
  70. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/runner.py +0 -0
  71. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/scenarios.py +0 -0
  72. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/benchmarks/worker.py +0 -0
  73. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docker/Dockerfile +0 -0
  74. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docker/Dockerfile.dockerignore +0 -0
  75. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docker/Dockerfile.ns3 +0 -0
  76. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docker/Dockerfile.ns3.dockerignore +0 -0
  77. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docker/ns3-base/Dockerfile +0 -0
  78. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docker/ns3-base/smoke.cc +0 -0
  79. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docker/smoke.smol +0 -0
  80. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0001-protocol-package-structure.md +0 -0
  81. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0002-modbus-tcp-implementation.md +0 -0
  82. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0003-smol-external-dsl.md +0 -0
  83. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0005-profinet-rt.md +0 -0
  84. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0006-profiling-and-baseline-benchmark.md +0 -0
  85. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0007-execution-independent-scenario-model.md +0 -0
  86. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0008-rust-des-engine-mvp.md +0 -0
  87. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0009-batch-execution-and-cross-backend-validation.md +0 -0
  88. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0010-ethernet-frames-on-the-wire.md +0 -0
  89. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/adr/0012-modbus-one-request-in-flight.md +0 -0
  90. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/dashboard.md +0 -0
  91. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/index.md +0 -0
  92. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/modbus.md +0 -0
  93. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/mqtt.md +0 -0
  94. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/profinet.md +0 -0
  95. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/docs/simulation-engine.md +0 -0
  96. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example.py +0 -0
  97. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example.smol +0 -0
  98. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_10_clients.py +0 -0
  99. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_12_clients.py +0 -0
  100. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_20_clients.py +0 -0
  101. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_bounded_buffer.smol +0 -0
  102. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_file_transfer.py +0 -0
  103. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_modbus.py +0 -0
  104. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_modbus_timeout.smol +0 -0
  105. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_mqtt.py +0 -0
  106. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_profinet.py +0 -0
  107. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_profinet.smol +0 -0
  108. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_staggered_transfer.py +0 -0
  109. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/examples/example_two_tier.py +0 -0
  110. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/pyproject.toml +0 -0
  111. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/Cargo.lock +0 -0
  112. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/Cargo.toml +0 -0
  113. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smol-engine/Cargo.toml +0 -0
  114. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smol-engine/src/frames.rs +0 -0
  115. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smol-engine/src/lib.rs +0 -0
  116. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smol-engine/src/rng.rs +0 -0
  117. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smol-engine/src/timebase.rs +0 -0
  118. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smolpy-engine-rs/Cargo.toml +0 -0
  119. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smolpy-engine-rs/pyproject.toml +0 -0
  120. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smolpy-engine-rs/smoke_test.py +0 -0
  121. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/rust/smolpy-engine-rs/src/lib.rs +0 -0
  122. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/_worker.py +0 -0
  123. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/batch.py +0 -0
  124. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/cli.py +0 -0
  125. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/core/__init__.py +0 -0
  126. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/core/adapter.py +0 -0
  127. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/core/batch.py +0 -0
  128. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/core/link.py +0 -0
  129. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/core/node.py +0 -0
  130. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/core/observation.py +0 -0
  131. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/ethernet/__init__.py +0 -0
  132. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/lang/__init__.py +0 -0
  133. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/lang/errors.py +0 -0
  134. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/lang/grammar.lark +0 -0
  135. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/modbus/__init__.py +0 -0
  136. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/modbus/slave.py +0 -0
  137. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/model/__init__.py +0 -0
  138. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/model/streams.py +0 -0
  139. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/model/timebase.py +0 -0
  140. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/mqtt/__init__.py +0 -0
  141. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/mqtt/broker.py +0 -0
  142. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/profinet/__init__.py +0 -0
  143. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/profinet/device.py +0 -0
  144. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/sim/__init__.py +0 -0
  145. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/stats.py +0 -0
  146. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/viz/__init__.py +0 -0
  147. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/viz/dashboard.py +0 -0
  148. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/src/smolpy/viz/text_dashboard.py +0 -0
  149. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/__init__.py +0 -0
  150. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/equivalence/__init__.py +0 -0
  151. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/equivalence/harness.py +0 -0
  152. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/equivalence/test_equivalence.py +0 -0
  153. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/equivalence/test_rust_timebase.py +0 -0
  154. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_backends.py +0 -0
  155. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_batch.py +0 -0
  156. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_buffers.py +0 -0
  157. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_cli.py +0 -0
  158. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_dsl.py +0 -0
  159. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_engine_ir.py +0 -0
  160. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_lang.py +0 -0
  161. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_model.py +0 -0
  162. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_outstanding.py +0 -0
  163. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_profinet.py +0 -0
  164. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_semantics.py +0 -0
  165. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_simulation.py +0 -0
  166. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_stats.py +0 -0
  167. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_sweep.py +0 -0
  168. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_timebase.py +0 -0
  169. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/tests/test_validate.py +0 -0
  170. {smolpy-1.13.1.dev2 → smolpy-1.14.0}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: smolpy
3
- Version: 1.13.1.dev2
3
+ Version: 1.14.0
4
4
  Summary: Network simulation DSL and discrete-event simulator
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -64,7 +64,7 @@ SMOLPy lets you describe a network topology in pure Python, define traffic flows
64
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
- 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 per egress or ingress port (`buffer=`, `ingress_buffer=`, in bytes or `Frames(n)`). Every end station can send flows, so a Modbus server can also stream data on its one port. 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.
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 per egress or ingress port (`buffer=`, `ingress_buffer=`, in bytes, `Frames(n)` or `Cells(n)`, with optional resume levels). Every end station can send flows, so a Modbus server can also stream data on its one port. 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.
68
68
 
69
69
  **Not supported (yet):** PROFINET IRT, PROFIBUS, EtherNet/IP, EtherCAT, OPC UA, Modbus RTU (serial), and Modbus write function codes. See the [Architecture Decision Records](https://jwszolek.github.io/SMOLPy/adr/0001-protocol-package-structure/) for what is planned.
70
70
 
@@ -334,6 +334,10 @@ net.observe(metric, on=node, every=interval_ms)
334
334
  | `modbus_skipped` | polls | Adapter (master), ModbusSlave (its polls): poll instants skipped so far, because a request was outstanding |
335
335
  | `ingress_drops_total` | frames | Switch: dropped by its ingress accounts so far |
336
336
  | `egress_drops_total` | frames | Switch: dropped by its egress accounts so far |
337
+ | `ingress_drop_episodes_total` | episodes | Switch: runs of drops by its ingress accounts so far |
338
+ | `egress_drop_episodes_total` | episodes | Switch: runs of drops by its egress accounts so far |
339
+ | `ingress_drop_time_total` | ms | Switch: time its ingress accounts spent in the drop state so far |
340
+ | `egress_drop_time_total` | ms | Switch: time its egress accounts spent in the drop state so far |
337
341
 
338
342
  ### Simulation
339
343
 
@@ -528,7 +532,7 @@ The model every engine implements:
528
532
  - **MAC-learning switch** — each switch pre-seeds its forwarding table from the topology wiring, eliminating spurious flooding toward silent endpoints (e.g. a server that only receives). Dynamic learning still operates for traffic through intermediate switches.
529
533
  - **Store-and-forward model** — transmission delay + propagation delay per hop.
530
534
  - **Queuing** — each link direction has its own egress queue with 8 strict 802.1Q priority classes (FIFO within a class, non-preemptive); `qos="fifo"` on a switch ignores priorities. `queue_depth` reports buffered frames at the switch's outbound ports.
531
- - **Bounded buffers** — a switch with `buffer` (per egress port) or `ingress_buffer` (per ingress port), in bytes or in frames, drops a frame that does not fit, with tail drop: delay is capped and loss appears, as on real switches near saturation ([ADR-0011](https://jwszolek.github.io/SMOLPy/adr/0011-bounded-switch-buffers/), [ADR-0013](https://jwszolek.github.io/SMOLPy/adr/0013-ingress-buffer-accounting/)). Without them queues are unbounded.
535
+ - **Bounded buffers** — a switch with `buffer` (per egress port) or `ingress_buffer` (per ingress port), in bytes, frames or cells, drops a frame that does not fit, with tail drop or with a resume threshold ([ADR-0014](https://jwszolek.github.io/SMOLPy/adr/0014-buffer-cells-and-hysteresis/)): delay is capped and loss appears, as on real switches near saturation ([ADR-0011](https://jwszolek.github.io/SMOLPy/adr/0011-bounded-switch-buffers/), [ADR-0013](https://jwszolek.github.io/SMOLPy/adr/0013-ingress-buffer-accounting/)). Without them queues are unbounded.
532
536
  - **Traffic shaping** — constant, Poisson, Pareto-burst and batch patterns; IMIX frame-size distribution.
533
537
  - **Live mode** (SimPy only) — simulation runs in 200 chunks (~8 s total wall time); the dashboard reads shared metric arrays between chunks via Python's GIL.
534
538
 
@@ -36,7 +36,7 @@ SMOLPy lets you describe a network topology in pure Python, define traffic flows
36
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
- 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 per egress or ingress port (`buffer=`, `ingress_buffer=`, in bytes or `Frames(n)`). Every end station can send flows, so a Modbus server can also stream data on its one port. 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.
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 per egress or ingress port (`buffer=`, `ingress_buffer=`, in bytes, `Frames(n)` or `Cells(n)`, with optional resume levels). Every end station can send flows, so a Modbus server can also stream data on its one port. 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.
40
40
 
41
41
  **Not supported (yet):** PROFINET IRT, PROFIBUS, EtherNet/IP, EtherCAT, OPC UA, Modbus RTU (serial), and Modbus write function codes. See the [Architecture Decision Records](https://jwszolek.github.io/SMOLPy/adr/0001-protocol-package-structure/) for what is planned.
42
42
 
@@ -306,6 +306,10 @@ net.observe(metric, on=node, every=interval_ms)
306
306
  | `modbus_skipped` | polls | Adapter (master), ModbusSlave (its polls): poll instants skipped so far, because a request was outstanding |
307
307
  | `ingress_drops_total` | frames | Switch: dropped by its ingress accounts so far |
308
308
  | `egress_drops_total` | frames | Switch: dropped by its egress accounts so far |
309
+ | `ingress_drop_episodes_total` | episodes | Switch: runs of drops by its ingress accounts so far |
310
+ | `egress_drop_episodes_total` | episodes | Switch: runs of drops by its egress accounts so far |
311
+ | `ingress_drop_time_total` | ms | Switch: time its ingress accounts spent in the drop state so far |
312
+ | `egress_drop_time_total` | ms | Switch: time its egress accounts spent in the drop state so far |
309
313
 
310
314
  ### Simulation
311
315
 
@@ -500,7 +504,7 @@ The model every engine implements:
500
504
  - **MAC-learning switch** — each switch pre-seeds its forwarding table from the topology wiring, eliminating spurious flooding toward silent endpoints (e.g. a server that only receives). Dynamic learning still operates for traffic through intermediate switches.
501
505
  - **Store-and-forward model** — transmission delay + propagation delay per hop.
502
506
  - **Queuing** — each link direction has its own egress queue with 8 strict 802.1Q priority classes (FIFO within a class, non-preemptive); `qos="fifo"` on a switch ignores priorities. `queue_depth` reports buffered frames at the switch's outbound ports.
503
- - **Bounded buffers** — a switch with `buffer` (per egress port) or `ingress_buffer` (per ingress port), in bytes or in frames, drops a frame that does not fit, with tail drop: delay is capped and loss appears, as on real switches near saturation ([ADR-0011](https://jwszolek.github.io/SMOLPy/adr/0011-bounded-switch-buffers/), [ADR-0013](https://jwszolek.github.io/SMOLPy/adr/0013-ingress-buffer-accounting/)). Without them queues are unbounded.
507
+ - **Bounded buffers** — a switch with `buffer` (per egress port) or `ingress_buffer` (per ingress port), in bytes, frames or cells, drops a frame that does not fit, with tail drop or with a resume threshold ([ADR-0014](https://jwszolek.github.io/SMOLPy/adr/0014-buffer-cells-and-hysteresis/)): delay is capped and loss appears, as on real switches near saturation ([ADR-0011](https://jwszolek.github.io/SMOLPy/adr/0011-bounded-switch-buffers/), [ADR-0013](https://jwszolek.github.io/SMOLPy/adr/0013-ingress-buffer-accounting/)). Without them queues are unbounded.
504
508
  - **Traffic shaping** — constant, Poisson, Pareto-burst and batch patterns; IMIX frame-size distribution.
505
509
  - **Live mode** (SimPy only) — simulation runs in 200 chunks (~8 s total wall time); the dashboard reads shared metric arrays between chunks via Python's GIL.
506
510
 
@@ -13,6 +13,8 @@ python -m benchmarks closed-loop [--loads 0.99] [--duration 30000] [--backend si
13
13
  python -m benchmarks closed-loop-summary benchmarks/results/<file>.json
14
14
  python -m benchmarks ingress [--loads 0.997] [--duration 30000] [--backend simpy rust ns3]
15
15
  python -m benchmarks ingress-summary benchmarks/results/<file>.json
16
+ python -m benchmarks cells [--duration 30000] [--backend simpy rust ns3]
17
+ python -m benchmarks cells-summary benchmarks/results/<file>.json
16
18
  """
17
19
 
18
20
  from __future__ import annotations
@@ -24,7 +26,7 @@ import subprocess
24
26
  import sys
25
27
  from pathlib import Path
26
28
 
27
- from benchmarks import closed_loop, ingress, loss
29
+ from benchmarks import cells, closed_loop, ingress, loss
28
30
  from benchmarks.load import DURATION_MS, LOADS, run_load, summarize_load
29
31
  from benchmarks.runner import parse_size, run_batch, run_suite, size_label, summarize
30
32
 
@@ -136,6 +138,17 @@ def main() -> None:
136
138
  ing_summ = sub.add_parser("ingress-summary", help="markdown table of an ingress results file")
137
139
  ing_summ.add_argument("file", type=Path)
138
140
 
141
+ cel = sub.add_parser(
142
+ "cells", help="the testbed of ADR-0014, cells with a resume threshold, every engine"
143
+ )
144
+ cel.add_argument("--duration", type=float, default=cells.DURATION_MS, help="simulated ms")
145
+ cel.add_argument("--backend", nargs="+", default=list(cells.ENGINES))
146
+ cel.add_argument("--label", default="buffer-cells")
147
+ cel.add_argument("--out", type=Path, default=None)
148
+
149
+ cel_summ = sub.add_parser("cells-summary", help="markdown tables of a cells results file")
150
+ cel_summ.add_argument("file", type=Path)
151
+
139
152
  a = p.parse_args()
140
153
  if a.cmd == "run":
141
154
  sizes = [parse_size(s) for s in a.frames]
@@ -172,6 +185,12 @@ def main() -> None:
172
185
  print(ingress.summarize_ingress(out))
173
186
  elif a.cmd == "ingress-summary":
174
187
  print(ingress.summarize_ingress(a.file))
188
+ elif a.cmd == "cells":
189
+ out = cells.run_cells(a.duration, a.backend, a.label, a.out)
190
+ print(f"results written to {out}")
191
+ print(cells.summarize_cells(out))
192
+ elif a.cmd == "cells-summary":
193
+ print(cells.summarize_cells(a.file))
175
194
  elif a.cmd == "batch":
176
195
  frames = parse_size(a.frames)
177
196
  r = run_batch(a.scenario, frames, a.metrics, a.runs, a.jobs, a.timeout, a.seed, a.backend)
@@ -0,0 +1,360 @@
1
+ """Buffer limits in cells with a resume threshold on the three engines: the
2
+ testbed of ADR-0014.
3
+
4
+ Scenario T4 is T3 of ``benchmarks.ingress``, the testbed as measured: the Pi
5
+ is one Modbus slave on a 1 Gb/s port that sends Poisson UDP of 1 518 B
6
+ frames to the laptop and serves its polls every 10 ms, and a Waveshare relay
7
+ module on another port is polled every 20 ms, both with one request in
8
+ flight and a timeout of 1 s. The switch models:
9
+ - ``cells``: 740 cells of 128 B per ingress port, resuming at 668, the
10
+ calibration of ADR-0014;
11
+ - ``cells-tail``: the same 740 cells, tail drop: no resume level;
12
+ - ``frames``: 60 frames per ingress port, the model of ADR-0013.
13
+
14
+ Three parts:
15
+ - **the testbed** at 8 100 frames/s: the UDP loss, the mean loss run
16
+ (ingress drops over drop episodes), the Pi's and the Waveshare's polls
17
+ affected; and on SimPy, by an audit of its decisions, each run's length;
18
+ - **the burst test**: N frames back to back from the Pi at the pace it put
19
+ them on the wire, its measured send rate or the 1 Gb/s line rate if lower,
20
+ for each row of the testbed's burst CSVs; the frames received are N less
21
+ the frames dropped among the first N;
22
+ - **the batch case**: Poisson groups of 8 back-to-back 1 518 B frames at
23
+ 7 500 frames/s; the Pi's polls affected over its UDP loss.
24
+
25
+ The record keeps every run and burst; ``summarize_cells`` prints the tables.
26
+
27
+ python -m benchmarks cells [--duration 30000] [--backend simpy rust ns3]
28
+ """
29
+
30
+ from __future__ import annotations
31
+
32
+ import contextlib
33
+ import csv
34
+ import datetime as dt
35
+ import json
36
+ import math
37
+ import statistics
38
+ from collections.abc import Iterator
39
+ from pathlib import Path
40
+
41
+ from benchmarks.runner import RESULTS_DIR, environment
42
+ from smolpy import Cells, Frames, Network, backends
43
+ from smolpy.model import Scenario
44
+ from smolpy.model import timebase as tb
45
+ from smolpy.model.frames import WIRE_OVERHEAD_BYTES
46
+
47
+ LAPTOP_MBPS = 100
48
+ PI_MBPS = 1_000
49
+ FRAME = 1_518
50
+ CELL = 128
51
+ LIMIT, RESUME = 740, 668
52
+ MODELS = {
53
+ "cells": {"cell": CELL, "ingress_buffer": Cells(LIMIT), "ingress_resume": Cells(RESUME)},
54
+ "cells-tail": {"cell": CELL, "ingress_buffer": Cells(LIMIT)},
55
+ "frames": {"ingress_buffer": Frames(60)},
56
+ }
57
+ SERVERS = {"pi": (100, 10), "waveshare": (50, 1)} # polls/s, registers
58
+ TIMEOUT_MS = 1_000.0
59
+ RATE = 8_100 # UDP frames/s, the testbed's
60
+ BATCH = (8, 7_500) # group size and UDP frames/s of the batch case
61
+ DURATION_MS = 30_000
62
+ ENGINES = ("simpy", "rust", "ns3")
63
+ SEEDS = (1, 2, 3, 4, 5)
64
+ LONG_MS = 100.0 # a round trip far over any queueing delay
65
+ # the testbed: the paper's repository, stanowisko/pomiary/wyniki/
66
+ DATA = Path.home() / (
67
+ "Documents/publications/smolpy-heterogeneous-networks/SMOLPy_TII_dla_ZK/stanowisko/pomiary/wyniki"
68
+ )
69
+ BURSTS = (
70
+ "2026-11-23_bufor_paczki.csv",
71
+ "2026-11-24_bufor_paczki_512B.csv",
72
+ "2026-11-24_bufor_paczki_64B.csv",
73
+ )
74
+ MEASURED = {
75
+ "udp_loss": "0.55-0.66 %",
76
+ "mean_run": "6.4-6.7 frames, from 2 to 15, no single-frame run",
77
+ "pi": "0.44 % of polls retransmitted",
78
+ "waveshare": "0 of 15 000 polls",
79
+ "batch_ratio": "0.55 (K = 8, 7 500 frames/s)",
80
+ }
81
+
82
+
83
+ def scenario(
84
+ model: str,
85
+ rate: float = RATE,
86
+ duration_ms: float = DURATION_MS,
87
+ seed: int = SEEDS[0],
88
+ batch: int | None = None,
89
+ ) -> Scenario:
90
+ """T4: the testbed with the switch *model*, at *rate* UDP frames/s, in
91
+ Poisson groups of *batch* frames if given."""
92
+ net = Network("T4")
93
+ sw = net.switch("sw", ports=3, **MODELS[model])
94
+ pi = net.modbus_slave("pi", ip="10.0.0.1", unit_id=1)
95
+ waveshare = net.modbus_slave("waveshare", ip="10.0.0.3", unit_id=1)
96
+ laptop = net.adapter("laptop", ip="10.0.0.2")
97
+ net.link(pi, sw, speed=PI_MBPS, length=2)
98
+ net.link(waveshare, sw, speed=1_000, length=2)
99
+ net.link(laptop, sw, speed=LAPTOP_MBPS, length=2)
100
+ if batch is None:
101
+ pi.sends(laptop, rate=rate, size=FRAME, pattern="poisson")
102
+ else:
103
+ pi.sends(laptop, rate=rate, size=FRAME, pattern="batch", batch=batch)
104
+ for server, (poll_rate, count) in SERVERS.items():
105
+ node = pi if server == "pi" else waveshare
106
+ laptop.polls(
107
+ node, register=0, count=count, rate=poll_rate, outstanding=1, timeout_ms=TIMEOUT_MS
108
+ )
109
+ end = duration_ms - 1 # the last sample, at the end of the run
110
+ for node in (pi, waveshare):
111
+ net.observe("modbus_latency", on=node, every=1)
112
+ for metric in ("modbus_unanswered", "modbus_skipped"):
113
+ net.observe(metric, on=node, every=end)
114
+ net.observe("frames_sent", on=pi, every=end)
115
+ for metric in ("ingress_drops_total", "ingress_drop_episodes_total", "ingress_drop_time_total"):
116
+ net.observe(metric, on=sw, every=end)
117
+ return net.to_scenario(duration=duration_ms, seed=seed)
118
+
119
+
120
+ def _instants(until_ms: float, rate: float) -> int:
121
+ end = tb.ms_to_ns(until_ms)
122
+ n = 0
123
+ for t in tb.instants(0, tb.interval_ns(rate)):
124
+ if t > end:
125
+ return n
126
+ n += 1
127
+ raise AssertionError("unreachable")
128
+
129
+
130
+ @contextlib.contextmanager
131
+ def _runs() -> Iterator[list[int]]:
132
+ """The length of each run of drops by SimPy's accounts, by an audit of
133
+ their decisions (ADR-0014): no metric gives each run's length."""
134
+ from smolpy.sim import engine
135
+
136
+ lengths: list[int] = []
137
+ running: dict[int, int] = {}
138
+ admit = engine._Account.admit
139
+
140
+ def counting(account: engine._Account, size: int) -> bool:
141
+ ok = admit(account, size)
142
+ if ok:
143
+ if id(account) in running:
144
+ lengths.append(running.pop(id(account)))
145
+ else:
146
+ running[id(account)] = running.get(id(account), 0) + 1
147
+ return ok
148
+
149
+ engine._Account.admit = counting # type: ignore[method-assign]
150
+ try:
151
+ yield lengths
152
+ finally:
153
+ engine._Account.admit = admit # type: ignore[method-assign]
154
+
155
+
156
+ def _summary(metrics: dict[str, list[tuple[float, float]]]) -> dict[str, object]:
157
+ last = {k: (s[-1][1] if s else math.nan) for k, s in metrics.items()}
158
+ out: dict[str, object] = {}
159
+ for server, (rate, _) in SERVERS.items():
160
+ rtt = [v / 1_000 for _, v in metrics[f"modbus_latency:{server}"]]
161
+ long = sum(r > LONG_MS for r in rtt)
162
+ at, skipped = metrics[f"modbus_skipped:{server}"][-1]
163
+ sent = _instants(at, rate) - skipped
164
+ affected = long + last[f"modbus_unanswered:{server}"]
165
+ out[server] = {"sent": sent, "affected": affected}
166
+ drops = last["ingress_drops_total:sw"]
167
+ out["dropped"] = drops / last["frames_sent:pi"]
168
+ out["drops"] = drops
169
+ out["episodes"] = last["ingress_drop_episodes_total:sw"]
170
+ out["drop_time_ms"] = last["ingress_drop_time_total:sw"]
171
+ return out
172
+
173
+
174
+ # --- the burst test ---
175
+
176
+
177
+ def burst_rows(data: Path = DATA) -> list[dict[str, float]]:
178
+ """Every row of the burst CSVs: frame size, N, received and the send rate."""
179
+ rows = []
180
+ for name in BURSTS:
181
+ with open(data / name, newline="") as f:
182
+ for r in csv.DictReader(f):
183
+ gen = r["gen"].split("=")[1].split()[0] # "... = 119166 ramek/s; ..."
184
+ rows.append(
185
+ {
186
+ "frame_bytes": int(r.get("frame_B") or FRAME),
187
+ "n": int(r["N"]),
188
+ "received": int(r["received"]),
189
+ "send_rate": float(gen),
190
+ }
191
+ )
192
+ return rows
193
+
194
+
195
+ def burst(model: str, frame_bytes: int, n: int, send_rate: float, engine: str = "simpy") -> int:
196
+ """The frames the laptop receives of N sent back to back at the pace the
197
+ Pi put them on the wire: its send rate, or the line rate if lower."""
198
+ line = PI_MBPS * 1e6 / ((frame_bytes + WIRE_OVERHEAD_BYTES) * 8)
199
+ rate = min(send_rate, line)
200
+ period = tb.interval_ns(rate)
201
+ # the N-th frame is sent at N T and decided after its transmission and
202
+ # propagation; the sample falls half a period later, before the next
203
+ tx = tb.transmission_ns(8 + frame_bytes, PI_MBPS)
204
+ at = tb.round_ns(n * period + tx + tb.propagation_ns(2) + period / 2)
205
+ net = Network("burst")
206
+ sw = net.switch("sw", ports=2, mac_table="topology", **MODELS[model])
207
+ pi = net.adapter("pi", ip="10.0.0.1")
208
+ laptop = net.adapter("laptop", ip="10.0.0.2")
209
+ net.link(pi, sw, speed=PI_MBPS, length=2)
210
+ net.link(laptop, sw, speed=LAPTOP_MBPS, length=2)
211
+ pi.sends(laptop, rate=rate, size=frame_bytes, pattern="constant")
212
+ net.observe("ingress_drops_total", on=sw, every=tb.ns_to_ms(at))
213
+ sc = net.to_scenario(duration=tb.ns_to_ms(at) + 0.001)
214
+ (_, dropped), *_ = backends.get(engine).run(sc).metrics["ingress_drops_total:sw"]
215
+ return n - int(dropped)
216
+
217
+
218
+ def run_cells(
219
+ duration_ms: float,
220
+ engines: list[str],
221
+ label: str = "buffer-cells",
222
+ out: Path | None = None,
223
+ seeds: tuple[int, ...] = SEEDS,
224
+ models: tuple[str, ...] = tuple(MODELS),
225
+ data: Path = DATA,
226
+ ) -> Path:
227
+ env = environment()
228
+ stamp = dt.datetime.now().strftime("%Y-%m-%d-%H%M")
229
+ out = out or RESULTS_DIR / f"{stamp}-{'-'.join(engines)}-{env['host']}-{label}.json"
230
+ out.parent.mkdir(parents=True, exist_ok=True)
231
+ doc: dict[str, object] = {
232
+ "format": "smolpy-cells",
233
+ "version": 1,
234
+ "label": label,
235
+ "created": dt.datetime.now().isoformat(timespec="seconds"),
236
+ "environment": env,
237
+ "scenario": "T4",
238
+ "models": {k: {a: str(v) for a, v in m.items()} for k, m in MODELS.items()},
239
+ "duration_ms": duration_ms,
240
+ "seeds": list(seeds),
241
+ "measured": MEASURED,
242
+ "runs": [],
243
+ "bursts": [],
244
+ }
245
+ runs: list[dict[str, object]] = []
246
+ doc["runs"] = runs
247
+ for case, rate, batch in (("testbed", RATE, None), ("batch", BATCH[1], BATCH[0])):
248
+ for model in models:
249
+ for seed in seeds:
250
+ sc = scenario(model, rate, duration_ms, seed, batch)
251
+ for engine in engines:
252
+ lengths: list[int] = []
253
+ if engine == "simpy":
254
+ with _runs() as lengths:
255
+ result = backends.get(engine).run(sc)
256
+ else:
257
+ result = backends.get(engine).run(sc)
258
+ s = _summary(result.metrics)
259
+ if engine == "simpy": # length -> runs
260
+ s["run_lengths"] = {str(n): lengths.count(n) for n in sorted(set(lengths))}
261
+ runs.append(
262
+ {
263
+ "case": case,
264
+ "model": model,
265
+ "seed": seed,
266
+ "backend": engine,
267
+ "events": result.stats.events,
268
+ "wall_s": result.stats.wall_s,
269
+ "summary": s,
270
+ }
271
+ )
272
+ out.write_text(json.dumps(doc, indent=1)) # keep partial progress
273
+ pi = s["pi"]
274
+ assert isinstance(pi, dict)
275
+ print(
276
+ f"{case:7s} {model:10s} seed {seed} {engine:6s}"
277
+ f" dropped {s['dropped']:.3%} run {s['drops'] / max(s['episodes'], 1):.2f}"
278
+ f" pi {pi['affected'] / pi['sent']:.2%} ({runs[-1]['wall_s']:.1f} s)",
279
+ flush=True,
280
+ )
281
+ bursts: list[dict[str, object]] = []
282
+ doc["bursts"] = bursts
283
+ if data.is_dir():
284
+ for row in burst_rows(data):
285
+ got = {
286
+ model: burst(model, int(row["frame_bytes"]), int(row["n"]), row["send_rate"])
287
+ for model in models
288
+ }
289
+ bursts.append({**row, "model": got})
290
+ out.write_text(json.dumps(doc, indent=1))
291
+ return out
292
+
293
+
294
+ def _held(frame_bytes: int, n: int, received: float, send_rate: float) -> float:
295
+ """What the switch held: the frames received less those its 100 Mb/s port
296
+ drained while the burst lasted on the wire."""
297
+ line = PI_MBPS * 1e6 / ((frame_bytes + WIRE_OVERHEAD_BYTES) * 8)
298
+ seconds = n / min(send_rate, line)
299
+ drained = seconds * LAPTOP_MBPS * 1e6 / ((frame_bytes + WIRE_OVERHEAD_BYTES) * 8)
300
+ return received - drained
301
+
302
+
303
+ def summarize_cells(path: Path) -> str:
304
+ doc = json.loads(path.read_text())
305
+ m = doc["measured"]
306
+ lines = [
307
+ f"T4, {doc['duration_ms'] / 1000:g} s per run, seeds {doc['seeds']}: sums or means over"
308
+ f" the seeds. The testbed: UDP loss {m['udp_loss']}; runs {m['mean_run']}; Pi {m['pi']};"
309
+ f" Waveshare {m['waveshare']}; batch ratio {m['batch_ratio']}.",
310
+ "",
311
+ "| case | model | engine | UDP loss | mean run | single-frame runs | Pi: polls affected"
312
+ " | Waveshare | Pi ratio to UDP loss |",
313
+ "|---|---|---|---|---|---|---|---|---|",
314
+ ]
315
+ groups: dict[tuple[str, str, str], list[dict]] = {}
316
+ for r in doc["runs"]:
317
+ groups.setdefault((r["case"], r["model"], r["backend"]), []).append(r["summary"])
318
+ for (case, model, engine), runs in groups.items():
319
+ sent = sum(s["pi"]["sent"] for s in runs)
320
+ pi = sum(s["pi"]["affected"] for s in runs) / sent
321
+ ws = sum(s["waveshare"]["affected"] for s in runs)
322
+ loss = statistics.fmean(s["dropped"] for s in runs)
323
+ run = sum(s["drops"] for s in runs) / max(sum(s["episodes"] for s in runs), 1)
324
+ hist: dict[str, int] = {}
325
+ for s in runs:
326
+ for n, k in s.get("run_lengths", {}).items():
327
+ hist[n] = hist.get(n, 0) + k
328
+ total = sum(hist.values())
329
+ single = f"{hist.get('1', 0) / total:.1%} of {total}" if total else "–"
330
+ lines.append(
331
+ f"| {case} | {model} | {engine} | {loss:.3%} | {run:.2f} | {single} | {pi:.2%}"
332
+ f" | {ws:.0f} | {pi / loss:.2f} |"
333
+ )
334
+ if doc["bursts"]:
335
+ models = list(doc["bursts"][0]["model"])
336
+ lines += [
337
+ "",
338
+ "Burst test: frames received of N, and what the switch held"
339
+ " (received less what drained during the burst).",
340
+ "",
341
+ "| frame (B) | N | send rate (frames/s) | received | "
342
+ + " | ".join(f"{m}: received" for m in models)
343
+ + " | held, measured | "
344
+ + " | ".join(f"held, {m}" for m in models)
345
+ + " |",
346
+ "|---" * (5 + 2 * len(models)) + "|",
347
+ ]
348
+ for b in doc["bursts"]:
349
+ held = _held(b["frame_bytes"], b["n"], b["received"], b["send_rate"])
350
+ model_held = [
351
+ _held(b["frame_bytes"], b["n"], b["model"][m], b["send_rate"]) for m in models
352
+ ]
353
+ lines.append(
354
+ f"| {b['frame_bytes']} | {b['n']} | {b['send_rate']:.0f} | {b['received']} | "
355
+ + " | ".join(str(b["model"][m]) for m in models)
356
+ + f" | {held:.0f} | "
357
+ + " | ".join(f"{h:.0f}" for h in model_held)
358
+ + " |"
359
+ )
360
+ return "\n".join(lines)