hypercube_sim 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,143 @@
1
+ # This file is autogenerated by maturin v1.16.0
2
+ # To update, run
3
+ #
4
+ # maturin generate-ci github -o .github/workflows/CI.yml
5
+ #
6
+ name: CI
7
+
8
+ on:
9
+ push:
10
+ branches:
11
+ - main
12
+ - master
13
+ tags:
14
+ - '*'
15
+ pull_request:
16
+ workflow_dispatch:
17
+
18
+ permissions:
19
+ contents: read
20
+
21
+ jobs:
22
+ linux:
23
+ runs-on: ${{ matrix.platform.runner }}
24
+ strategy:
25
+ matrix:
26
+ platform:
27
+ - runner: ubuntu-22.04
28
+ target: x86_64
29
+ - runner: ubuntu-22.04
30
+ target: aarch64
31
+ steps:
32
+ - uses: actions/checkout@v6
33
+ - uses: actions/setup-python@v6
34
+ with:
35
+ python-version: "3.12"
36
+ - name: Build wheels
37
+ uses: PyO3/maturin-action@v1
38
+ with:
39
+ target: ${{ matrix.platform.target }}
40
+ args: --release --out dist --find-interpreter
41
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
42
+ manylinux: 2_28
43
+ - name: Upload wheels
44
+ uses: actions/upload-artifact@v6
45
+ with:
46
+ name: wheels-linux-${{ matrix.platform.target }}
47
+ path: dist
48
+
49
+ windows:
50
+ runs-on: ${{ matrix.platform.runner }}
51
+ strategy:
52
+ matrix:
53
+ platform:
54
+ - runner: windows-latest
55
+ target: x64
56
+ python_arch: x64
57
+ - runner: windows-11-arm
58
+ target: aarch64
59
+ python_arch: arm64
60
+ steps:
61
+ - uses: actions/checkout@v6
62
+ - uses: actions/setup-python@v6
63
+ with:
64
+ python-version: "3.13"
65
+ architecture: ${{ matrix.platform.python_arch }}
66
+ - name: Build wheels
67
+ uses: PyO3/maturin-action@v1
68
+ with:
69
+ target: ${{ matrix.platform.target }}
70
+ args: --release --out dist --find-interpreter
71
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
72
+ - name: Upload wheels
73
+ uses: actions/upload-artifact@v6
74
+ with:
75
+ name: wheels-windows-${{ matrix.platform.target }}
76
+ path: dist
77
+
78
+ macos:
79
+ runs-on: ${{ matrix.platform.runner }}
80
+ strategy:
81
+ matrix:
82
+ platform:
83
+ - runner: macos-15-intel
84
+ target: x86_64
85
+ - runner: macos-latest
86
+ target: aarch64
87
+ steps:
88
+ - uses: actions/checkout@v6
89
+ - uses: actions/setup-python@v6
90
+ with:
91
+ python-version: "3.12"
92
+ - name: Build wheels
93
+ uses: PyO3/maturin-action@v1
94
+ with:
95
+ target: ${{ matrix.platform.target }}
96
+ args: --release --out dist --find-interpreter
97
+ sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
98
+ - name: Upload wheels
99
+ uses: actions/upload-artifact@v6
100
+ with:
101
+ name: wheels-macos-${{ matrix.platform.target }}
102
+ path: dist
103
+
104
+ sdist:
105
+ runs-on: ubuntu-latest
106
+ steps:
107
+ - uses: actions/checkout@v6
108
+ - name: Build sdist
109
+ uses: PyO3/maturin-action@v1
110
+ with:
111
+ command: sdist
112
+ args: --out dist
113
+ - name: Upload sdist
114
+ uses: actions/upload-artifact@v6
115
+ with:
116
+ name: wheels-sdist
117
+ path: dist
118
+
119
+ release:
120
+ name: Release
121
+ runs-on: ubuntu-latest
122
+ if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
123
+ needs: [linux, windows, macos, sdist]
124
+ environment: release
125
+ permissions:
126
+ # Use to sign the release artifacts
127
+ id-token: write
128
+ # Used to upload release artifacts
129
+ contents: write
130
+ # Used to generate artifact attestation
131
+ attestations: write
132
+ steps:
133
+ - uses: actions/download-artifact@v7
134
+ - name: Generate artifact attestation
135
+ uses: actions/attest@v4
136
+ with:
137
+ subject-path: 'wheels-*/*'
138
+ - name: Install uv
139
+ if: ${{ startsWith(github.ref, 'refs/tags/') }}
140
+ uses: astral-sh/setup-uv@v7
141
+ - name: Publish to PyPI
142
+ if: ${{ startsWith(github.ref, 'refs/tags/') }}
143
+ run: uv publish --trusted-publishing always 'wheels-*/*'
@@ -0,0 +1,72 @@
1
+ /target
2
+
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ .pytest_cache/
6
+ *.py[cod]
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ .venv/
14
+ env/
15
+ bin/
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ eggs/
20
+ lib/
21
+ lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ include/
26
+ man/
27
+ venv/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+
32
+ # Installer logs
33
+ pip-log.txt
34
+ pip-delete-this-directory.txt
35
+ pip-selfcheck.json
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .coverage
41
+ .cache
42
+ nosetests.xml
43
+ coverage.xml
44
+
45
+ # Translations
46
+ *.mo
47
+
48
+ # Mr Developer
49
+ .mr.developer.cfg
50
+ .project
51
+ .pydevproject
52
+
53
+ # Rope
54
+ .ropeproject
55
+
56
+ # Django stuff:
57
+ *.log
58
+ *.pot
59
+
60
+ .DS_Store
61
+
62
+ # Sphinx documentation
63
+ docs/_build/
64
+
65
+ # PyCharm
66
+ .idea/
67
+
68
+ # VSCode
69
+ .vscode/
70
+
71
+ # Pyenv
72
+ .python-version
@@ -0,0 +1,228 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "autocfg"
7
+ version = "1.5.1"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
10
+
11
+ [[package]]
12
+ name = "heck"
13
+ version = "0.5.0"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
16
+
17
+ [[package]]
18
+ name = "hypercube_sim"
19
+ version = "0.1.0"
20
+ dependencies = [
21
+ "numpy",
22
+ "pyo3",
23
+ ]
24
+
25
+ [[package]]
26
+ name = "libc"
27
+ version = "0.2.191"
28
+ source = "registry+https://github.com/rust-lang/crates.io-index"
29
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
30
+
31
+ [[package]]
32
+ name = "matrixmultiply"
33
+ version = "0.3.11"
34
+ source = "registry+https://github.com/rust-lang/crates.io-index"
35
+ checksum = "3f607c237553f086e7043417a51df26b2eb899d3caff94e6a67592ff992fedc7"
36
+ dependencies = [
37
+ "autocfg",
38
+ "rawpointer",
39
+ ]
40
+
41
+ [[package]]
42
+ name = "ndarray"
43
+ version = "0.17.2"
44
+ source = "registry+https://github.com/rust-lang/crates.io-index"
45
+ checksum = "520080814a7a6b4a6e9070823bb24b4531daac8c4627e08ba5de8c5ef2f2752d"
46
+ dependencies = [
47
+ "matrixmultiply",
48
+ "num-complex",
49
+ "num-integer",
50
+ "num-traits",
51
+ "portable-atomic",
52
+ "portable-atomic-util",
53
+ "rawpointer",
54
+ ]
55
+
56
+ [[package]]
57
+ name = "num-complex"
58
+ version = "0.4.6"
59
+ source = "registry+https://github.com/rust-lang/crates.io-index"
60
+ checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
61
+ dependencies = [
62
+ "num-traits",
63
+ ]
64
+
65
+ [[package]]
66
+ name = "num-integer"
67
+ version = "0.1.47"
68
+ source = "registry+https://github.com/rust-lang/crates.io-index"
69
+ checksum = "7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b"
70
+ dependencies = [
71
+ "num-traits",
72
+ ]
73
+
74
+ [[package]]
75
+ name = "num-traits"
76
+ version = "0.2.19"
77
+ source = "registry+https://github.com/rust-lang/crates.io-index"
78
+ checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
79
+ dependencies = [
80
+ "autocfg",
81
+ ]
82
+
83
+ [[package]]
84
+ name = "numpy"
85
+ version = "0.30.0"
86
+ source = "registry+https://github.com/rust-lang/crates.io-index"
87
+ checksum = "aa0b9111761885449e894981fa8051dcf69e0bd114aecbd4bcdd830b6be4ed92"
88
+ dependencies = [
89
+ "libc",
90
+ "ndarray",
91
+ "num-complex",
92
+ "num-integer",
93
+ "num-traits",
94
+ "pyo3",
95
+ "pyo3-build-config",
96
+ "rustc-hash",
97
+ ]
98
+
99
+ [[package]]
100
+ name = "once_cell"
101
+ version = "1.21.4"
102
+ source = "registry+https://github.com/rust-lang/crates.io-index"
103
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
104
+
105
+ [[package]]
106
+ name = "portable-atomic"
107
+ version = "1.15.0"
108
+ source = "registry+https://github.com/rust-lang/crates.io-index"
109
+ checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
110
+
111
+ [[package]]
112
+ name = "portable-atomic-util"
113
+ version = "0.2.8"
114
+ source = "registry+https://github.com/rust-lang/crates.io-index"
115
+ checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715"
116
+ dependencies = [
117
+ "portable-atomic",
118
+ ]
119
+
120
+ [[package]]
121
+ name = "proc-macro2"
122
+ version = "1.0.107"
123
+ source = "registry+https://github.com/rust-lang/crates.io-index"
124
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
125
+ dependencies = [
126
+ "unicode-ident",
127
+ ]
128
+
129
+ [[package]]
130
+ name = "pyo3"
131
+ version = "0.30.1"
132
+ source = "registry+https://github.com/rust-lang/crates.io-index"
133
+ checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4"
134
+ dependencies = [
135
+ "libc",
136
+ "once_cell",
137
+ "portable-atomic",
138
+ "pyo3-build-config",
139
+ "pyo3-ffi",
140
+ "pyo3-macros",
141
+ ]
142
+
143
+ [[package]]
144
+ name = "pyo3-build-config"
145
+ version = "0.30.1"
146
+ source = "registry+https://github.com/rust-lang/crates.io-index"
147
+ checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700"
148
+ dependencies = [
149
+ "target-lexicon",
150
+ ]
151
+
152
+ [[package]]
153
+ name = "pyo3-ffi"
154
+ version = "0.30.1"
155
+ source = "registry+https://github.com/rust-lang/crates.io-index"
156
+ checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4"
157
+ dependencies = [
158
+ "libc",
159
+ "pyo3-build-config",
160
+ ]
161
+
162
+ [[package]]
163
+ name = "pyo3-macros"
164
+ version = "0.30.1"
165
+ source = "registry+https://github.com/rust-lang/crates.io-index"
166
+ checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60"
167
+ dependencies = [
168
+ "proc-macro2",
169
+ "pyo3-macros-backend",
170
+ "quote",
171
+ "syn",
172
+ ]
173
+
174
+ [[package]]
175
+ name = "pyo3-macros-backend"
176
+ version = "0.30.1"
177
+ source = "registry+https://github.com/rust-lang/crates.io-index"
178
+ checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b"
179
+ dependencies = [
180
+ "heck",
181
+ "proc-macro2",
182
+ "quote",
183
+ "syn",
184
+ ]
185
+
186
+ [[package]]
187
+ name = "quote"
188
+ version = "1.0.47"
189
+ source = "registry+https://github.com/rust-lang/crates.io-index"
190
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
191
+ dependencies = [
192
+ "proc-macro2",
193
+ ]
194
+
195
+ [[package]]
196
+ name = "rawpointer"
197
+ version = "0.2.1"
198
+ source = "registry+https://github.com/rust-lang/crates.io-index"
199
+ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
200
+
201
+ [[package]]
202
+ name = "rustc-hash"
203
+ version = "2.1.3"
204
+ source = "registry+https://github.com/rust-lang/crates.io-index"
205
+ checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
206
+
207
+ [[package]]
208
+ name = "syn"
209
+ version = "3.0.10"
210
+ source = "registry+https://github.com/rust-lang/crates.io-index"
211
+ checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
212
+ dependencies = [
213
+ "proc-macro2",
214
+ "quote",
215
+ "unicode-ident",
216
+ ]
217
+
218
+ [[package]]
219
+ name = "target-lexicon"
220
+ version = "0.13.6"
221
+ source = "registry+https://github.com/rust-lang/crates.io-index"
222
+ checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
223
+
224
+ [[package]]
225
+ name = "unicode-ident"
226
+ version = "1.0.27"
227
+ source = "registry+https://github.com/rust-lang/crates.io-index"
228
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
@@ -0,0 +1,16 @@
1
+ [package]
2
+ name = "hypercube_sim"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+ [lib]
8
+ name = "hypercube_sim"
9
+ crate-type = ["cdylib"]
10
+
11
+ [dependencies]
12
+ numpy = "0.30.0"
13
+ pyo3 = { version = "0.30", features = [
14
+ "extension-module",
15
+ "experimental-inspect",
16
+ ] }
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.4
2
+ Name: hypercube_sim
3
+ Version: 0.1.0
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
7
+ Requires-Dist: numpy>=1.24.4
8
+ Requires-Dist: pytest ; extra == 'tests'
9
+ Provides-Extra: tests
10
+ Requires-Python: >=3.12
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["maturin>=1.16,<2.0"]
3
+ build-backend = "maturin"
4
+
5
+ [project]
6
+ name = "hypercube_sim"
7
+ version = "0.1.0"
8
+ requires-python = ">=3.12"
9
+ classifiers = [
10
+ "Programming Language :: Rust",
11
+ "Programming Language :: Python :: Implementation :: CPython",
12
+ "Programming Language :: Python :: Implementation :: PyPy",
13
+ ]
14
+ # dynamic = ["version"]
15
+ dependencies = [
16
+ "numpy>=1.24.4",
17
+ ]
18
+ [project.optional-dependencies]
19
+ tests = [
20
+ "pytest",
21
+ ]
22
+ [tool.maturin]
23
+ python-source = "python"
24
+ exclude = [
25
+ "**/__pycache__",
26
+ "**/*.pyc",
27
+ "**/*.pyo"
28
+ ]
29
+ bindings = "pyo3"
30
+ module-name = "hypercube_sim.native"
31
+
32
+ [tool.maturin.generate-ci.github]
33
+ trusted-publishing = true
34
+ publishing-environment = "release"
35
+
36
+ [tool.maturin.generate-ci.github.linux]
37
+ manylinux = "2_28"
38
+ targets = ["x86_64", "aarch64"]
39
+
40
+ [tool.maturin.generate-ci.github.windows]
41
+ targets = ["x64", "aarch64"]
42
+
43
+ [tool.maturin.generate-ci.github.macos]
44
+ targets = ["x86_64", "aarch64"]
@@ -0,0 +1,6 @@
1
+ from . import native as _native
2
+ from .native import Simulator as Simulator
3
+ from .stats import run_with_stats as run_with_stats
4
+
5
+ __doc__ = _native.__doc__
6
+ __all__ = ["Simulator", "run_with_stats"]
@@ -0,0 +1,31 @@
1
+ from _typeshed import SupportsGetItem
2
+ from typing import Callable, SupportsIndex, final
3
+
4
+ __all__ = ["Simulator"]
5
+
6
+ @final
7
+ class Simulator:
8
+ """
9
+ Synchronous packet routing on an implicit hypercube of up to 32 dimensions.
10
+ """
11
+ def __new__(cls, /, *, dimension: SupportsIndex, packets: SupportsGetItem[int, tuple[SupportsIndex, SupportsIndex]]) -> Simulator:
12
+ """
13
+ Create a simulator from (source, destination) pairs in packet ID order.
14
+ """
15
+ def run(self, /, route_fn: Callable[[int, int], int | None], *, max_rounds: SupportsIndex = 10000) -> dict:
16
+ """
17
+ Start a fresh run from the original packet sources.
18
+
19
+ route_fn(packet_id, current_location) returns an adjacent router or None
20
+ to wait for one round. It is called again after a hop or voluntary wait.
21
+ A packet waiting in a link queue is served in FIFO order. Each directed
22
+ link serves at most one packet per round.
23
+
24
+ The result includes delivery_ticks and final_positions in packet ID
25
+ order, plus complete, rounds_elapsed, and rounds. Packets already at
26
+ their destinations have delivery tick 0. Undelivered packets have None.
27
+
28
+ Each round contains tick, hops as (packet_id, source, destination),
29
+ delivered packet IDs, and congestion keyed by source router. Congestion
30
+ includes only routers with queued outgoing traffic in that round.
31
+ """
@@ -0,0 +1,126 @@
1
+ """Compute run statistics from the native hypercube simulator's round trace."""
2
+
3
+ from collections.abc import Callable, Mapping, Sequence
4
+ from dataclasses import dataclass
5
+ from time import perf_counter
6
+ from typing import Protocol, TypedDict, cast
7
+
8
+ RouteFn = Callable[[int, int], int | None]
9
+
10
+
11
+ class NodeCongestion(TypedDict):
12
+ queued_before: int
13
+ waiting_after: int
14
+ transmitted: int
15
+ links: dict[int, int]
16
+
17
+
18
+ class RoundResult(TypedDict):
19
+ tick: int
20
+ hops: list[tuple[int, int, int]]
21
+ delivered: list[int]
22
+ congestion: dict[int, NodeCongestion]
23
+
24
+
25
+ class SimulationResult(TypedDict):
26
+ complete: bool
27
+ rounds_elapsed: int
28
+ final_positions: list[int]
29
+ delivery_ticks: list[int | None]
30
+ rounds: list[RoundResult]
31
+
32
+
33
+ class _NativeSimulator(Protocol):
34
+ def run(self, route_fn: RouteFn, *, max_rounds: int) -> SimulationResult: ...
35
+
36
+
37
+ @dataclass(frozen=True, slots=True)
38
+ class SimulationStats:
39
+ total_rounds: int
40
+ wall_time_seconds: float | None
41
+ average_packet_rounds: float | None
42
+ congestion_packet_rounds: int
43
+ congested_rounds: int
44
+ utilization_percent: float
45
+ delivered_packets: int
46
+ total_packets: int
47
+
48
+
49
+ def summarize(
50
+ result: Mapping[str, object],
51
+ *,
52
+ dimension: int,
53
+ wall_time_seconds: float | None = None,
54
+ ) -> SimulationStats:
55
+ """Summarize the mapping returned by Simulator.run.
56
+
57
+ Average packet time uses delivered packets, including tick-zero deliveries.
58
+ It is None when no packet arrived. A packet still queued after transmission
59
+ contributes one packet-round of congestion for that round. A router counts
60
+ toward utilization when it sends or receives a hop. Zero elapsed rounds
61
+ give zero utilization.
62
+ """
63
+ if not 0 <= dimension <= 32:
64
+ raise ValueError("dimension must be between 0 and 32")
65
+
66
+ trace = cast(SimulationResult, result)
67
+ total_rounds = trace["rounds_elapsed"]
68
+ if total_rounds != len(trace["rounds"]):
69
+ raise ValueError("rounds_elapsed must match the number of round records")
70
+
71
+ delivered_packets = 0
72
+ delivery_tick_sum = 0
73
+ for tick in trace["delivery_ticks"]:
74
+ if tick is not None:
75
+ delivered_packets += 1
76
+ delivery_tick_sum += tick
77
+
78
+ congestion_packet_rounds = 0
79
+ congested_rounds = 0
80
+ active_node_rounds = 0
81
+ for round_result in trace["rounds"]:
82
+ waiting = sum(node["waiting_after"] for node in round_result["congestion"].values())
83
+ congestion_packet_rounds += waiting
84
+ congested_rounds += int(waiting > 0)
85
+
86
+ active_nodes: set[int] = set()
87
+ for _, source, destination in round_result["hops"]:
88
+ active_nodes.add(source)
89
+ active_nodes.add(destination)
90
+ active_node_rounds += len(active_nodes)
91
+
92
+ return SimulationStats(
93
+ total_rounds=total_rounds,
94
+ wall_time_seconds=wall_time_seconds,
95
+ average_packet_rounds=(
96
+ delivery_tick_sum / delivered_packets if delivered_packets else None
97
+ ),
98
+ congestion_packet_rounds=congestion_packet_rounds,
99
+ congested_rounds=congested_rounds,
100
+ utilization_percent=(
101
+ 100.0 * active_node_rounds / ((1 << dimension) * total_rounds)
102
+ if total_rounds
103
+ else 0.0
104
+ ),
105
+ delivered_packets=delivered_packets,
106
+ total_packets=len(trace["delivery_ticks"]),
107
+ )
108
+
109
+
110
+ def run_with_stats(
111
+ *,
112
+ dimension: int,
113
+ packets: Sequence[tuple[int, int]],
114
+ route_fn: RouteFn,
115
+ max_rounds: int = 10_000,
116
+ ) -> tuple[SimulationResult, SimulationStats]:
117
+ """Run the simulator and time the native run, including its Python callback."""
118
+ from .native import Simulator
119
+
120
+ native_simulator = Simulator(dimension=dimension, packets=packets)
121
+ # Maturin's generated stub describes the native result as a plain dict.
122
+ simulator = cast(_NativeSimulator, cast(object, native_simulator))
123
+ start = perf_counter()
124
+ result = simulator.run(route_fn, max_rounds=max_rounds)
125
+ elapsed = perf_counter() - start
126
+ return result, summarize(result, dimension=dimension, wall_time_seconds=elapsed)
@@ -0,0 +1,6 @@
1
+ import pytest
2
+ import hypercube_sim
3
+
4
+
5
+ def test_sum_as_string():
6
+ assert hypercube_sim.sum_as_string(1, 1) == "2"