ensemble_problem
Stable type · Simulation
Tier: stable · Kind: type · Topic: Simulation
| Julia | TypeScript | Python | Rust | Go |
|---|---|---|---|---|
| not exported | outside profile | EnsembleProblem | EnsembleProblem | outside profile |
Julia
Julia does not export this type.
TypeScript
Not available in TypeScript. TypeScript is outside the simulation capability profile (Julia, Python, Rust): build an RHS and integrate it; TypeScript and Go are deliberately non-simulating.
Python
class EnsembleProblem
EnsembleProblem(prob: EsmProblem, rewrite: Callable[[EsmProblem, int], EsmProblem | None] | None = None)
EnsembleProblem.problem_for(i: int) -> EsmProblem
EnsembleProblem.solve(trajectories: int | None = None, **kwargs: Any) -> list[Solution]
A EsmProblem
plus a per-trajectory rewrite (esm-libraries-spec §2.5.8).
This is the canonical form for a parameter sweep, Monte Carlo over declared distributions, and perturbed initial conditions:
ens = EnsembleProblem(prob, lambda p, i: remake(p, p={"k1": ks[i]}))
sols = solve(ens, trajectories=len(ks))
rewrite(prob, i) returns the EsmProblem for trajectory i (0-based) —
ordinarily via remake
, so the family shares one build. A rewrite
that returns None runs the base EsmProblem unchanged.
Members
problem_for— The EsmProblem for trajectoryi.solve— Solve the family, returning oneSolutionper trajectory.
Example (ensemble_problem)
rates = [0.1, 0.2, 0.3]
ensemble = earthsci_ast.EnsembleProblem(
prob, lambda p, i: earthsci_ast.remake(p, p={"lambda": rates[i]})
)
runs = earthsci_ast.solve(ensemble, trajectories=len(rates), saveat=[10.0])
finals = [run["N"][-1] for run in runs]
for rate, final in zip(rates, finals):
assert math.isclose(final, 100.0 * math.exp(-rate * 10.0), rel_tol=1e-3)
Rust
pub struct EnsembleProblem<'a> {
/* private fields */
}
impl<'a> EnsembleProblem<'a> { pub fn new(prob: &'a EsmProblem, trajectories: usize, rewrite: impl Fn(&EsmProblem, usize) -> Result<Remake, SimulateError> + 'a) -> Self }
impl<'a> EnsembleProblem<'a> { pub fn problem(&self) -> &EsmProblem }
impl<'a> EnsembleProblem<'a> { pub fn trajectories(&self) -> usize }
impl<'a> EnsembleProblem<'a> { pub fn trajectory(&self, i: usize) -> Result<EsmProblem, SimulateError> }
A EsmProblem plus a per-trajectory rewrite, and the family it stands for (§2.5.8) — the canonical form for parameter sweeps, Monte Carlo over declared distributions, and perturbed initial conditions.
Go
Not available in Go. Go is outside the simulation capability profile (Julia, Python, Rust): build an RHS and integrate it; TypeScript and Go are deliberately non-simulating.