Staged solve from YAML — medium-level API.


Demonstrates how to run a multi-stage Boulder simulation from Python using BoulderRunner directly, with each stage solved explicitly via solve_stage().

The two-stage PSR → PFR network in configs/staged_psr_pfr.yaml is used: the perfectly-stirred reactor (PSR) reaches steady state first, then its outlet initialises a chain of plug-flow reactor (PFR) cells.

Note

This is the script shape generated by the Boulder GUI.

When you load a YAML in the Boulder interface and click Download Python, the downloaded .py file follows this exact pattern — one solve_stage() call per stage, with the stage id and node list shown as comments.

You can use that script as a starting point for offline batch runs, parameter sweeps, or post-processing without launching the GUI.

See also

Workflow — detailed companion example showing how to call build_viz_network() and network.draw() after each stage to inspect intermediate results.

Requires: cantera, boulder

from pathlib import Path
from typing import Any

from boulder.runner import BoulderRunner

# sphinx-gallery sets cwd to the examples directory; configs/ is one level up.
config_path = str(Path.cwd().parent / "configs" / "staged_psr_pfr.yaml")
runner = BoulderRunner.from_yaml(config_path)
plan = runner.build_stage_graph()
trajectory = runner.new_trajectory()
inlet_states: dict[str, Any] = {}

# Stage 1/2: psr_stage  [nodes: psr]
runner.solve_stage(plan, plan.ordered_stages[0], inlet_states, trajectory)

# Stage 2/2: pfr_stage  [nodes: pfr_cell_1, pfr_cell_2, pfr_cell_3, pfr_cell_4]
runner.solve_stage(plan, plan.ordered_stages[1], inlet_states, trajectory)

# Assemble visualization network from all converged states
runner.build_viz_network(plan, trajectory)
network = runner.network
assert network is not None

Report converged reactor states#

print("Simulation completed.")
print(f"{'Reactor':<20} {'T [K]':>10} {'P [Pa]':>12}")
print("-" * 44)
for r in network.reactors:
    print(f"{r.name:<20} {r.phase.T:>10.2f} {r.phase.P:>12.1f}")
Simulation completed.
Reactor                   T [K]       P [Pa]
--------------------------------------------
psr                     2105.05     101325.0
pfr_cell_1              2117.94     101325.0
pfr_cell_2              2176.61     101325.0
pfr_cell_3              2194.50     101325.0
pfr_cell_4              2197.02     101325.0

Total running time of the script: (0 minutes 0.740 seconds)