# run_scenarios

Python reference for `nagasim.experiments.run_scenarios`.

`nagasim.experiments.run_scenarios`

```python
run_scenarios(layout, scenario_names = None, replications: int | None = None, seed: int = 0, run_length: float | None = None, warmup: float | None = None, crn: bool = True, workers: int | str = 1, on_progress = None, should_stop = None, pool = None, baseline: bool = True, logic = None, controllers: dict | None = None, keep_empty: bool = False, log_level: str | None = None)
```

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

Parameters
----------
layout : dict
    The model, with a ``scenarios`` list of ``{"name", "overrides"}``.
scenario_names : list of str, optional
    A subset to run. The baseline runs too, unless *baseline* is False.
replications, run_length, 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.
seed : int, default 0
    Base seed.
crn : bool, default True
    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.
workers : int or "auto", default 1
    ``"auto"`` times the first replication of the first scenario once and
    reuses that worker count for every scenario.
on_progress : callable, optional
    ``on_progress(done, total)`` counts replications across all scenarios.
should_stop : callable, optional
    Stops between replications and leaves ``completed`` False on the result.
pool : ProcessPoolExecutor, optional
    A pool the caller owns and reuses across studies (best built with
    `nagasim.api.new_pool`). Results are unchanged.
baseline : bool, default True
    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.
logic : str or module, optional
    The caller's LOGIC module, as `nagasim.api.run_model` takes it; every
    scenario's LOGIC blocks take their classes from it first.
controllers : dict, optional
    ``{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.
keep_empty : bool, default False
    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.
log_level : str, optional
    The run log level of every scenario, as `nagasim.api.run_model` takes it (D1395).
    None keeps each scenario's own settings.

Returns
-------
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']
