run_model¶
Python reference for nagasim.api.run_model.
Run replications of a model and return its KPI frames.
Replication r is seeded with seed + r, so a run is reproducible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or dict
|
A model file path, the name of a bundled model ( |
required |
replications
|
optional
|
Fall back to the model's own |
None
|
warmup
|
optional
|
Fall back to the model's own |
None
|
run_length
|
optional
|
Fall back to the model's own |
None
|
seed
|
int
|
Seed of replication 0. |
0
|
workers
|
int or 'auto'
|
More than 1 spreads the replications over a process pool; the output is
identical to a sequential run. |
1
|
on_progress
|
callable
|
|
None
|
should_stop
|
callable
|
Polled between replications and during one; on an interruption only the completed replications are returned. |
None
|
trace
|
TraceRecorder
|
Subscribed to replication 0 only, which then runs in this process. |
None
|
bind_data
|
bool
|
Resolve the model's data bindings once, before the first replication, so
every replication runs on the same bound values. The |
False
|
base_dir
|
path
|
What a source's relative |
None
|
network
|
NetworkPolicy
|
The caller's |
None
|
confine_to
|
path
|
The one directory a file-backed source may be read from. |
None
|
feed
|
Feed
|
The caller's open |
None
|
controllers
|
dict
|
|
None
|
logic
|
str or module
|
The module LOGIC blocks take their classes from first, by dotted name (on
|
None
|
pool
|
ProcessPoolExecutor
|
A pool the caller owns and reuses across calls (see |
None
|
record_logs
|
bool
|
False switches the per-event logs off: the log frames have no rows, so they are left out (see keep_empty), and every summary statistic is untouched. None keeps the model's own setting (default: on). |
None
|
deterministic
|
bool
|
True makes every distribution sample its mean, chance branches use
largest-remainder allocation and replications are forced to 1. None keeps
the model's own |
None
|
pace
|
float
|
Keep pace with the wall clock: pace model seconds per wall second
(1 = real time, 60 = one model minute per second), converted from the
model's time unit. An event already behind the wall clock runs at once
and is counted, never raised. The results are an unpaced run's; the
result's |
None
|
keep_empty
|
bool
|
Also return the frames with no rows (D1321): by default only the frames
that have rows come back, plus |
False
|
log_level
|
str
|
What the run records (D1395): |
None
|
Returns:
| Type | Description |
|---|---|
Results or None
|
A |
See Also
nagasim.experiments.run_scenarios : Several variants of one model, compared. nagasim.experiments.run_until_precision : Replicate until an interval is tight enough. nagasim.experiments.flatten_kpis : The KPI frames as one long table.
Examples:
>>> from pathlib import Path
>>> import nagasim
>>> from nagasim import api
>>> path = Path(nagasim.__file__).parent / "models" / "single_server.json"
>>> results = api.run_model(str(path), replications=2, run_length=200, warmup=20, seed=0)
>>> sorted(int(r) for r in results["system"]["Run"].unique())
[0, 1]
>>> results.kpi("system/Total Entities Completed") > 0
True