# Electrical continuity contracts, schema 2

Authoritative validation: `datacenter_twin/topology.py`. Authoritative output: `SimulationRun` in `datacenter_twin/continuity.py`. The complete runnable input is [reference-site-v2.json](../../datacenter_twin/resources/reference-site-v2.json); obtain a preset through `GET /api/v1/demo?preset=generator_failure`. Every field is required, unknown fields are rejected, and JSON object keys must be unique.

## Quantities and records

Decimal quantities use decimal strings in canonical JSON, including all output times and power/energy values. Input seconds/counts are integers. Input decimal numbers are accepted but strings preserve precision across JSON implementations. Booleans, non-finite numbers, negative unsigned quantities and more than nine decimal places are rejected. The numerical input ceiling is 1e12; it is a computational bound, not an equipment rating. Output ratios may repeat and are rendered with 100 significant digits. Currency totals round half-even once after aggregation.

| Contract | Required fields | Interpretation |
| --- | --- | --- |
| `Asset` | `id`, `name`, `kind`, `capacity_kw`, `failure_domains`, `source_ids` | Unique ID; utility, generator, battery, bus, distribution or load. Positive gross electrical path/input rating in kW, including the load's electrical input rating. Battery rating bounds discharge and charging power. Nonempty, distinct domain and source IDs. |
| `Dependency` | `source`, `target`, `relation` | Existing, distinct asset IDs. `feeds` routes gross electrical power. `requires` propagates the source's availability to the target. `charges` explicitly connects one bus to the battery. Duplicate edges and feed/require cycles are rejected. |
| `Event` | `at_s`, `action`, `target`, `value_kw` | Relative integer seconds, before the end. Actions: `asset_down`, `asset_up`, `domain_down`, `domain_up`, `set_demand`. Only demand changes carry a nonnegative `value_kw`; other events require null. Same-time events use input order. These events operate on the simulation only. |
| `SimulationRun` | `schema_version`, `model`, `engine_version`, `run_id`, `input_sha256`, `mode`, `quality`, `scenario`, `intervals`, `events`, `summary`, `boundary`, `limitations` | Generated by the engine from a validated scenario. It embeds the canonical input, version, source IDs, timeline, energy/cost ledger and explicit limitations. `mode=SIMULATED`; `quality=synthetic_uncalibrated`. |

The scenario includes identity, `currency` (USD/EUR/INR), duration/step seconds, IT demand/envelope kW, distribution efficiency, optional grid/generator energy rates, generator delay, battery capacity/initial state/charge power/charge and discharge efficiencies, source IDs, assets, dependencies and events. The fixture shows every exact key. Efficiencies must be greater than zero and no more than one. Initial stored energy cannot exceed capacity. A nullable rate is unknown; every supplied rate remains illustrative in this model. There is no currency conversion or claim of price verification.

The supported envelope is one utility, one generator, one battery and one aggregate IT load, with up to 64 assets, 256 dependencies and 128 events. Duration is 1–86,400 seconds, step 1–3,600 seconds, and at most 2,000 regular steps. Event/depletion/full-charge boundaries split intervals further; a 5,000-interval execution budget guards expansion. Input requests/files are at most 4 MiB. Each source must reach the load before failures; the charging bus must have a utility path. An unavailable asset has zero transferable capacity.

Every interval reports `[start_s, end_s)`, duration, requested/served/unserved IT kW, individual source/charge/discharge kW, battery opening and closing kWh, IT envelope margin, cumulative grid charge, asset states, warnings, feed flows and a signed energy ledger. Asset states describe the interval's dispatch. Battery energy and cumulative charges are at the interval end. A depletion warning can therefore appear in the interval whose closing energy becomes zero. A 700 kW surviving path with 0.95 distribution efficiency delivers at most 665 kW at the IT boundary; demand stays visible.

`run_id` is the first 20 hex characters of SHA-256 over the model identifier, engine version and input digest. `input_sha256` covers sorted, compact canonical scenario JSON. This supports deterministic replay and provenance, not signatures or tamper-proof audit. Array order is retained; equivalent graph reorderings need not have the same ID.

## Version and migration rules

- Schema 1 remains supported by `run`, `compare` and `/api/v1/planning`. It computes whole-facility energy from assumed PUE; its original JSON remains valid.
- Schema 2 uses `simulate` and `/api/v1/simulations`. A v1 PUE value cannot determine a topology, battery, generator sequence or conversion efficiency. There is deliberately no automatic inference between these models.
- To migrate a planning study, create a v2 fixture, explicitly supply the graph and electrical assumptions, copy only justified demand/currency/tariff facts, and attach their source IDs. Do not apply PUE to the v2 result: cooling is outside its boundary.
- Incompatible future input/output changes increment `schema_version`; model-behavior changes increment the engine version and update model documentation. Existing run exports retain their embedded model/version. Consumers must reject unsupported versions rather than silently discard fields.
- Browser cards and charts format server values for display; the exported JSON retains the full server precision and complete run. A draft edit leaves the previous run visible with an unapplied-edits label until a successful calculation replaces it.

Source IDs establish traceability, not credibility by themselves. The bundled catalogue resolves demo sources; arbitrary user source IDs can remain unresolved and are flagged in the evidence view. No source ID changes `synthetic_uncalibrated` to a calibrated status.
