# failures

Resource failures: uptime/downtime distribution pairs per named resource group.

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

A scenario, an experiment or an optimizer can set a field by the path `failures.<name>.<field>`. A data binding can write a field.

## Typical uses

These sections define what entities wait for and when it is available. `resources` are the machines, staff and spaces that SEIZE and PROCESS blocks request. `resource_sets` group resources so that a request takes any one of them. `schedules` give a resource a shift pattern or give a CREATE block a changing arrival rate. `failures` break resources down and repair them.

## Behaviour and rules

A resource has a `capacity` of units, a queue discipline and optional costs. The discipline is `FIFO` by default. The ranked disciplines `LowestValueFirst` and `HighestValueFirst` need a `ranking_expr`. With `rerank` on, the rank is re-evaluated before every grant.

A resource set is seized by its own name. The `rule` picks one member for each request. `PreferredOrder` tries the members in the listed order, and `Cyclical` takes turns. The member that was chosen is the one that is released later.

A schedule is a list of `[duration, value]` points. The value holds for the duration. With `repeat`, the pattern starts over, and without it the last value holds for ever. For a `capacity` schedule the value is a number of units. For an `arrival` schedule it is a rate per time unit. A weekly grid needs `simulation.calendar`.

A schedule or a failure never interrupts a job in service. The unit goes out of service when the job frees it. A resource is built at its full `capacity`, which must cover the highest value its schedule asks for. Each failure draws its own uptime and downtime for each resource it lists.

## Fields

| Field | Type | Required | Default | Unit | Description |
|---|---|---|---|---|---|
| `name` | string | yes |  |  | The failure's name, shown in the resource log. |
| `resources` | list of string | yes |  |  | The resources that fail; each one fails and recovers on its own, drawing its own times. |
| `uptime` | duration | yes |  | time (`uptime.time_unit`) | A duration spec: a distribution, its parameters and an optional unit. Used by link delays and failure uptime/downtime. |
| `downtime` | duration | yes |  | time (`downtime.time_unit`) | A duration spec: a distribution, its parameters and an optional unit. Used by link delays and failure uptime/downtime. |

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
{"resources": [{"name": "Server", "capacity": 1}]}
```

The fragment:

```json
{"failures": [{"name": "Breakdowns", "resources": ["Server"], "uptime": {"distribution": "Exponential", "dist_params": {"rate": 0.01}}, "downtime": {"distribution": "Exponential", "dist_params": {"rate": 0.2}}}]}
```

In the Python builder:

```python
from nagasim import build as nb
m = nb.Model()
m.add_failure(name='Breakdowns', resources=['Server'], uptime={'distribution': 'Exponential', 'dist_params': {'rate': 0.01}}, downtime={'distribution': 'Exponential', 'dist_params': {'rate': 0.2}})
```

## Used in

Bundled models: [Biogas digester, holder and CHP](../../gallery/energy.md), [Biogas plant (library assets)](../../gallery/energy.md), [Line with finite buffers](../../gallery/manufacturing.md), [Machine with breakdowns](../../gallery/manufacturing.md), [Job shop with MES digital twin](../../gallery/manufacturing.md), [Make-to-order line (library assets)](../../gallery/manufacturing.md).

Guides: [Model file format](../../model-file-format.md), [Coming from AnyLogic](../../coming-from/anylogic.md), [Coming from Arena](../../coming-from/arena.md), [Coming from SimPy](../../coming-from/simpy.md), [How do I model a machine that wears out?](../../how-to/recipes/weibull-wear-out.md), [Semantic diff](../../semantic-diff.md).

## See also

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