Skip to content

run_until_precision

Python reference for nagasim.experiments.run_until_precision.

Keep adding replications until the confidence interval on a KPI is tight enough.

After the first n0 replications the needed count is the textbook n >= (t * s / h)**2 from the current sample. Each step runs at most as many replications again as have run so far (never more than doubling), so a wildly optimistic first estimate cannot blow the budget in one go.

Parameters:

Name Type Description Default
layout dict

The model.

required
kpi str

A flatten_kpis key, e.g. "system/Avg Throughput Time".

required
relative float

Target half-width as a fraction of |mean|; used when absolute is not given.

0.05
absolute float

Target half-width in the KPI's own unit; wins over relative.

None
confidence float

Confidence level of the interval.

0.95
n0 int

Replications of the first pass.

10
max_replications int

Hard cap.

200
seed int

Seed of replication 0.

0
run_length float

Fall back to the model's own settings.

None
warmup float

Fall back to the model's own settings.

None
workers int

Process-pool size.

1
on_progress callable

As in nagasim.api.run_model.

None
should_stop callable

As in nagasim.api.run_model.

None

Returns:

Type Description
tuple

(results, report). The report carries replications, the achieved half_width, the target and met.

See Also

nagasim.api.run_model : A fixed number of replications. nagasim.experiments.flatten_kpis : Where the KPI keys come from.

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"))
>>> results, report = experiments.run_until_precision(
...     layout, "system/Avg Queue Length", relative=0.5, n0=3, run_length=200, warmup=20, seed=0)
>>> report["met"] or report["replications"] == 200
True