Repository navigation
Add weighted OPM Flow adjoints for PET - #19
Merged
KriFos1 merged 2 commits intoNov 27, 2026
Merged
Conversation
This was referenced Nov 26, 2026
FlowAdjoint.run_vjp now targets the official OPM/opm-adjoint
flow_adjoint instead of a fork with the linw objective. Each weight
column is written as a JSON objective (--adjoint-config) with one
rate term per observed value, active on the substep that ends on its
report, and the gradients are read from the
ADJOINT_GRADIENTS_{PORO,PERM}.csv files and their JSON sidecar.
A rate term carries the substep length as a factor. The summary
stores time in single precision, so each batch adds one objective-
only replay with unit weights that gives the lengths in double
precision; the summary time differences then check units, sign and
timing.
Reports no longer have to be at midnight, and state vectors may be
given per active cell or per grid cell. Connection factors that
follow the permeability and multisegment wells are left to
opm-adjoint. The run_vjp(state, weights) contract is unchanged.
This was referenced Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Public API
Adds
subsurface.multphaseflow.opm_adjoint.FlowAdjoint(options), an opt-in Flow wrapper for PET LowRankGN (PET #207).adjoint_executableselects theflow_adjointbinary of the official OPM/opm-adjoint, used for forecasts and derivatives.run_vjp(state, weights)records the centre once, replays one weighted objective per nonzero column and returns one(k, n)gradient block per state variable. Each replay uses its own output directory to protect the forward summary. The existingflowwrapper is unchanged.How it talks to opm-adjoint
--adjoint-config): onerateterm per observed value, active on the substep that ends on its report. No fork or custom objective is needed.ADJOINT_GRADIENTS_{PORO,PERM}.csvand the JSON sidecar.Scope
Serial METRIC decks; producer oil, water and gas surface rates on any report a simulator step ends on; direct porosity or independent permeability fields (mD or natural log of mD), per active cell or per grid cell. Connection factors that follow the permeability and multisegment wells are differentiated by opm-adjoint. Two cases need changes that are not in opm-adjoint master yet: OPM/opm-adjoint#2 for exact gradients with producers on RESV control, and OPM/opm-adjoint#3 for wells that the schedule defines after the first report step.
Verification
Against unmodified OPM/opm-adjoint master (a02f844, OPM modules of 17-18 November 2026) on its three-cell
MODEL_1D_DEBUGtutorial deck:tests/test_flow_vjp.pypasses with fixed and with adaptive time steps (several substeps per report): identity and mixed seeds built with PET'sDataLayoutmatch central directional differences for porosity and permeability.LowRankGNran end to end through the wrapper on a twin experiment (data misfit 3.07 to 0.13 in six iterations).Not exercised: state vectors per grid cell on a deck with inactive cells (the tutorial deck has none). The wrapper reads per-term objective values from the
flow_adjointlog in the extra replay and raises if that format changes. The README documents the executable and fixture needed to repeat the test.