# auxiliaries

Named expressions read by AUX("name"), evaluated on read.

In the model file this key holds a list of `auxiliary` entries, each named by its `name`.

A scenario, an experiment or an optimizer can set a field by the path `auxiliaries.<name>.<field>`.

## Typical uses

These sections add the rest of a stock-and-flow model to the levels and flows. `auxiliaries` are named expressions. `delays` are material or information delays with a delay time. `subscripts` are dimensions that repeat a record once for each element, such as regions or age groups. System dynamics models use them together with `simulation.sd`.

## Behaviour and rules

An auxiliary is read with `AUX("name")` and is computed on each read. Auxiliaries that read each other in a cycle are an error. A delay is read with `DELAY("name")`. Its `kind` is `material`, `information` or `pipeline`. A material delay conserves the quantity, an information delay smooths a signal, and a pipeline returns the input exactly `delay_time` later.

Material and information delays need the step grid in `simulation.sd`. A pipeline does not. A delay time of 0 or less is an error. The inline forms such as `SMOOTH` and `DELAY3` write the same records for you, and they are allowed only in a flow rate, an auxiliary or a delay input.

A record with `dims` is expanded into one record for each element, named `Pop[north]`. Inside it, a name with the dimension in brackets reads the same element. `SUM(x)` and `MEAN(x)` over `x[*]` aggregate across the elements. A record can give `elements` to replace its first expression for chosen elements.

## Fields

| Field | Type | Required | Default | Unit | Description |
|---|---|---|---|---|---|
| `name` | string | yes |  |  | The auxiliary's name, the argument of AUX("name"). |
| `dims` | list of string |  |  |  | Subscripts this record runs over: it is flattened into one record per element, named "Name[north]" ("Name[north,young]" for two). Inside, "x[dim]" in a LEVEL/FLOW/AUX/DELAY name reads the same element, and SUM(x)/MEAN(x) aggregate over "x[*]". |
| `elements` | object |  |  |  | Per-element equations: {"north": "2", "a,x": "3"} replaces the record's first expression (a level's initial, a flow's rate, an auxiliary's expr, a delay's input) for those elements; the shared one covers the rest. Keys join one element per dim with a comma. |
| `description` | string |  |  |  | What the auxiliary computes; the run does not read it. |
| `expr` | number or string | yes | `"0"` |  | A number, or any flow-rate expression; may call AUX() of another auxiliary (no cycles) and the inline delays. |
| `unit` | string |  |  |  | Label only. |
| `diagram` | object |  |  |  | Position in the stock-and-flow view; ignored by the engine. |
| `locals` | object |  |  |  | Submodel parameter bindings, written by flattening; not authored by hand. |

A field of a nested object is described in the JSON Schema (`naga schema`).

## Example

```json
{"auxiliaries": [{"name": "Demand", "expr": "10 + 2"}]}
```

In the Python builder:

```python
from nagasim import build as nb
m = nb.Model()
m.add_auxiliary(name='Demand', expr='10 + 2')
```

## Used in

Bundled models: [Supply line: order-rate management game](../../gallery/games.md), [Bass diffusion](../../gallery/system-dynamics.md), [Inventory with lead time](../../gallery/system-dynamics.md), [Population (logistic)](../../gallery/system-dynamics.md), [SIR epidemic](../../gallery/system-dynamics.md), [Training pipeline with attrition](../../gallery/system-dynamics.md) and 1 more.

Guides: [Coming from AnyLogic](../../coming-from/anylogic.md), [Coming from Vensim](../../coming-from/vensim.md), [How do I turn a heading and a distance into x and y?](../../how-to/recipes/bearing.md), [How do I add a daily or weekly cycle to a rate?](../../how-to/recipes/daily-cycle.md), [How do I discount a stream of cash?](../../how-to/recipes/discounted-cash.md), [How do I add a first-order information delay to a forecast?](../../how-to/recipes/forecast-lag.md) and 7 more.

## See also

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