# Stage 8: measured-data comparison infrastructure

Implemented 6 November 2026. **The comparison tooling is implemented; experimental validation is not complete.** No measured II C/D dataset or held-out device result is supplied by the synthetic example. Neither a working reader nor a numerically consistent comparison certifies an experiment's provenance or model applicability.

## Traced gap and smallest implementation

The existing path is controls → typed solver worker → numerical result → JSON export. It retains physical settings but has no measured-data provenance, unit/coordinate matching, expected model identity, or protected calibration/held-out split. In simple terms, a plot resembling a published figure cannot establish that the same experiment was modeled or that the prediction was independent of the data used to tune it.

`src/experimental-validation.ts` adds a separate, pure comparison boundary. It does not alter solvers, fit free parameters automatically, import older run JSON by guessing its meaning, or modify old public behavior. Explicit case and prediction artifacts keep numerical provenance and measurements reviewable. A general optimizer would not resolve missing physical inputs or measurement provenance, so calibration remains an external, documented step; the artifact records exactly which conditions were used.

## Artifact contract

Both case and prediction formats are `schemaVersion: 1`. Older/malformed schemas fail explicitly; there is no pre-existing persisted import format to migrate.

The case supplies source kind (`measured` or `synthetic`), a citation, a unique case ID, the **expected** model name/version/source SHA-256, predefined score/error-budget thresholds, and physical conditions. Each condition has an ID, explicit physical settings and a `calibration` or `heldout` split. Measurements supply an observable, exact unit string, finite value, positive standard uncertainty, and optionally a coordinate name/unit/value.

The prediction artifact supplies the matching model and case identity, a convergence declaration with evidence, the IDs used for calibration and condition-specific predictions. Predictions explicitly carry separate arrays for mean, predictive standard uncertainty and a numerical-error bound. Profiles require finite strictly increasing coordinates; scalars require one value. Names and units are matched exactly; there is no implicit centimetre/metre or density conversion. Physical settings must match exactly, including their key set. Coordinate interpolation is linear **inside** the supplied range only; extrapolation is blocked.

Numerical bounds must include time/grid/particle and interpolation error as applicable. Merely supplying zero is not evidence that these errors vanish. The declaration and source/hash identity remain externally reviewable attestations, not proof generated by this comparison function.

The function rejects duplicate IDs/observables and blocks unknown calibration IDs, fitting a held-out condition, a calibration/held-out pair with identical declared physical settings, missing calibration measurements, absent/missing hold-out points, incompatible units/coordinates, stale model versions/hashes and changed physical settings. It cannot detect a deliberately false provenance statement, undeclared preprocessing/leakage or a physically important parameter omitted from the settings; those need review of the actual data and calibration record.

## Scores and decision

The reported residual is prediction minus measurement in the measurement's units. Measurement standard uncertainty and predictive standard uncertainty remain separately visible. A descriptive scale is `s = hypot(sigma_measurement, sigma_prediction)`; this assumes uncorrelated sources for that scale and does **not** imply Gaussian coverage, a p-value, chi-square validity or independent residuals. Calibration residuals in particular can be correlated with fitted predictions.

Numerical error is a separate bounded contribution, not added as Gaussian noise:

```
scoreLower = max(0, abs(residual) - numericalBound) / s
scoreUpper = (abs(residual) + numericalBound) / s
```

Interpolated predictive standard uncertainties use a conservative linear bound for arbitrary neighboring error correlation. Interpolated numerical bounds are meaningful only if their supplied envelope also covers interpolation error. A separate numerical-budget check requires each numerical bound to remain below the case's declared fraction of measurement uncertainty.

- **blocked:** synthetic data, no established numerical convergence, incomplete/mismatched evidence, excessive numerical error, or bounds straddling the predefined threshold. Model/case identity mismatches block before displaying stale residuals.
- **inconsistent:** complete eligible comparisons exceed the threshold even after accounting for numerical bounds.
- **consistent:** all eligible calibration and distinct held-out residuals lie inside the predefined threshold including numerical bounds. This means consistency with **the supplied measurements and assumptions**, not a validated universal model or an experiment independently authenticated by the tool.

Thresholds must be chosen before inspecting results. The example's score threshold 3 and numerical-error fraction 0.25 are invented demonstration settings, not plasma-physics standards or a formal 99.7% criterion. Increasing uncertainties or retuning after observing the hold-out cannot be treated as independent validation.

## CLI and example

```sh
./node_modules/.bin/tsx scripts/validate-experiment.ts CASE.json PREDICTIONS.json NEW-REPORT.json
./node_modules/.bin/tsx scripts/validate-experiment.ts assets/validation-example.json NEW-REPORT.json
```

The second form reads a bundle with `case` and `predictions`. Output must be a new file; existing files are not overwritten. JSON is parsed as data, never evaluated. CLI success means a report was written; inspect its `status`, not just process exit code. The synthetic example deliberately reports **blocked**, even though its point values match, because its source is synthetic and model convergence is unestablished.

## Evidence and remaining experimental gate

Targeted command: `./node_modules/.bin/tsx --test tests/experimental-validation.test.ts` — **8 passed, 0 failed** at implementation. Tests cover real entrypoint comparison, profile matching/interpolation, unit/settings mismatches, missing evidence, hold-out leakage, explicit stale schema/model/version/hash, numerical-error bounds, derived overflow and incompatible/ambiguous results. Finite inputs whose derived arithmetic overflows block comparison instead of creating nonfinite/null residuals or false consistency. These are software contract checks using invented fixtures, not physical validation.

The standalone strict NodeNext typecheck of `src/experimental-validation.ts` passed. The example CLI wrote a report with **blocked**, one matched calibration and one held-out residual, with explicit synthetic-source and unconverged-model reasons.

Execution uses the user's previously authorized scoped host exception outside the inaccessible container, with `login:false`; no policy, hook, credential or browser access changes. Root owns the final repository-wide gate. No deployed-origin/browser/GPU verification was attempted.

To complete the scientific stage: obtain traceable measured radial composition/density/rotation/potential or collector data; reconstruct its source/field/boundary conditions; demonstrate numerical convergence for those observables; document calibration with parameter uncertainty; freeze the resulting model; predict a genuinely held-out physical condition; run this comparison and review uncertainty, correlations and model scope. The tool keeps absent evidence blocked rather than manufacturing experimental completion.
