reality_checks¶
Vensim-style reality checks: a test input and a constraint the model must then satisfy.
In the model file this key holds a list of reality_check entries, each named by its name.
Typical uses¶
These sections control how a model is run and compared. simulation sets the run length, the warm-up, the replications, the units and the optional step grid and calendar. outputs switches on extra collection. scenarios are named sets of parameter overrides. reality_checks test a stock-and-flow model against an input and a constraint.
Behaviour and rules¶
The time_unit is the model's base unit. Every duration without its own unit is in it. Statistics are reset at warmup. Each of the replications is an independent run with its own seed. The deterministic mode samples every distribution at its mean and forces one replication. Without a time_limit, a run ends when the model drains, which only works for a model that can drain.
record_logs set to false empties the three event logs and keeps every summary exact. This is what a large study wants. The outputs options cost memory or time, so each is off by default.
A scenario is a list of overrides applied in order to the base model. An override is a path and a value, for example resources.Server.capacity. An override with a missing path or value is an error. The experiments run each scenario and compare them.
Fields¶
| Field | Type | Required | Default | Unit | Description |
|---|---|---|---|---|---|
name |
string | yes | The check's name, as its result lists it. | ||
description |
string | What the check tests; the run does not read it. | |||
inputs |
object | yes | Override path -> value, the same grammar a scenario override's "path" uses (e.g. "auxiliaries.Workforce.expr": "0"). | ||
constraint |
string | yes | A boolean expression over LEVEL()/AUX()/FLOW() and TNOW, checked at every sampled instant the "when" below selects. | ||
when |
string | "always" |
"always" (every sample), "final" (the last sample only), or a window of sampled times, ends included: "after <t>", "before <t>" or "between <t1> and <t2>" (the constraint holds at every sample in it). "eventually", alone or followed by a window, asks that it hold at least once in it. |
A field of a nested object is described in the JSON Schema (naga schema).
Example¶
The fragment refers to entries that are defined elsewhere in the same file:
{"levels": [{"name": "Tank", "capacity": 100, "initial": 40}]}
The fragment:
{"reality_checks": [{"name": "Tank stays empty", "inputs": {"levels.Tank.initial": 0}, "constraint": "LEVEL('Tank') <= 100"}]}
In the Python builder:
from nagasim import build as nb
m = nb.Model()
m.add_reality_check(name='Tank stays empty', inputs={'levels.Tank.initial': 0}, constraint="LEVEL('Tank') <= 100")
Used in¶
Guides: Coming from Vensim, Model assertions and CI, Semantic diff, System dynamics.