smolpy 1.16.1__tar.gz → 1.16.2.dev3__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 (183) hide show
  1. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/PKG-INFO +2 -2
  2. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/README.md +1 -1
  3. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/__main__.py +21 -1
  4. smolpy-1.16.2.dev3/benchmarks/light_port.py +500 -0
  5. smolpy-1.16.2.dev3/benchmarks/results/2026-11-26-1508-simpy-jaws-zbook-light-port.json +9333 -0
  6. smolpy-1.16.2.dev3/docs/adr/0017-drain-counted-net.md +477 -0
  7. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/backends.md +31 -0
  8. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/dsl-reference.md +33 -1
  9. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/language-reference.md +15 -1
  10. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/model-semantics.md +13 -2
  11. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/roadmap.md +17 -0
  12. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/scenario-model.md +2 -2
  13. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/mkdocs.yml +1 -0
  14. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smol-engine/src/scenario.rs +178 -0
  15. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smol-engine/src/sim.rs +111 -15
  16. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/backends.py +15 -1
  17. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/core/network.py +18 -1
  18. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/ethernet/switch.py +37 -0
  19. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/lang/ast.py +4 -0
  20. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/lang/interpreter.py +4 -0
  21. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/lang/transformer.py +8 -0
  22. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/model/scenario.py +26 -1
  23. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/model/validate.py +49 -0
  24. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/ns3/__init__.py +8 -2
  25. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/ns3/cpp/smol-ns3.cc +111 -15
  26. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/sim/engine.py +93 -21
  27. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/equivalence/scenarios.py +143 -6
  28. smolpy-1.16.2.dev3/tests/light_port_audit.py +162 -0
  29. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_benchmarks.py +119 -0
  30. smolpy-1.16.2.dev3/tests/test_drain_net.py +505 -0
  31. smolpy-1.16.2.dev3/tests/test_light_port.py +618 -0
  32. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_ns3.py +3 -2
  33. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/.github/workflows/ci.yml +0 -0
  34. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/.github/workflows/dev-build.yml +0 -0
  35. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/.github/workflows/docker-image.yml +0 -0
  36. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/.github/workflows/docs.yml +0 -0
  37. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/.github/workflows/github-release.yml +0 -0
  38. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/.github/workflows/ns3-base.yml +0 -0
  39. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/.github/workflows/publish.yml +0 -0
  40. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/.github/workflows/release.yml +0 -0
  41. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/.github/workflows/rust-wheels.yml +0 -0
  42. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/.gitignore +0 -0
  43. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/LICENSE +0 -0
  44. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/__init__.py +0 -0
  45. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/cells.py +0 -0
  46. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/closed_loop.py +0 -0
  47. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/ingress.py +0 -0
  48. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/load.py +0 -0
  49. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/loss.py +0 -0
  50. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/pool.py +0 -0
  51. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-13-0921-simpy-jaws-zbook-baseline.json +0 -0
  52. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-13-1527-simpy-jaws-zbook-optimised.json +0 -0
  53. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-13-2116-simpy-jaws-zbook-research-batch.json +0 -0
  54. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-13-2119-simpy-jaws-zbook-research-b4.json +0 -0
  55. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-15-1255-rust-jaws-zbook-stop-criterion.json +0 -0
  56. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-15-1333-rust-jaws-zbook-research-b4.json +0 -0
  57. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-15-1346-rust-jaws-zbook-research-batch.json +0 -0
  58. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-16-1839-simpy-ns3-jaws-zbook-tcp-under-load.json +0 -0
  59. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-23-1228-simpy-rust-ns3-jaws-zbook-bounded-buffers.json +0 -0
  60. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-23-2106-simpy-rust-ns3-jaws-zbook-one-request-in-flight.json +0 -0
  61. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-24-0836-simpy-rust-ns3-jaws-zbook-ingress-buffers.json +0 -0
  62. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-24-1006-simpy-rust-ns3-jaws-zbook-buffer-cells.json +0 -0
  63. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-24-1538-simpy-rust-ns3-jaws-zbook-shared-pool.json +0 -0
  64. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/results/2026-11-24-2122-simpy-rust-ns3-jaws-zbook-switch-drop-state.json +0 -0
  65. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/runner.py +0 -0
  66. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/scenarios.py +0 -0
  67. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/switch_drop.py +0 -0
  68. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/benchmarks/worker.py +0 -0
  69. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docker/Dockerfile +0 -0
  70. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docker/Dockerfile.dockerignore +0 -0
  71. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docker/Dockerfile.ns3 +0 -0
  72. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docker/Dockerfile.ns3.dockerignore +0 -0
  73. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docker/ns3-base/Dockerfile +0 -0
  74. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docker/ns3-base/smoke.cc +0 -0
  75. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docker/smoke.smol +0 -0
  76. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0001-protocol-package-structure.md +0 -0
  77. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0002-modbus-tcp-implementation.md +0 -0
  78. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0003-smol-external-dsl.md +0 -0
  79. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0004-execution-backends.md +0 -0
  80. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0005-profinet-rt.md +0 -0
  81. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0006-profiling-and-baseline-benchmark.md +0 -0
  82. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0007-execution-independent-scenario-model.md +0 -0
  83. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0008-rust-des-engine-mvp.md +0 -0
  84. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0009-batch-execution-and-cross-backend-validation.md +0 -0
  85. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0010-ethernet-frames-on-the-wire.md +0 -0
  86. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0011-bounded-switch-buffers.md +0 -0
  87. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0012-modbus-one-request-in-flight.md +0 -0
  88. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0013-ingress-buffer-accounting.md +0 -0
  89. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0014-buffer-cells-and-hysteresis.md +0 -0
  90. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0015-shared-pool-and-drain-resume.md +0 -0
  91. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/adr/0016-switch-wide-drop-state.md +0 -0
  92. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/benchmarks.md +0 -0
  93. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/dashboard.md +0 -0
  94. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/examples.md +0 -0
  95. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/index.md +0 -0
  96. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/modbus.md +0 -0
  97. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/mqtt.md +0 -0
  98. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/profinet.md +0 -0
  99. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/docs/simulation-engine.md +0 -0
  100. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/README.md +0 -0
  101. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example.py +0 -0
  102. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example.smol +0 -0
  103. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_10_clients.py +0 -0
  104. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_12_clients.py +0 -0
  105. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_20_clients.py +0 -0
  106. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_bounded_buffer.smol +0 -0
  107. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_file_transfer.py +0 -0
  108. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_ingress_buffer.smol +0 -0
  109. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_modbus.py +0 -0
  110. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_modbus_timeout.smol +0 -0
  111. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_mqtt.py +0 -0
  112. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_profinet.py +0 -0
  113. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_profinet.smol +0 -0
  114. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_staggered_transfer.py +0 -0
  115. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/examples/example_two_tier.py +0 -0
  116. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/pyproject.toml +0 -0
  117. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/Cargo.lock +0 -0
  118. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/Cargo.toml +0 -0
  119. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smol-engine/Cargo.toml +0 -0
  120. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smol-engine/src/frames.rs +0 -0
  121. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smol-engine/src/lib.rs +0 -0
  122. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smol-engine/src/rng.rs +0 -0
  123. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smol-engine/src/timebase.rs +0 -0
  124. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smolpy-engine-rs/Cargo.toml +0 -0
  125. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smolpy-engine-rs/README.md +0 -0
  126. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smolpy-engine-rs/pyproject.toml +0 -0
  127. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smolpy-engine-rs/smoke_test.py +0 -0
  128. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/rust/smolpy-engine-rs/src/lib.rs +0 -0
  129. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/__init__.py +0 -0
  130. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/_worker.py +0 -0
  131. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/batch.py +0 -0
  132. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/cli.py +0 -0
  133. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/core/__init__.py +0 -0
  134. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/core/adapter.py +0 -0
  135. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/core/batch.py +0 -0
  136. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/core/link.py +0 -0
  137. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/core/node.py +0 -0
  138. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/core/observation.py +0 -0
  139. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/ethernet/__init__.py +0 -0
  140. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/lang/__init__.py +0 -0
  141. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/lang/errors.py +0 -0
  142. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/lang/grammar.lark +0 -0
  143. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/modbus/__init__.py +0 -0
  144. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/modbus/slave.py +0 -0
  145. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/model/__init__.py +0 -0
  146. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/model/frames.py +0 -0
  147. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/model/streams.py +0 -0
  148. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/model/timebase.py +0 -0
  149. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/mqtt/__init__.py +0 -0
  150. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/mqtt/broker.py +0 -0
  151. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/profinet/__init__.py +0 -0
  152. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/profinet/device.py +0 -0
  153. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/sim/__init__.py +0 -0
  154. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/stats.py +0 -0
  155. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/viz/__init__.py +0 -0
  156. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/viz/dashboard.py +0 -0
  157. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/src/smolpy/viz/text_dashboard.py +0 -0
  158. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/__init__.py +0 -0
  159. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/equivalence/__init__.py +0 -0
  160. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/equivalence/harness.py +0 -0
  161. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/equivalence/test_equivalence.py +0 -0
  162. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/equivalence/test_rust_timebase.py +0 -0
  163. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_backends.py +0 -0
  164. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_batch.py +0 -0
  165. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_buffers.py +0 -0
  166. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_cli.py +0 -0
  167. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_dsl.py +0 -0
  168. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_engine_ir.py +0 -0
  169. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_hysteresis.py +0 -0
  170. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_ingress.py +0 -0
  171. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_lang.py +0 -0
  172. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_model.py +0 -0
  173. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_outstanding.py +0 -0
  174. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_pool.py +0 -0
  175. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_profinet.py +0 -0
  176. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_semantics.py +0 -0
  177. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_simulation.py +0 -0
  178. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_stats.py +0 -0
  179. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_sweep.py +0 -0
  180. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_switch_drop.py +0 -0
  181. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_timebase.py +0 -0
  182. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/tests/test_validate.py +0 -0
  183. {smolpy-1.16.1 → smolpy-1.16.2.dev3}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: smolpy
3
- Version: 1.16.1
3
+ Version: 1.16.2.dev3
4
4
  Summary: Network simulation DSL and discrete-event simulator
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -533,7 +533,7 @@ The model every engine implements:
533
533
  - **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.
534
534
  - **Store-and-forward model** — transmission delay + propagation delay per hop.
535
535
  - **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.
536
- - **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/)), and can share one pool among its ports, with a reserve each ([ADR-0015](https://jwszolek.github.io/SMOLPy/adr/0015-shared-pool-and-drain-resume/)), and one drop state for the whole switch ([ADR-0016](https://jwszolek.github.io/SMOLPy/adr/0016-switch-wide-drop-state/)): 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.
536
+ - **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/)), and can share one pool among its ports, with a reserve each ([ADR-0015](https://jwszolek.github.io/SMOLPy/adr/0015-shared-pool-and-drain-resume/)), and one drop state for the whole switch ([ADR-0016](https://jwszolek.github.io/SMOLPy/adr/0016-switch-wide-drop-state/)), ended by its drain counted net and protecting a light port ([ADR-0017](https://jwszolek.github.io/SMOLPy/adr/0017-drain-counted-net/)): 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.
537
537
  - **Traffic shaping** — constant, Poisson, Pareto-burst and batch patterns; IMIX frame-size distribution.
538
538
  - **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.
539
539
 
@@ -505,7 +505,7 @@ The model every engine implements:
505
505
  - **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.
506
506
  - **Store-and-forward model** — transmission delay + propagation delay per hop.
507
507
  - **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.
508
- - **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/)), and can share one pool among its ports, with a reserve each ([ADR-0015](https://jwszolek.github.io/SMOLPy/adr/0015-shared-pool-and-drain-resume/)), and one drop state for the whole switch ([ADR-0016](https://jwszolek.github.io/SMOLPy/adr/0016-switch-wide-drop-state/)): 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.
508
+ - **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/)), and can share one pool among its ports, with a reserve each ([ADR-0015](https://jwszolek.github.io/SMOLPy/adr/0015-shared-pool-and-drain-resume/)), and one drop state for the whole switch ([ADR-0016](https://jwszolek.github.io/SMOLPy/adr/0016-switch-wide-drop-state/)), ended by its drain counted net and protecting a light port ([ADR-0017](https://jwszolek.github.io/SMOLPy/adr/0017-drain-counted-net/)): 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.
509
509
  - **Traffic shaping** — constant, Poisson, Pareto-burst and batch patterns; IMIX frame-size distribution.
510
510
  - **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.
511
511
 
@@ -19,6 +19,8 @@ python -m benchmarks pool [--duration 60000] [--backend simpy rust ns3]
19
19
  python -m benchmarks pool-summary benchmarks/results/<file>.json
20
20
  python -m benchmarks switch-drop [--duration 60000] [--backend simpy rust ns3]
21
21
  python -m benchmarks switch-drop-summary benchmarks/results/<file>.json
22
+ python -m benchmarks light-port [--duration 56000] [--seeds 1 2 3]
23
+ python -m benchmarks light-port-summary benchmarks/results/<file>.json
22
24
  """
23
25
 
24
26
  from __future__ import annotations
@@ -30,7 +32,7 @@ import subprocess
30
32
  import sys
31
33
  from pathlib import Path
32
34
 
33
- from benchmarks import cells, closed_loop, ingress, loss, pool, switch_drop
35
+ from benchmarks import cells, closed_loop, ingress, light_port, loss, pool, switch_drop
34
36
  from benchmarks.load import DURATION_MS, LOADS, run_load, summarize_load
35
37
  from benchmarks.runner import parse_size, run_batch, run_suite, size_label, summarize
36
38
 
@@ -178,6 +180,18 @@ def main() -> None:
178
180
  sd_summ = sub.add_parser("switch-drop-summary", help="markdown tables of a switch-drop file")
179
181
  sd_summ.add_argument("file", type=Path)
180
182
 
183
+ lp = sub.add_parser(
184
+ "light-port",
185
+ help="ADR-0017 Part 2: a light port's protection, against the quick model and hardware",
186
+ )
187
+ lp.add_argument("--duration", type=float, default=light_port.DURATION_MS, help="ms per run")
188
+ lp.add_argument("--seeds", type=int, nargs="+", default=list(light_port.SEEDS))
189
+ lp.add_argument("--label", default="light-port")
190
+ lp.add_argument("--out", type=Path, default=None)
191
+
192
+ lp_summ = sub.add_parser("light-port-summary", help="markdown tables of a light-port file")
193
+ lp_summ.add_argument("file", type=Path)
194
+
181
195
  a = p.parse_args()
182
196
  if a.cmd == "run":
183
197
  sizes = [parse_size(s) for s in a.frames]
@@ -234,6 +248,12 @@ def main() -> None:
234
248
  print(switch_drop.summarize(out))
235
249
  elif a.cmd == "switch-drop-summary":
236
250
  print(switch_drop.summarize(a.file))
251
+ elif a.cmd == "light-port":
252
+ out = light_port.run_light_port(a.duration, tuple(a.seeds), a.label, a.out)
253
+ print(f"results written to {out}")
254
+ print(light_port.summarize(out))
255
+ elif a.cmd == "light-port-summary":
256
+ print(light_port.summarize(a.file))
237
257
  elif a.cmd == "batch":
238
258
  frames = parse_size(a.frames)
239
259
  r = run_batch(a.scenario, frames, a.metrics, a.runs, a.jobs, a.timeout, a.seed, a.backend)
@@ -0,0 +1,500 @@
1
+ """The protection of a light port (ADR-0017 Part 2) on the testbed.
2
+
3
+ The LS108GP as ADR-0017 models it: ``cell=128 pool=740cells
4
+ ingress_reserve=60cells ingress_drain=72cells ingress_drop=switch
5
+ ingress_drain_count=net ingress_pool_count=total ingress_alpha=24
6
+ ingress_mark=204cells``. Nothing is refitted here: L = 770, R = 60 and
7
+ D = 72 are ADR-0015's and ADR-0016's, and α, P and the mark were fitted on
8
+ the quick model's five campaigns (ADR-0017 §6.5).
9
+
10
+ **One sender.** With α the identity with ADR-0016 holds only by its bound:
11
+ beyond its reserve a frame of u cells is admitted while the port holds at
12
+ most ⌊(α (P + R) + R − u) / (1 + α)⌋, 769 for u = 12, so a Pi alone holds
13
+ 780 cells after a frame where ADR-0016's holds 768. The module runs one Pi
14
+ at 8 090/s under both.
15
+
16
+ **Against the quick model** (``stanowisko/model/symulacja_puli.py``,
17
+ ``res_shared=True``, ``alpha``, ``snap``): SMOLPy with the quick model's
18
+ streams, a heavy Poisson Pi, the light Pi, and the Modbus responses as
19
+ constant streams of 1 cell on ports of their own (50/s from the Waveshare,
20
+ 100/s from each Pi), each stream's loss and mean run against the quick
21
+ model's, with the sampling errors of both.
22
+
23
+ **Against the hardware**, with no refitting: the testbed's scenario, each
24
+ Pi a Modbus slave polled every 10 ms for 10 registers and the Waveshare
25
+ every 20 ms, on the blind campaign ``2026-11-26_ciemno_mac`` (21 cases) and
26
+ ``2026-11-25_noc2_mac`` (44 cases), at the rates the Pis sent. The hardware
27
+ is each case's ``RAPORT.md`` row, the middle of its repetitions' range:
28
+ each Pi's loss and mean run, in the window in which both send. The model's
29
+ streams are measured by SimPy's admission decisions, as in
30
+ ``benchmarks.switch_drop``.
31
+
32
+ python -m benchmarks light-port [--duration 56000] [--seeds 1 2 3]
33
+ """
34
+
35
+ from __future__ import annotations
36
+
37
+ import datetime as dt
38
+ import importlib.util
39
+ import json
40
+ import math
41
+ import re
42
+ import statistics
43
+ from collections.abc import Callable, Iterable
44
+ from concurrent.futures import ProcessPoolExecutor
45
+ from pathlib import Path
46
+
47
+ from benchmarks import pool, switch_drop
48
+ from benchmarks.runner import RESULTS_DIR, environment
49
+ from smolpy import Cells, Network, backends
50
+
51
+ DATA = pool.DATA
52
+ QUICK_MODEL = DATA.parent.parent / "model" / "symulacja_puli.py"
53
+ CAMPAIGNS = ("2026-11-26_ciemno_mac", "2026-11-25_noc2_mac")
54
+ CELL = 128
55
+ P, R, D, ALPHA, MARK = 740, 60, 72, 24.0, 204
56
+ LS108GP = {
57
+ "cell": CELL,
58
+ "pool": Cells(P),
59
+ "ingress_reserve": Cells(R),
60
+ "ingress_drain": Cells(D),
61
+ "ingress_drop": "switch",
62
+ "ingress_drain_count": "net",
63
+ "ingress_pool_count": "total",
64
+ "ingress_alpha": ALPHA,
65
+ "ingress_mark": Cells(MARK),
66
+ }
67
+ ADR_0016 = {**switch_drop.switch(710, R, D)}
68
+ QUICK = {
69
+ "pool": P,
70
+ "R": R,
71
+ "D": D,
72
+ "alpha": ALPHA,
73
+ "end": "zajecie",
74
+ "snap": MARK,
75
+ "res_shared": True,
76
+ }
77
+ RESPONSES = (50, 100, 100) # 1-cell Modbus responses/s: the Waveshare, Pi 1, Pi 2
78
+ S_FRAME = 123.04e-6 # 1 538 B on the wire at 100 Mb/s
79
+ SEEDS = (1, 2, 3)
80
+ DURATION_MS = 56_000.0 # the window in which both Pis send
81
+
82
+
83
+ def frame(payload: int) -> int:
84
+ """The Ethernet frame of a UDP payload: 8 + 20 + 14 + 4 bytes more."""
85
+ return payload + 46
86
+
87
+
88
+ # --- the campaigns ---
89
+
90
+ Case = tuple[float, float, int, str] # Pi 1/s, Pi 2/s, Pi 2's payload, its pattern
91
+
92
+
93
+ def plan(campaign: str, data: Path = DATA) -> dict[str, Case]:
94
+ """A campaign's cases, from its ``plan.txt``: Pi 1 always Poisson 1 472 B."""
95
+ out = {}
96
+ for line in (data / campaign / "plan.txt").read_text().splitlines():
97
+ f = line.split()
98
+ if not f or f[0].startswith("#") or len(f) < 5:
99
+ continue
100
+ out[f[0]] = (float(f[1]), float(f[2]), int(f[3]), f[4])
101
+ return out
102
+
103
+
104
+ def sent_rates(campaign: str, case: str, data: Path = DATA) -> tuple[float, float]:
105
+ """The rates the Pis sent, from ``*_gen.txt``, over the repetitions."""
106
+ rates = []
107
+ for pi in ("pi1", "pi2"):
108
+ v = []
109
+ for path in sorted((data / campaign).glob(f"{case}_r*_{pi}_gen.txt")):
110
+ m = re.search(r"(\d+) ramek w ([\d.]+) s", path.read_text())
111
+ if m:
112
+ v.append(int(m[1]) / float(m[2]))
113
+ rates.append(statistics.fmean(v) if v else 0.0)
114
+ return rates[0], rates[1]
115
+
116
+
117
+ def _middle(cell: str) -> float | None:
118
+ numbers = re.findall(r"\d+(?:\.\d+)?", cell.split("(")[0])
119
+ return statistics.fmean(map(float, numbers[:2])) if numbers else None
120
+
121
+
122
+ def hardware(campaign: str, data: Path = DATA) -> dict[str, dict]:
123
+ """Each case's hardware row in ``RAPORT.md``: each Pi's loss (a
124
+ fraction) and mean run, the middle of the repetitions' range."""
125
+ out = {}
126
+ case = None
127
+ for line in (data / campaign / "RAPORT.md").read_text().splitlines():
128
+ if not line.startswith("|"):
129
+ continue
130
+ c = [x.strip() for x in line.strip().strip("|").split("|")]
131
+ if len(c) < 6:
132
+ continue
133
+ if c[0]:
134
+ case = c[0].replace("*", "").split()[0]
135
+ if c[1] == "sprzęt" and case is not None:
136
+ loss = [_middle(c[2]), _middle(c[3])]
137
+ out[case] = {
138
+ "loss": [None if x is None else x / 100 for x in loss],
139
+ "mean_run": [_middle(c[4]), _middle(c[5])],
140
+ }
141
+ return out
142
+
143
+
144
+ # --- SMOLPy's streams ---
145
+
146
+
147
+ def _streams(found: dict, ports: Iterable[int], sizes: dict[int, int] | None = None) -> list[dict]:
148
+ """Each port's stream, by SimPy's decisions: its loss and mean run; with
149
+ *sizes*, only its frames of that size."""
150
+ out = []
151
+ for port in ports:
152
+ decisions = sorted(
153
+ d
154
+ for (p, size), ds in found.items()
155
+ if p == port and (sizes is None or size == sizes[port])
156
+ for d in ds
157
+ )
158
+ runs = switch_drop.runs_from_decisions(decisions)
159
+ out.append(
160
+ {
161
+ "loss": sum(not ok for _, ok in decisions) / len(decisions) if decisions else 0.0,
162
+ "mean_run": statistics.fmean(k for *_, k in runs) if runs else 0.0,
163
+ "frames": len(decisions),
164
+ }
165
+ )
166
+ return out
167
+
168
+
169
+ def quick_net(case: Case, kw: dict = LS108GP, source_mbps: float = 10_000) -> Network:
170
+ """The quick model's streams on SMOLPy: a heavy Poisson Pi of 1 518 B,
171
+ the light Pi, and the three Modbus response streams of 64 B (1 cell, 84 B
172
+ on the wire), constant, each on a port of its own, into one 100 Mb/s
173
+ port. The sources' links are fast, as the quick model has none."""
174
+ r1, r2, payload, pattern = case
175
+ net = Network("quick-model")
176
+ sw = net.switch("sw", ports=6, mac_table="topology", **kw)
177
+ sink = net.adapter("mac", ip="10.0.0.100")
178
+ flows = [(r1, 1_518, "poisson"), (r2, frame(payload), _pattern(pattern))]
179
+ flows += [(rate, 64, "constant") for rate in RESPONSES]
180
+ for i, (rate, size, pat) in enumerate(flows): # stream i on port i
181
+ src = net.adapter(f"s{i}", ip=f"10.0.0.{i + 1}")
182
+ net.link(src, sw, speed=source_mbps, length=2)
183
+ src.sends(sink, rate=rate, size=size, pattern=pat) # type: ignore[arg-type]
184
+ net.link(sink, sw, speed=100, length=2)
185
+ return net
186
+
187
+
188
+ def _pattern(pattern: str) -> str:
189
+ return {"const": "constant"}.get(pattern, pattern)
190
+
191
+
192
+ def _smolpy_quick(job: tuple) -> list[dict]:
193
+ case, seed, seconds = job
194
+ sc = quick_net(case).to_scenario(duration=seconds * 1_000, seed=seed)
195
+ with switch_drop.audit() as found:
196
+ backends.get("simpy").run(sc)
197
+ return _streams(found, range(5))
198
+
199
+
200
+ def _quick(job: tuple) -> list[dict]:
201
+ path, case, seed, seconds = job
202
+ spec = importlib.util.spec_from_file_location("symulacja_puli", path)
203
+ module = importlib.util.module_from_spec(spec) # type: ignore[arg-type]
204
+ import sys
205
+
206
+ sys.path.insert(0, str(Path(path).parent)) # it imports nakladanie beside it
207
+ spec.loader.exec_module(module) # type: ignore[union-attr]
208
+ r1, r2, payload, pattern = case
209
+ fr = frame(payload)
210
+ streams = [(r1, 12), (r2, math.ceil(fr / CELL), fr + 20, pattern)]
211
+ streams += [(rate, 1, 84, "const") for rate in RESPONSES]
212
+ n = round(sum(s[0] for s in streams) * seconds)
213
+ r = module.sim(streams, "dt_glob", n=n, seed=seed, s=S_FRAME, **QUICK)
214
+ return [{"loss": r["loss"][i], "mean_run": r["mean_run"][i]} for i in range(len(streams))]
215
+
216
+
217
+ def _mean_se(values: list[float]) -> tuple[float, float]:
218
+ mean = statistics.fmean(values)
219
+ se = statistics.stdev(values) / math.sqrt(len(values)) if len(values) > 1 else 0.0
220
+ return mean, se
221
+
222
+
223
+ def _summary(per_seed: list[list[dict]], stream: int) -> dict:
224
+ loss, loss_se = _mean_se([s[stream]["loss"] for s in per_seed])
225
+ run, run_se = _mean_se([s[stream]["mean_run"] for s in per_seed])
226
+ return {"loss": loss, "loss_se": loss_se, "mean_run": run, "mean_run_se": run_se}
227
+
228
+
229
+ def against_quick_model(
230
+ path: Path,
231
+ cases: list[Case],
232
+ seeds: int = 3,
233
+ seconds: float = 56,
234
+ names: list[str] | None = None,
235
+ workers: int | None = None,
236
+ ) -> list[dict]:
237
+ """Each case on SMOLPy (SimPy) and on the quick model, *seeds* runs of
238
+ *seconds* each: the heavy and the light stream's loss and mean run."""
239
+ jobs_s = [(c, s, seconds) for c in cases for s in range(1, seeds + 1)]
240
+ jobs_q = [(str(path), c, s, seconds) for c in cases for s in range(1, seeds + 1)]
241
+ with ProcessPoolExecutor(workers) as ex:
242
+ smol = list(ex.map(_smolpy_quick, jobs_s))
243
+ quick = list(ex.map(_quick, jobs_q))
244
+ rows = []
245
+ for i, case in enumerate(cases):
246
+ a, b = smol[i * seeds : (i + 1) * seeds], quick[i * seeds : (i + 1) * seeds]
247
+ rows.append(
248
+ {
249
+ "case": names[i] if names else str(case),
250
+ "rates": case[:2],
251
+ "heavy": {"smolpy": _summary(a, 0), "quick": _summary(b, 0)},
252
+ "light": {"smolpy": _summary(a, 1), "quick": _summary(b, 1)},
253
+ "waveshare": {"smolpy": _summary(a, 2), "quick": _summary(b, 2)},
254
+ }
255
+ )
256
+ return rows
257
+
258
+
259
+ # --- the testbed ---
260
+
261
+
262
+ def _testbed(job: tuple) -> dict:
263
+ kw, case, seed, duration_ms = job
264
+ r1, r2, payload, pattern = case
265
+ pis = [[(r1, 1_518, "poisson")], [(r2, frame(payload), _pattern(pattern))]]
266
+ sc = pool.testbed(kw, pis, duration_ms, seed, 100, 10, 10, True)
267
+ with switch_drop.audit() as found:
268
+ result = backends.get("simpy").run(sc)
269
+ m = result.metrics
270
+ return {
271
+ "seed": seed,
272
+ "streams": _streams(found, (0, 1), {0: 1_518, 1: frame(payload)}),
273
+ "pi": [switch_drop.polls(m, f"pi{i + 1}", 100) for i in range(2)],
274
+ "waveshare": switch_drop.polls(m, "waveshare", 50),
275
+ }
276
+
277
+
278
+ def validate(
279
+ kw: dict,
280
+ campaigns: Iterable[str] = CAMPAIGNS,
281
+ seeds: Iterable[int] = SEEDS,
282
+ duration_ms: float = DURATION_MS,
283
+ data: Path = DATA,
284
+ workers: int | None = None,
285
+ log: Callable[[str], None] = print,
286
+ ) -> list[dict]:
287
+ """Every case of *campaigns* on the testbed's scenario at the rates the
288
+ Pis sent, against the hardware."""
289
+ jobs, meta = [], []
290
+ for campaign in campaigns:
291
+ hw = hardware(campaign, data)
292
+ for name, (_, _, payload, pattern) in plan(campaign, data).items():
293
+ r1, r2 = sent_rates(campaign, name, data)
294
+ if not (r1 and r2) or name not in hw:
295
+ continue
296
+ for seed in seeds:
297
+ jobs.append((kw, (r1, r2, payload, pattern), seed, duration_ms))
298
+ meta.append((campaign, name, (r1, r2), payload, pattern, hw[name]))
299
+ rows: dict[tuple[str, str], dict] = {}
300
+ with ProcessPoolExecutor(workers) as ex:
301
+ for (campaign, name, rates, payload, pattern, hw), run in zip(
302
+ meta, ex.map(_testbed, jobs), strict=True
303
+ ):
304
+ row = rows.setdefault(
305
+ (campaign, name),
306
+ {
307
+ "campaign": campaign,
308
+ "case": name,
309
+ "rates": rates,
310
+ "payload": payload,
311
+ "pattern": pattern,
312
+ "hardware": hw,
313
+ "runs": [],
314
+ },
315
+ )
316
+ row["runs"].append(run)
317
+ if len(row["runs"]) == len(tuple(seeds)):
318
+ s = [r["streams"] for r in row["runs"]]
319
+ log(
320
+ f"{campaign} {name:13s} loss {_pct(s, 0)} / {_pct(s, 1)}"
321
+ f" hw {_hw(hw['loss'][0])} / {_hw(hw['loss'][1])}"
322
+ f" light run {statistics.fmean(x[1]['mean_run'] for x in s):.2f}"
323
+ f" hw {hw['mean_run'][1]}"
324
+ )
325
+ return list(rows.values())
326
+
327
+
328
+ def _pct(per_seed: list[list[dict]], i: int) -> str:
329
+ return f"{100 * statistics.fmean(s[i]['loss'] for s in per_seed):.3f}"
330
+
331
+
332
+ def _hw(x: float | None) -> str:
333
+ return "–" if x is None else f"{100 * x:.3f}"
334
+
335
+
336
+ def _run(x: float | None) -> str:
337
+ return "–" if x is None else f"{x:.2f}"
338
+
339
+
340
+ def one_sender(seeds: Iterable[int] = SEEDS, duration_ms: float = 30_000) -> dict:
341
+ """One Pi at 8 090/s with the Waveshare: ADR-0016 (P = 710) against
342
+ Part 2 (P = 740, α = 24), its loss and mean run."""
343
+ out: dict = {}
344
+ for label, kw in (("adr_0016", ADR_0016), ("part_2", LS108GP)):
345
+ runs = []
346
+ for seed in seeds:
347
+ sc = pool.testbed(
348
+ kw, [[(8_090, 1_518, "poisson")]], duration_ms, seed, 100, 10, 10, True
349
+ )
350
+ with switch_drop.audit() as found:
351
+ backends.get("simpy").run(sc)
352
+ runs.append(_streams(found, (0,), {0: 1_518})[0])
353
+ out[label] = {
354
+ "loss": statistics.fmean(r["loss"] for r in runs),
355
+ "mean_run": statistics.fmean(r["mean_run"] for r in runs),
356
+ }
357
+ return out
358
+
359
+
360
+ # --- the run and its summary ---
361
+
362
+
363
+ def run_light_port(
364
+ duration_ms: float = DURATION_MS,
365
+ seeds: tuple[int, ...] = SEEDS,
366
+ label: str = "light-port",
367
+ out: Path | None = None,
368
+ data: Path = DATA,
369
+ quick_model: Path = QUICK_MODEL,
370
+ log: Callable[[str], None] = print,
371
+ ) -> Path:
372
+ env = environment()
373
+ stamp = dt.datetime.now().strftime("%Y-%m-%d-%H%M")
374
+ out = out or RESULTS_DIR / f"{stamp}-simpy-{env['host']}-{label}.json"
375
+ out.parent.mkdir(parents=True, exist_ok=True)
376
+ doc: dict = {
377
+ "format": "smolpy-light-port",
378
+ "version": 1,
379
+ "label": label,
380
+ "created": dt.datetime.now().isoformat(timespec="seconds"),
381
+ "environment": env,
382
+ "switch": {k: str(v) for k, v in LS108GP.items()},
383
+ "duration_ms": duration_ms,
384
+ "seeds": list(seeds),
385
+ }
386
+ doc["one_sender"] = one_sender(seeds)
387
+ log(f"one sender: {doc['one_sender']}")
388
+ out.write_text(json.dumps(doc, indent=1))
389
+ blind = CAMPAIGNS[0]
390
+ cases = plan(blind, data)
391
+ doc["quick_model"] = against_quick_model(
392
+ quick_model,
393
+ list(cases.values()),
394
+ seeds=len(seeds),
395
+ seconds=duration_ms / 1_000,
396
+ names=list(cases),
397
+ )
398
+ out.write_text(json.dumps(doc, indent=1))
399
+ doc["validation"] = validate(LS108GP, CAMPAIGNS, seeds, duration_ms, data, log=log)
400
+ out.write_text(json.dumps(doc, indent=1))
401
+ return out
402
+
403
+
404
+ def _mae(pairs: list[tuple[float, float]]) -> tuple[float, float]:
405
+ """The mean absolute error and the mean error (bias) of (model, hardware)."""
406
+ return (
407
+ statistics.fmean(abs(a - b) for a, b in pairs),
408
+ statistics.fmean(a - b for a, b in pairs),
409
+ )
410
+
411
+
412
+ def light_index(row: dict) -> int:
413
+ """Which Pi is the light one: the fewer cells per second."""
414
+ r1, r2 = row["rates"]
415
+ return 0 if r1 * 12 < r2 * math.ceil(frame(row["payload"]) / CELL) else 1
416
+
417
+
418
+ def summarize(path: Path) -> str:
419
+ doc = json.loads(path.read_text())
420
+ lines = []
421
+ one = doc.get("one_sender")
422
+ if one:
423
+ a, b = one["adr_0016"], one["part_2"]
424
+ lines += [
425
+ "**One Pi at 8 090/s** (with the Waveshare):",
426
+ f"ADR-0016 {100 * a['loss']:.3f} %, run {a['mean_run']:.2f};"
427
+ f" Part 2 {100 * b['loss']:.3f} %, run {b['mean_run']:.2f}.",
428
+ "",
429
+ ]
430
+ quick = doc.get("quick_model")
431
+ if quick:
432
+ lines += [
433
+ "**Against the quick model** (same streams), loss % and mean run, SMOLPy / quick:",
434
+ "",
435
+ "| Case | heavy loss | light loss | light run | heavy run |",
436
+ "|---|---|---|---|---|",
437
+ ]
438
+ z = []
439
+ for row in quick:
440
+ h, li = row["heavy"], row["light"]
441
+
442
+ def cell(x: dict, key: str, scale: float = 1.0, fmt: str = ".3f") -> str:
443
+ s, q = x["smolpy"], x["quick"]
444
+ return f"{scale * s[key]:{fmt}} / {scale * q[key]:{fmt}}"
445
+
446
+ lines.append(
447
+ f"| {row['case']} | {cell(h, 'loss', 100)} | {cell(li, 'loss', 100)}"
448
+ f" | {cell(li, 'mean_run', fmt='.2f')} | {cell(h, 'mean_run', fmt='.2f')} |"
449
+ )
450
+ for x in (h, li):
451
+ s, q = x["smolpy"], x["quick"]
452
+ se = math.hypot(s["loss_se"], q["loss_se"])
453
+ if se > 0:
454
+ z.append((s["loss"] - q["loss"]) / se)
455
+ if z:
456
+ lines += [
457
+ "",
458
+ f"Loss differences in standard errors: mean {statistics.fmean(z):+.2f},"
459
+ f" |z| ≤ 2 in {sum(abs(x) <= 2 for x in z)} of {len(z)}.",
460
+ "",
461
+ ]
462
+ rows = doc.get("validation", [])
463
+ for campaign in dict.fromkeys(r["campaign"] for r in rows):
464
+ sel = [r for r in rows if r["campaign"] == campaign]
465
+ lines += [
466
+ f"**{campaign}**, loss % and mean run, model (mean of seeds) / hardware:",
467
+ "",
468
+ "| Case | Pi 1 loss | Pi 2 loss | Pi 1 run | Pi 2 run | Waveshare polls |",
469
+ "|---|---|---|---|---|---|",
470
+ ]
471
+ light_loss, heavy_loss, light_run = [], [], []
472
+ for r in sel:
473
+ runs = [x["streams"] for x in r["runs"]]
474
+ model_loss = [statistics.fmean(s[i]["loss"] for s in runs) for i in (0, 1)]
475
+ model_run = [statistics.fmean(s[i]["mean_run"] for s in runs) for i in (0, 1)]
476
+ hw = r["hardware"]
477
+ ws = sum(x["waveshare"]["affected"] for x in r["runs"])
478
+ lines.append(
479
+ f"| {r['case']} | {100 * model_loss[0]:.3f} / {_hw(hw['loss'][0])}"
480
+ f" | {100 * model_loss[1]:.3f} / {_hw(hw['loss'][1])}"
481
+ f" | {model_run[0]:.2f} / {_run(hw['mean_run'][0])}"
482
+ f" | {model_run[1]:.2f} / {_run(hw['mean_run'][1])} | {ws:g} |"
483
+ )
484
+ li = light_index(r)
485
+ if hw["loss"][li] is not None and hw["loss"][1 - li] is not None:
486
+ light_loss.append((100 * model_loss[li], 100 * hw["loss"][li]))
487
+ heavy_loss.append((100 * model_loss[1 - li], 100 * hw["loss"][1 - li]))
488
+ if hw["mean_run"][li] is not None:
489
+ light_run.append((model_run[li], hw["mean_run"][li]))
490
+ parts = []
491
+ for what, pairs, unit in (
492
+ ("light loss", light_loss, " pp"),
493
+ ("heavy loss", heavy_loss, " pp"),
494
+ ("light run", light_run, ""),
495
+ ):
496
+ if pairs:
497
+ mae, bias = _mae(pairs)
498
+ parts.append(f"{what} {mae:.3f}{unit} (bias {bias:+.3f})")
499
+ lines += ["", f"MAE over {len(sel)} cases: " + "; ".join(parts) + ".", ""]
500
+ return "\n".join(lines)