# 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 -&gt; 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 &lt;t&gt;", "before &lt;t&gt;" or "between &lt;t1&gt; and &lt;t2&gt;" (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:

```json
{"levels": [{"name": "Tank", "capacity": 100, "initial": 40}]}
```

The fragment:

```json
{"reality_checks": [{"name": "Tank stays empty", "inputs": {"levels.Tank.initial": 0}, "constraint": "LEVEL('Tank') <= 100"}]}
```

In the Python builder:

```python
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](../../coming-from/vensim.md), [Model assertions and CI](../../model-assertions.md), [Semantic diff](../../semantic-diff.md), [System dynamics](../../system-dynamics.md).

## See also

- [All sections](index.md), [Model file keys](../schema.md), [Model file format](../../model-file-format.md)
