Skip to content

run_scenarios

Python reference for nagasim.experiments.run_scenarios.

Run every named scenario (all of them by default) and return the results.

Parameters:

Name Type Description Default
layout dict

The model, with a scenarios list of {"name", "overrides"}.

required
scenario_names list of str

A subset to run. The baseline runs too, unless baseline is False.

None
replications optional

Fall back to the model's own simulation section, as in nagasim.api.run_model; run length and warm-up fall back per scenario, so a scenario may override either.

None
run_length optional

Fall back to the model's own simulation section, as in nagasim.api.run_model; run length and warm-up fall back per scenario, so a scenario may override either.

None
warmup optional

Fall back to the model's own simulation section, as in nagasim.api.run_model; run length and warm-up fall back per scenario, so a scenario may override either.

None
seed int

Base seed.

0
crn bool

Common random numbers: replication r of every scenario uses seed seed + r, and each block draws from its own stream, so a block a scenario did not touch draws the same numbers in both runs. The comparison then uses the paired t interval. With False each scenario gets a disjoint seed block and the comparison uses Welch's interval.

True
workers int or 'auto'

"auto" times the first replication of the first scenario once and reuses that worker count for every scenario.

1
on_progress callable

on_progress(done, total) counts replications across all scenarios.

None
should_stop callable

Stops between replications and leaves completed False on the result.

None
pool ProcessPoolExecutor

A pool the caller owns and reuses across studies (best built with nagasim.api.new_pool). Results are unchanged.

None
baseline bool

False skips the baseline, for a caller that keeps the baseline's results from an earlier run; the result then has nothing to compare against until the caller adds it.

True
logic str or module

The caller's LOGIC module, as nagasim.api.run_model takes it; every scenario's LOGIC blocks take their classes from it first.

None
controllers dict

{decision point: controller} for the Policy-mode DECIDE blocks of every scenario, as nagasim.api.run_model takes it; with workers not 1 each controller must pickle.

None
keep_empty bool

Also keep each scenario's frames with no rows, as nagasim.api.run_model (D1328): by default only frames with rows are kept, plus "system" always.

False
log_level str

The run log level of every scenario, as nagasim.api.run_model takes it (D1395). None keeps each scenario's own settings.

None

Returns:

Type Description
ExperimentResult

Per-scenario results and comparison(kpis=...) against the baseline.

Notes

The unit of parallel work is one (scenario, replication), so five scenarios of one replication each fill five workers.

See Also

nagasim.api.run_model : One model, no scenarios. nagasim.optimize.optimize : Search the space instead of naming the points.

Examples:

>>> import json
>>> from pathlib import Path
>>> import nagasim
>>> from nagasim import experiments
>>> path = Path(nagasim.__file__).parent / "models" / "single_server.json"
>>> layout = json.loads(path.read_text(encoding="utf-8"))
>>> layout["scenarios"] = [{"name": "Faster server", "overrides": [
...     {"path": "blocks.process_1.params.dist_params.rate", "value": 1.6}]}]
>>> experiment = experiments.run_scenarios(layout, replications=3, run_length=200, warmup=20, seed=0)
>>> sorted(experiment.results)
['Baseline', 'Faster server']