1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
"""Runs gridoxide directly via its native Python bindings (the `gridoxide`
extension module, built with `maturin` from `src/python.rs`) on a PGM-format
JSON network, and times repeated `solve()` calls — the same methodology
`bench_pgm.py`/`bench_lightsim2grid.py`/`bench_pypowsybl.py`/
`bench_pandapower.py` already use, so the whole `scripts/bench/` comparison
can run without shelling out to a compiled `bench_network.rs` binary and
parsing its stdout at all.
Usage: python3 bench_gridoxide_native.py <input.json> [backend]
`backend` (default "scalar") selects `scalar`, `block`, `klu`, `klu_native`,
or `pardiso` — the `gridoxide` module must have been built with the
matching Cargo feature (`klu` needs `maturin develop --features
python,klu`; `klu_native` needs no extra feature; `pardiso` needs `maturin
develop --features python,pardiso` with `MKLROOT` set at build time; see
this directory's README for the exact command).
Build the bindings first:
pip install maturin
maturin develop --release --features python # scalar + block
maturin develop --release --features python,klu # + klu
maturin develop --release --features python,pardiso # + pardiso (needs MKLROOT)
`PowerFlowModel.solve()` reuses cached symbolic factorization across calls
on the same model (it wraps `solver::PersistentSolver` directly) — this
script's repeated-call timing is a *warm* number by construction, the same
way every other tool's `bench_*.py` script is warm (one persistent model
object, reused across the 5 timed calls). There is no separate cold/warm
mode here the way `bench_network.rs` has one, since a fresh
`PowerFlowModel` per call would just be reimplementing that binary's `cold`
mode in slower Python for no benefit.
"""
=
=
=
=
=
=
# Warm-up (first-call overhead — including the first, uncached symbolic
# factorization), then timed runs.
=
=
=
=
# Also time full cold construction+calc, comparable to the other tools'
# "cold (construct+calc)" figure.
=
=
=