Skip to content

feat(python): ensembles and burn probability (#172) - #228

Merged
HugoFara merged 3 commits into
forefireAPI:devfrom
HugoFara:feat/runner-fork
Oct 29, 2026
Merged

HugoFara merged 3 commits into
forefireAPI:devfrom
HugoFara:feat/runner-fork

Conversation

@HugoFara

@HugoFara HugoFara commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

First step of #172: burn-probability maps from ensembles, all in Python.

arrivals = pyforefire.run_ensemble(setup, winds, until=3600, perturb=perturb)
p = pyforefire.burn_probability(arrivals, t=1800)   # fraction of members burnt by t
  • setup runs once; each member is a ForeFireRunner.fork() of it (~4 ms vs ~80 ms for a new runner), then perturb changes its wind or fuels.
  • fork=False gives each member a fresh runner instead, for parameters read only at construction (windReductionFactor, propagationSpeedAdjustmentFactor).
  • ForeFireRunner(stdout=..., stderr=...) redirects output; members are silent by default.
  • Arrival times are read through plot[parameter=arrival_time], which can crop to a bbox.

Tested: test_runner.py (forks) and test_ensemble.py (members match the deterministic run, perturbations apply, probabilities in [0, 1] and non-decreasing in time), both in the invariants workflow. Also on the runff Corsica case: 16 wind members in 1.2 s.

New User Guide page: user_guide/ensembles.rst.

Drafted with Claude Opus 5.5.

@HugoFara HugoFara changed the title feat(python): fork a running simulation with ForeFireRunner.fork() (#172) feat(python): ensembles and burn probability (#172) Oct 28, 2026
@filippi

filippi commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

hi @HugoFara still some trouble in the linux build, I thought runners were forks already ! but cool if it forks faster, and nice way to make ensembles in python

…orefireAPI#172)

fork() returns a new runner holding a copy of the simulation, so ensemble
members can branch from one spin-up instead of rerunning it. The worker
forks itself, not the caller: the worker has no threads, and the copy
starts with the whole kernel state. The new socket is passed over the
existing one, and the copy is double-forked so nobody has to reap it.

A fork takes a few milliseconds, against about 80 ms for a new runner.
Open files are shared with the copy, and an HTTP command server is not
copied.
…PI#172)

run_ensemble(setup, members, until, perturb) runs setup once, forks one
runner per member, applies perturb to each and steps them in parallel to
`until`. It returns the arrival-time maps, [member, y, x], and
burn_probability() turns them into the fraction of members burnt by any
time. With fork=False each member gets a fresh runner and perturb runs
before setup, for parameters the kernel reads only at construction, such
as windReductionFactor and propagationSpeedAdjustmentFactor.

The maps are read through plot[parameter=arrival_time] into an ASCII grid,
because the BMap layer is never filled outside coupled runs; bbox crops
them on large domains. ForeFireRunner takes stdout and stderr like Popen,
and ensemble members discard their output by default.

A User Guide page runs a 32-member wind ensemble end to end, and
test_ensemble.py runs in the Model Invariants workflow.
…PI#229)

forefireAPI#229 makes plot[...;filename=*.asc] write a valid ESRI grid, one row per
y from the north edge, so arrival_time flips it instead of transposing it.
@HugoFara

Copy link
Copy Markdown
Collaborator Author

Hi, fixed the small issue with .asc grid.

Forks: ForeFireRunner (#175) didn't fork. It starts a fresh interpreter (python -m pyforefire._worker), because forking a caller that may have threads is unsafe. fork() forks the worker instead, which has no threads. The copy starts with the whole simulation already in memory. So the gain isn't only process startup (~4 ms vs ~80 ms): members branch from one spin-up instead of each rerunning setup.

@HugoFara
HugoFara merged commit 7156823 into forefireAPI:dev Oct 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants