Performance Benchmarks¶
Engine speed beside EwE 6 and EwE-F¶
Since pypath-ewe 1.26.2 Ecosim's RK4 months run as one loop compiled with
numba, since 1.26.3 Ecospace's cells and months
do too, and Adams-Bashforth (method="AB") runs in the same compiled loop. Install the extra to get it: pip install "pypath-ewe[numba]" (the conda
package includes numba). Without numba the same calculation runs in Python.
The compiled month covers the EwE and Rpath rules' usual options (foraging
arena, handling time, prey switching, nutrient limitation, multi-stanza groups,
forcing, migration, detritus, fast-equilibrium groups). A run that uses
mediation, IBM groups, UseVarPQ, a metabolic model, or prey switching together
with link forcing (ForcedSearchLink, ForcedVulLink) keeps the Python step
even with numba installed (pypath.core.ecosim_fast.unsupported_reason names the
cause), and so takes the pre-1.26.2 time. The figures below are for runs on the
compiled path, after the first run of the process.
Measured on 2026-11-30 with pypath-ewe 1.26.3, scripts/benchmark_engines.py,
one thread. Times are milliseconds per simulated year of Ecosim with RK4: the
slope of the wall time over runs of 10, 20 and 40 years.
Beside EwE-F (Linux, Intel i9-10940X; EwE-F built from its current sources)
| Model | Groups | PyPath | EwE-F, its Makefile's flags | EwE-F, -O2 |
|---|---|---|---|---|
| Central Baltic | 22 | 0.99 | 2.83 | 1.07 |
| Curonian Lagoon | 20 | 0.79 | 1.75 | 0.78 |
| Lithuanian Coast | 45 | 2.41 | 11.37 | 3.95 |
| Black Sea* | 23 | 1.17 | 1.84 | 0.97 |
* PyPath's reading of EwE-F's Black Sea case does not yet follow EwE-F's trajectory, so this row compares the cost of a model of that size only. On the other three the end biomasses after 10 years agree to a median 0.006-0.009 %.
Beside EwE 6.7.144 (Windows Server 2025, 2-core GitHub runner, the same EwE database read by both)
| Model | PyPath | EwE 6 | Ecopath solve, PyPath / EwE 6 |
|---|---|---|---|
| Black Sea | 0.52 | 1.68 | 4.4 ms / 4.0 ms |
| LT2022 (45 groups) | 0.75 | 5.37 | 4.6 ms / 4.2 ms |
The two tables come from different machines; do not rank EwE 6 against EwE-F from them. Before 1.26.2 PyPath took 6 to 18 times EwE-F's time per simulated year and 9 to 15 times EwE 6's.
Adams-Bashforth on the compiled loop takes 0.3-1.8 ms per simulated year on the example models, 13 to 35 times less than in Python.
The continuous solvers (LSODA, BDF, Radau, DOP853) evaluate their right-hand side and the month's mean rates on the compiled derivative, with handling time solved at each state. On the Lithuanian Coast model 50 years take 5.3 s with LSODA (30 s in Python), 3.7 s with BDF (12 s), 3.8 s with Radau (14 s) and 12 s with DOP853 (72 s); RK4 and AB take about 0.1 s. Without handling time (the Rpath rule) the results are those of the Python path; with it handling time is solved by another algorithm to the same tolerance, so they agree to about the solver's tolerance.
What is not faster:
- Continuous runs with forcing interpolated within the month keep the Python evaluation. Runs with feeding-time adjustment are compiled but repack the month's inputs at each evaluation, so they gain less (LT2022: 10 years with LSODA 20 s in Python, 6 s compiled).
- Starting up. The first run in a new Python process loads the compiled code; a whole run of a model from its files takes 1-2.5 s, most of it Python and numba starting.
Switching the compiled code off¶
The compiled paths are on by default when numba is installed. Round-off
differences grow in runs that are unstable anyway (a group collapsing to the
biomass floor), so compare such runs by their trend, not digit by digit. Each can be
turned off by setting an environment variable to 0 (or false, no, off)
before pypath is imported:
| Variable | Turns off | Results with it on |
|---|---|---|
PYPATH_FAST_RK4 |
Ecosim's compiled RK4 and AB months | identical to the Python path without multi-stanza groups; with them equal to round-off (a few units in the last place a month): the stanza update's exp and power round differently in numba and NumPy |
PYPATH_FAST_AB |
Adams-Bashforth only | as above |
PYPATH_FAST_CONTINUOUS |
the continuous solvers' compiled evaluation | identical without handling time; with it equal to the handling-time tolerance |
PYPATH_NUMBA_CONSUMPTION |
the compiled consumption kernel | identical |
PYPATH_FAST_ECOSPACE |
Ecospace's compiled cell loop | identical |
PYPATH_FAST_ECOSPACE_MONTH |
Ecospace's compiled month | equal to round-off (about 1e-15 relative): diffusion adds its terms in another order |
Spatial regression gate¶
This section defines the deterministic benchmark gate used for spatial-performance regression checks.
Scope¶
The benchmark suite is in:
packages/pypath/tests/benchmarks/test_spatial_benchmarks.py- Baseline medians:
packages/pypath/tests/benchmarks/spatial_benchmark_baseline.json
Benchmarks currently cover:
diffusion_10x10(100-patch diffusion flux)combined_flux_10x10_10groups(combined diffusion/advection flux path)spatial_simulation_5year_10x10(5-year coupled spatial run)
Local execution¶
python -m pytest packages/pypath/tests/benchmarks/test_spatial_benchmarks.py -q -m "benchmark" --tb=short
To export machine-readable benchmark results:
PYPATH_BENCHMARK_OUTPUT=benchmark-results.json python -m pytest packages/pypath/tests/benchmarks/test_spatial_benchmarks.py -q -m "benchmark" --tb=short
CI gating¶
Workflow: .github/workflows/ci-performance-benchmarks.yml
Triggers:
- Pull requests that touch core runtime/tests/workflow files
- Weekly schedule (
0 3 * * 1) - Manual
workflow_dispatch
The workflow produces:
benchmark-results.jsonartifact (raw timings)benchmark-summary.mdartifact and step summary table (current vs baseline)
Configurable thresholds¶
All thresholds are environment-configurable so they can be tuned for CI hardware:
| Variable | Default | Meaning |
|---|---|---|
PYPATH_BENCH_DIFFUSION_MAX_SECONDS |
0.005 |
Absolute max median for diffusion_10x10 |
PYPATH_BENCH_COMBINED_FLUX_MAX_SECONDS |
0.05 |
Absolute max median for combined_flux_10x10_10groups |
PYPATH_BENCH_SIMULATION_5Y_10X10_MAX_SECONDS |
30 |
Absolute max median for spatial_simulation_5year_10x10 |
PYPATH_BENCH_REGRESSION_MAX_RATIO |
1.5 |
Max allowed median ratio vs baseline |
PYPATH_BENCH_THRESHOLD_SCALE |
1.0 |
Multiplier applied to absolute thresholds |
A benchmark must satisfy both checks:
median <= absolute_threshold * threshold_scalemedian <= baseline_median * regression_ratio
Baseline calibration on CI hardware¶
When CI hardware or workload changes significantly:
- Run the benchmark workflow on
mainwithout code changes. - Review
benchmark-results.jsonartifact medians. - Update
spatial_benchmark_baseline.jsonwith the new medians. - Keep
PYPATH_BENCH_REGRESSION_MAX_RATIOconservative (for example1.3-1.5) to avoid noisy failures while still detecting regressions.
This keeps gating deterministic while preserving sensitivity to meaningful slowdowns.