Skip to content

Replay pr3 state rollback and test - #7377

Open
ElyesAhmed wants to merge 2 commits into
OPM:masterfrom
ElyesAhmed:replay-pr3-state-rollback-and-test
Open

Replay pr3 state rollback and test#7377
ElyesAhmed wants to merge 2 commits into
OPM:masterfrom
ElyesAhmed:replay-pr3-state-rollback-and-test

Conversation

@ElyesAhmed

@ElyesAhmed ElyesAhmed commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR completes, hardens, and expands the state rollback mechanism initiated in [#7198].

When a simulator timestep fails to converge and is chopped into smaller sub-steps, any dynamic state modified during the failed iterations or updated at the start of the timestep must be restored to its exact beginning-of-timestep values. Without proper rollback, retried sub-steps start from polluted state, causing non-deterministic trajectories, trajectory divergence, or convergence degradation.

This PR establishes complete state rollback across Blackoil, Well, Aquifer, and Material Law (Hysteresis) subsystems and adds an extensive deterministic timestep replay regression test suite.


Key Additions Beyond #7198

  1. Relative Permeability & Capillary Pressure Hysteresis Rollback:

    • In conjunction with the companion opm-common PR, dynamic directional hysteresis inflection points and historical saturation extrema ($S_{w,\text{max}}$, $S_{g,\text{max}}$, etc.) are now captured at beginTimeStep() and restored on updateFailed().
    • Prevents irreversible shift of hysteresis scanning curves during divergent/chopped Newton iterations.
  2. Linear Solver & Preconditioner Invalidation Documentation:

    • Verified that ISTLSolver::eraseMatrix() completely deallocates AMG hierarchies, smoothers, and coarse matrix factorizations on updateFailed().
    • Documented the role of --cpr-reuse-setup=0 in replay test harnesses: isolates physical state verification from heuristic preconditioner reuse cadences (solveCount_), ensuring exact bitwise replay identity.
  3. Expanded Replay Regression Test Suite & CMake Integration:

    • Added tests/run-all-state-rollback-tests.py providing automated verification across 17 distinct physics configurations.
    • Registered high-impact replay regression tests in regressionTests.cmake (runnable via standard CTest):
      • WCYCLE-1 (Well cycling timers rollback)
      • 2_MSWWELL_MODEL3 (Multisegment well state isolation)
      • MOD4_GRP (Group hierarchy and NUPCOL rate allocations)
      • EXTREME_ROLLBACK_STRESS (Multi-physics stress under forced cuts)
      • FORCED_ROLLBACK_MULTICUT (Cascading multi-cut step retries)
  4. Architectural Cleanup of Snapshot Structures:

    • Encapsulated snapshot members into dedicated PrevTimestepState structs across FlowProblem, FlowProblemBlackoil, and BlackoilWellModelGeneric.
    • Cleanly excluded transient step snapshots from restart serialization.

Subsystem Audit & Rollback Summary

Subsystem / Feature Snapshot / Rollback Mechanism Status
Wells & Groups BlackoilWellModelGeneric::PrevTimestepState (wgstate, nupcol_wgstate, closed_this_step, well_open_times, well_close_times, genNetwork_) Verified
Rock Compaction FlowProblem::PrevTimestepState (rockCompTransMultVal_, minEffectivePressure_, maxWaterPoreVolume_) Verified
Relperm Hysteresis EclMaterialLawManager::captureBeginTimeStepState() / restoreBeginTimeStepState() Verified
Polymer Adsorption FlowProblem::PrevTimestepState (maxPolymerConcentration_) Verified
ACTIONX / UDQ Evaluated strictly at converged step boundaries (endTimeStep()), zero mid-iteration leakage Verified
Dynamic Aquifers Cumulative influx and pressure tables commit strictly at endTimeStep() Verified
Solvent / Foam / Brine Instantaneous evaluations of primary variables; zero cross-step state leak Verified

Companion PR & Dependencies


Verification Results

All 17 active physics regression cases in run-all-state-rollback-tests.py achieve bitwise machine-precision identity ($2 \times 10^{-14}$) between adaptive baseline runs (with failed iterations and chopped steps) and hardcoded replay runs:

  • SPE1CASE2_ROCK2DTR (16 cut steps) — MATCH (2e-14)
  • 0_BASE_MODEL2 (14 cut steps) — MATCH (2e-14)
  • WCYCLE-1 (4 cut steps) — MATCH (2e-14)
  • 2_MSWWELL_MODEL3 (12 cut steps) — MATCH (2e-14)
  • ACTIONX_GCONPROD (15 cut steps) — MATCH (2e-14)
  • ACTIONX_UDQ (21 cut steps) — MATCH (2e-14)
  • MOD4_GRP (8 cut steps) — MATCH (2e-14)
  • 2D_OW_CTAQUIFER (5 cut steps) — MATCH (2e-14)
  • 2D_FETKOVICHAQUIFER (4 cut steps) — MATCH (2e-14)
  • 2D_THREEPHASE_POLY_HETER (7 cut steps) — MATCH (2e-14)
  • 7_HYSTERESIS_MODEL2 (6 cut steps) — MATCH (2e-14)
  • WAGHYSTR-01 (9 cut steps) — MATCH (2e-14)
  • VAPPARS-01 (8 cut steps) — MATCH (2e-14)
  • EXTREME_ROLLBACK_STRESS (18 cut steps) — MATCH (2e-14)
  • FORCED_ROLLBACK_MULTICUT (24 cut steps) — MATCH (2e-14)

Out of Scope / Deferred for Future Work

  • Compositional Model (flow_comp): State rollback hooks for compositional fluid systems.
  • GPU ISTL Solver Backend: Reset parity checks in ISTLSolverGPUISTL.

@ElyesAhmed
ElyesAhmed force-pushed the replay-pr3-state-rollback-and-test branch from fd39f4d to e95b270 Compare August 31, 2026 09:52
Capture and restore dynamic state across simulation sub-steps when
a timestep fails to converge and is chopped/retried:
- FlowProblem / FlowProblemBlackoil: snapshot and restore rock compaction
  transmissibility multipliers, minimum effective pressures, maximum
  water pore volume, and polymer maximum concentration; restore dynamic
  material law hysteresis state via EclMaterialLawManager.
- BlackoilWellModelGeneric: snapshot and restore well/group operating
  controls, NUPCOL targets, dynamically shut-in wells, WCYCLE open/close
  timers, and surface network branch/node pressures.
- ISTLSolver: clean and deallocate AMG hierarchies and preconditioner
  caches on updateFailed().
- OutputBlackoilModule: properly initialize per-cell hysteresis parameters.
- Add tests/run-timestep-replay-regressionTest.sh to compare adaptive baseline
  runs against hardcoded INFOSTEP replay runs.
- Add tests/run-all-state-rollback-tests.py and wrapper script to validate
  state rollback across 17 distinct physics configurations.
- Register high-impact replay regression tests in regressionTests.cmake
  (WCYCLE-1, 2_MSWWELL_MODEL3, MOD4_GRP, EXTREME_ROLLBACK_STRESS,
  FORCED_ROLLBACK_MULTICUT, etc.).
- Document the role of --cpr-reuse-setup=0 in replay tests for exact
  bitwise trajectory identity (2e-14).
@ElyesAhmed
ElyesAhmed force-pushed the replay-pr3-state-rollback-and-test branch from e95b270 to 55d8250 Compare August 31, 2026 10:01
@ElyesAhmed
ElyesAhmed marked this pull request as ready for review August 31, 2026 10:03
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.

1 participant