Skip to content

Gate SPE5 Case 1 on acceptance bands and a scorecard row against JutulDarcy (#183) - #184

Merged
sergeyfarin merged 11 commits into
masterfrom
test/183-spe5-scorecard-bands
Dec 6, 2026
Merged

sergeyfarin merged 11 commits into
masterfrom
test/183-spe5-scorecard-bands

Conversation

@sergeyfarin

@sergeyfarin sergeyfarin commented Dec 5, 2026 •

Copy link
Copy Markdown
Owner

What and why

This finishes item 2 of the SPE5 order in #52: SPE5 Case 1 now has a gated row against the matched-interval JutulDarcy fixture (opm/compositional/spe5/shut_in/reference.json), compared through the earlier of the two shut-ins.

Before this, compare_small_direct.py --case spe5_shut_in was a diagnostic only. --check refused it, and none of its numbers was compared to a limit.

  • Scored diagnostics (tools/opm_flow/compare_small_direct.py):
    • A manifest diagnostic can opt in with "scored": true. It can then be selected alone with --check or --write-scorecard, and its entry merges into the shared scorecard. --prune-scorecard is refused.
    • A complete run (the records mode CI runs) keeps that entry but does not require it, because the replay takes ~15–20 min. A graded case that goes missing still fails coverage.
  • Scorecard metrics:
    • summary.*: the worst producer oil-rate, GOR, pore-volume-weighted pressure and water-cut differences.
    • stop.reports and stop.reason_differs.
    • These sit beside the cell-33 fields and the work counts already stored.
    • New BANDS entries for them; no existing band changes.
  • Acceptance bands are declared once, in the spe5_shut_in entry of opm/compositional/trajectory_cases.json. They are checked whenever the diagnostic runs and printed beside the measured values; a breach exits non-zero and is never written as a baseline. A scored diagnostic's block must band all four summary differences, the stop's report distance and its condition, or the comparator refuses it before comparing.
  • An explicit check requires the row. --check of a scored diagnostic fails when its scorecard entry, a run, or the baseline of any metric it measures is missing.
  • The gate: bash scripts/validate-compositional.sh spe5 runs the replay, exports the record, and checks the bands and the scorecard entry. update-scorecard-spe5 writes the entry. Both fail when the replay fails or writes nothing.
  • Baseline: written by update-scorecard-spe5 on clean 5be5522e, and documented in docs/SPE5_VALIDATION.md → "Acceptance bands and scorecard row (Gate SPE5 Case 1 against the matched-interval JutulDarcy fixture: acceptance bands and a scorecard row #183)".
Worst through the earlier stop Band Measured (5be5522e)
Producer oil rate (relative) ≤ 3% 2.00%
GOR (relative) ≤ 1.5% 0.86%
Pore-volume-weighted pressure ≤ 0.3 bar 0.1726 bar
Water cut (absolute) ≤ 0.005 0.00218
Stops, reports apart ≤ 1 0
Stop condition same same (water cut, 6285.34375 d)

No engine code changes.

Closes #183. Refs #52.

Decisions I made on the owner's behalf (from #183's "Decisions for the owner")

You approved shaping and building in the session. I used the issue's recommended values; each is easy to change in review.

  1. Band values: the table above.
    • Each of the four trajectory bands is 1.5–2.3× its matched-interval difference (water cut is the 2.3×). Corrected in review: first stated as 1.5–2×.
    • Each is well below either simulator's own interval-vs-0.5 d time-step error: 6.1–7.7% in rate and GOR, 0.38–0.47 bar, and 0.013–0.015 in water cut. A breach establishes a larger gap than measured under the replay settings; it does not say whether physics or step selection moved (each simulator still picks its own internal steps). Corrected in review.
  • The stop band counts reports. A stop between reports counts as the report that ends its interval, so one report apart allows up to two intervals (< 10.15 d) between the stop days; the day difference is printed beside the band, unbanded. Corrected in review: the first version said one report was 5.07 d.
  • Cell-33 fields are ratcheted only, with no acceptance band.
  • Cumulative oil is left for the published Figure 9 comparison (Roadmap: run SPE5, then SPE3, live on the compositional engine #52 item 3).
  1. Placement: the shared scorecard, outside CI's coverage. The row is checked only by the opt-in spe5 gate.
  2. Ratchet bands for the new metrics:
    • 25% relative, with absolute floors of 0.002 (rate, GOR, water cut) and 0.05 bar (pressure), matching p and sw.
    • The stop metrics ratchet exactly.
  3. The product chart's average pressure stays arithmetic (src/lib/compositional/runSeries.ts). Switching it moves a number users see. It belongs with the Figure 12 overlay in Roadmap: run SPE5, then SPE3, live on the compositional engine #52 item 3, and the docs say so.

Validation

Gate Result
cd tools/opm_flow && uv run --with pytest --with numpy python -m pytest -q After the third review: 220 passed, 55 subtests passed. The review tests fail on the head before them, except test_a_breach_is_never_written_as_a_baseline, which guards the restructured write path; the old comparator already refused that write. Before review: 213 passed, 14 subtests passed. Seven new ScoredShutInTests: bands printed and passing; each kind of breach failing (pressure, oil, stop, unmeasured, different condition, no trajectory); merge and ratchet into the shared scorecard; exact stop ratchet; records coverage not requiring the diagnostic but still failing on a missing graded case; prune refused. The existing test that an unscored diagnostic cannot --check still passes.
SPE5_GATE_OUT=… bash scripts/validate-compositional.sh update-scorecard-spe5 on 5be5522e acceptance check: OK, compositional gate 'update-scorecard-spe5': OK. 1239 steps, 0 failed, 6226 Newton, 816 s.
Replay on 0c110a44 (master, same engine) + manual export/compare Identical numbers. 14:51 wall, 1.70 GB peak RSS.
Comparator on the review head against the saved cf5e40fd replay (--case spe5_shut_in --check) acceptance check: OK, cross-solver check: OK; every measured metric has a baseline. The engine and gate script are unchanged since cf5e40fd, so the 1114 s replay below was not repeated.
bash scripts/validate-compositional.sh spe5 on cf5e40fd On cf5e40fd: acceptance check: OK, cross-solver check: OK against the recorded baseline, no regressions or improvements; compositional gate 'spe5': OK (replay 1114 s, with other work running).
bash scripts/validate-compositional.sh records (rerun on the review head) cross-solver check: OK, compositional gate 'records': OK. spe5_shut_in is listed as kept, not measured.
bash scripts/validate-compositional.sh thermo (rerun on the review head) compositional gate 'thermo': OK
bash scripts/validate-cross-solver.sh (flow 2026.10, rerun on the review head) Inventory check: OK, cross-solver check: OK
bash scripts/benchmarks.sh check --tier fast (rerun on the review head) benchmark check: OK, benchmark pages: in sync with their records
pnpm exec vitest run src/lib/catalog, pnpm run typecheck, pnpm run lint 256 passed / 2 skipped; clean; clean

Not run:

  • pnpm run validate:product and validate-solver-coverage.sh: no Rust or frontend logic changed, only a scenario's method-reference string and a comment.
  • validate-native-binding.sh: no payload boundary change.

Also fixed

  • fix(opm): --check printed the scorecard's top-level provenance, which describes only the last write. After this PR's SPE5 write, a black-oil check would have said its baselines were "measured at 5be5522, no black-oil Flow". The header, and (after review) the "Flow itself changed" note, now use each checked case's own measured block. Covered by a test that checks a preserved black-oil row after a compositional write.

  • docs(readme): the local-gates block said "one gate is local only, because CI has no OPM Flow" but listed several commands. --grid-refine and records need no Flow, and PR CI runs records inside benchmarks.sh check --tier fast.

  • The withheld-scenario comment in src/lib/catalog/scenarios.ts still said SPE3 fails at 4109 d, but it completes 15 years since SPE3 fails at 4109 d: separator stability trial converged to roundoff but its trial sum never stops moving by 1e-14 #164. It and the SPE5 method reference also said the scorecard row was missing.

  • fix(opm), from review: the scorecard ratchet passed any regression against a non-finite baseline (1e309, Infinity, NaN), and a NaN measurement passed too. judge() now fails when either side is not a finite number, for every scorecard case. Test: test_a_non_finite_value_never_passes_the_ratchet. --write-scorecard likewise refuses to write a non-finite measured value and leaves the scorecard untouched. Test: test_a_non_finite_measurement_is_never_written.

Follow-up issues

None filed. #157's acceptance looks met since #182 (the replay completes 15 years and the record is in docs/SPE3_VALIDATION.md), but it is still open. Closing it is the owner's call.

🤖 Generated with Claude Code

sergeyfarin and others added 7 commits December 5, 2026 17:12
…card row (#183)

The spe5_shut_in comparison against the matched-interval JutulDarcy fixture
was a diagnostic only: --check refused it and nothing compared its numbers
to a limit. A manifest diagnostic can now opt in with `scored`, which lets
it be selected alone with --check or --write-scorecard and merges its entry
into the shared scorecard. A complete `records` run (CI) keeps that entry
without requiring it, because the replay takes ~20 min.

The scorecard entry stores the worst producer oil-rate, GOR,
pore-volume-weighted pressure and water-cut differences (summary.*) and the
stop agreement (stop.reports, stop.reason_differs) beside the cell-33
fields and the work counts. New BANDS: the summary metrics use the existing
25% relative allowance with absolute floors matching `p`/`sw` (0.05 bar,
0.002); the stop is discrete and ratcheted exactly.

The manifest entry also declares absolute acceptance bands, checked
whenever the diagnostic runs: oil rate 3%, GOR 1.5%, PV-weighted pressure
0.3 bar, water cut 0.005, stops at most one report apart and on the same
condition. Justification: each is 1.5-2x the matched-interval
ResSim-JutulDarcy difference measured on 03e1281 (2.00%, 0.86%,
0.173 bar, 0.00216, +0 reports) and well below either simulator's own
interval-vs-0.5 d time-step error (6.1-7.7% in oil rate and GOR,
0.38-0.47 bar, 0.013-0.015 in water cut), so a breach is an engine
disagreement rather than a resolution difference. No existing band moves.

`validate-compositional.sh spe5` runs the replay, exports the record and
checks both; `update-scorecard-spe5` writes the entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The block said one gate was local only because CI has no Flow, but it
lists five commands: --grid-refine and validate-compositional.sh records
need no Flow, and PR CI runs records inside benchmarks.sh check --tier fast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Written by bash scripts/validate-compositional.sh update-scorecard-spe5 on
5be5522 (clean): 1239 reports to the water-cut shut-in at 6285.34375 d on
both sides, +0 reports. Worst vs JutulDarcy: oil rate 2.00%, GOR 0.86%,
PV-weighted pressure 0.1726 bar, water cut 0.00218; 1239 steps, 6226
Newton, 0 failed. All within the acceptance bands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
--check printed the top-level provenance, which describes only the last
write. After a compositional or SPE5 write, a black-oil check said its
baselines were 'measured at <commit>, no black-oil Flow'. The header now
names the per-case measured blocks of the cases it checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…#183)

docs/SPE5_VALIDATION.md states the bands, their justification and the
5be5522 measurement, marks reference-plan item 4 done and gives the
spe5 gate in Reproducer and gates. ROADMAP §4a item 2 links #183. The
withheld-scenario comment and the SPE5 method reference no longer say the
scorecard row is missing, and the comment no longer says SPE3 fails at
4109 d: it completes 15 years since #164.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing (#183)

Review of #184 (Codex) found three ways the scored-diagnostic gate could
report success with a check missing:

- An explicit --check of a scored diagnostic whose scorecard row was
  removed called it ungated and exited 0. The row, each run and a
  baseline for every metric it measures are now required.
- An acceptance block reduced to a comment printed 'acceptance check: OK'.
  A scored diagnostic's block must now band every summary difference,
  the stop's report distance and its condition; unknown keys, bad
  values and a missing block are refused before the comparison.
- The records coverage exemption covered every diagnostic, so listing a
  graded case as an unscored diagnostic dropped it silently. Only
  scored diagnostics are exempt.

The Flow-change note also used the top-level provenance, which after a
compositional write says Flow None for a black-oil row; it now uses the
row's own measured block, like the header.

A --check now reports both the acceptance bands and the ratchet before
failing; a write still stops at a breach. The stop's day difference is
printed beside its report band, unbanded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…stablish (#183)

Review of #184 (Codex):

- The stop band counts reports, and a stop between reports counts as the
  report that ends its interval, so one report apart allows up to two
  intervals (< 10.15 d) between the stop days. Drop the stated 5.07 d
  equivalence and explain the rule.
- A breach establishes a larger gap under the replay settings, not that
  the engines disagree: matched reports still leave each simulator its
  own internal steps, and the 0.5 d pair moved both stops by one report.
- Say that a missing scorecard row, missing baseline or incomplete bands
  block fails the gate, and drop the stale claim that the shared
  scorecard is still to do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sergeyfarin

Copy link
Copy Markdown
Owner Author

Review round (Codex review of cf5e40fd). Fixed in c27e748f (comparator and tests) and 73150c48 (docs). All five findings reproduced; none is disputed.

1. P1: the gate could pass with a check missing. Fixed.

  • check() takes the explicitly selected scored diagnostic as required. A missing entry, a missing run, or a measured metric with no baseline is now a failure, not an "ungated" note.
  • New acceptance_config_error: a scored diagnostic, or any diagnostic with an acceptance block, must band exactly the four SUMMARY_KEYS (finite and ≥ 0), stop_reports (a whole number ≥ 0) and same_stop_reason: true. Unknown keys are refused. This runs at selection, before the comparison, in every mode.
  • --check now reports both the acceptance bands and the ratchet before failing. A write still stops at a breach, before anything is written.
  • Tests:
    • test_an_explicit_check_requires_the_scored_row_and_its_metrics: row removed, then summary.producer_water_cut or stop.reports removed;
    • test_an_incomplete_acceptance_block_is_refused_before_any_check: ten malformed blocks, including your comment-only case, each in plain, --check and --write-scorecard modes, with no scorecard written;
    • test_a_breach_is_never_written_as_a_baseline.

2. P2: records could drop a demoted graded case. Fixed. The coverage exemption now applies only when diagnostics[case].scored is true. Test: test_demoting_a_graded_case_to_an_unscored_diagnostic_fails_coverage, which fails on cf5e40fd.

3. P2: the stop band claimed 5.07 d. Fixed as you suggested. The report-index rule stays, and the 5.07 d equivalence is gone from the doc and the PR body.

  • SPE5_VALIDATION.md now says a stop between reports counts as the report that ends its interval, so one report apart allows up to two intervals (< 10.15 d).
  • The comparator prints stop days apart: … d (not banded) beside the band.
  • Asserted in test_acceptance_bands_are_printed_beside_the_measured_values.

4. P2: the rationale overstated a breach. Fixed in SPE5_VALIDATION.md and the PR body. A breach now "establishes that, under these replay settings, the two simulators differ by more than they did when the bands were set". The text adds that each simulator picks its own internal steps, that both stops moved a report at 0.5 d, and that attributing a breach takes separate evidence. #183 is corrected to match (see below).

5. P3: the Flow-change note used top-level provenance. Fixed. It now uses the row's own measured block, like the header. Test: test_a_preserved_row_keeps_its_own_flow_after_another_family_is_written merges a compositional write over a black-oil row measured with Flow 2026.10, then checks that row. Both the note and measured_text must name abc1234 / flow 2026.10, not the top-level def5678 / None. It fails on cf5e40fd.

Validation on 73150c48:

Gate Result
uv run --with pytest --with numpy python -m pytest -q 218 passed, 45 subtests passed
Same tests against the cf5e40fd comparator Every new test fails
Comparator --case spe5_shut_in --check on the saved cf5e40fd replay acceptance check: OK, cross-solver check: OK, no missing baseline; stop days apart: +0.0000 d
validate-compositional.sh records OK
validate-compositional.sh thermo OK
validate-cross-solver.sh (flow 2026.10) Inventory check: OK, cross-solver check: OK
benchmarks.sh check --tier fast OK, pages in sync

Not rerun: the fresh ~15–20 min spe5 replay. The engine and validate-compositional.sh are unchanged since cf5e40fd, where it passed, so the saved replay is the same input.

Tracking.

sergeyfarin and others added 3 commits December 5, 2026 20:20
…183)

Review of #184 (Codex): `scored` exempts a case from complete-run
coverage, and a quoted "false" is truthy in Python, so relisting a
graded case as a diagnostic with "scored": "false" dropped it from
records without a word. The manifest reader now refuses any value but
true or false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #184 (Codex): every comparison with NaN is false and nothing
exceeds infinity, so a baseline of 1e309, Infinity or NaN (all accepted
by Python's JSON reader) let a 10 bar regression pass --check, and so
would a NaN measurement. judge() now fails when either side is not a
finite number. Applies to every scorecard case, not only SPE5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #184 (Codex): the water-cut band is 2.29x its measured
difference, so the four trajectory bands span 1.5-2.3x, not 1.5-2x.
No band value changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sergeyfarin

Copy link
Copy Markdown
Owner Author

Second review round (Codex re-review of 73150c48). Both findings reproduced and both are fixed; the two evidence corrections are taken.

1. P2: a quoted scored flag exempted a graded case. Fixed in ddc798df. comp_manifest now refuses any scored value other than JSON true or false, so it fails at load, before coverage is computed. Test: test_demoting_a_graded_case_to_an_unscored_diagnostic_fails_coverage gains subtests for "false", "true", 1 and null.

2. P2: a non-finite value disabled the ratchet. Fixed in 26c27596, as its own commit because it covers every scorecard case, not only SPE5.

  • judge() now fails when either the measured or the baseline value is not a finite number.
  • The same hole existed on the measured side: a NaN measurement compares false against any band and passed.
  • Test: test_a_non_finite_value_never_passes_the_ratchet covers 1e309, Infinity, NaN and a quoted "0.5" baseline.

Evidence corrections.

  • Band ratio: water cut is 0.005 / 0.0022 = 2.29×. SPE5_VALIDATION.md (0b847941), the manifest $comment, this PR's body and Gate SPE5 Case 1 against the matched-interval JutulDarcy fixture: acceptance bands and a scorecard row #183 now say 1.5–2.3× and give each band beside its measured value. No band value changed.
  • The breach-write test: you're right that test_a_breach_is_never_written_as_a_baseline passes on both heads. The old comparator returned at any acceptance failure, before writing. The test guards the restructured path: --check now continues past a breach to report the ratchet, so the write path needed its own stop. My earlier "every new test fails on cf5e40fd" was wrong for that one test. The PR body now says so. This round's eight new subtests all fail on 73150c48.

Validation on 0b847941:

Gate Result
uv run --with pytest --with numpy python -m pytest -q 219 passed, 53 subtests passed
--case spe5_shut_in --check on the saved replay acceptance check: OK, cross-solver check: OK
validate-compositional.sh records OK
validate-compositional.sh thermo OK
validate-cross-solver.sh (flow 2026.10) Inventory check: OK, cross-solver check: OK
benchmarks.sh check --tier fast OK, pages in sync

Not rerun: the fresh SPE5 replay, for the same reason as before; the engine and gate script are unchanged.

Review of #184 (Codex): --write-scorecard wrote whatever it measured,
so a 1e309 Newton count passed the acceptance bands and became the
baseline, after which the unmodified replay failed its check. The write
now refuses any run metric or invariant-pair value that --check would
refuse, prints them and exits 1 with the scorecard untouched;
json.dumps(allow_nan=False) is the backstop. The finite test is shared
with the ratchet. Applies to every scorecard write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sergeyfarin

Copy link
Copy Markdown
Owner Author

Third review round (Codex re-review of 0b847941). The finding reproduced and is fixed in 4b9dcf32.

P2: --write-scorecard could write an infinite baseline. The write path stored whatever scorecard_metrics returned. The fix:

  • A new unwritable_metrics() applies the same finite-number test as the ratchet to every measured value check compares: each run metric, and p/sw/sg of each invariant pair. is_finite_number() is now shared by both paths.
  • If any value fails, the write prints the values, exits 1 and leaves the scorecard file untouched.
  • json.dumps(..., allow_nan=False) backs this up, in case something reaches the writer unchecked.
  • Like 26c27596, this applies to every scorecard write, not only SPE5.

Test: test_a_non_finite_measurement_is_never_written.

  • It writes a finite baseline (Newton 20), then attempts writes with one report's Newton count set to 1e309 and then to NaN.
  • Each attempt must exit 1, name spe5_shut_in/comp newton, and leave the file byte-identical.
  • The unmodified record must then still pass --check.
  • It fails on 0b847941.

Validation on 4b9dcf32:

Gate Result
uv run --with pytest --with numpy python -m pytest -q 220 passed, 55 subtests passed
--case spe5_shut_in --check on the saved replay acceptance check: OK, cross-solver check: OK
--write-scorecard of the saved replay into a copy of the committed scorecard Writes; the SPE5 metrics are identical to the committed row
validate-compositional.sh records OK
validate-cross-solver.sh (flow 2026.10) Inventory check: OK, cross-solver check: OK
benchmarks.sh check --tier fast OK, pages in sync

Not rerun: thermo (the Python comparator is the only change since its last pass) and the fresh SPE5 replay (engine unchanged).

@sergeyfarin
sergeyfarin merged commit c64c50e into master Dec 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gate SPE5 Case 1 against the matched-interval JutulDarcy fixture: acceptance bands and a scorecard row

1 participant