Repository navigation
Weighted adjoint (Hᵀw) for the JutulDarcy wrapper - #20
Merged
KriFos1 merged 1 commit intoNov 27, 2026
Merged
Conversation
New `weighted_adjoint` option: one adjoint solve per member returns the gradient of sum_i w_i d_i for given data weights (DataFrame or callable (forward_df, member)). With w = C_d^-1 (d_obs - d) this is minus the gradient of the data misfit, as needed by SVGD. The objective is cross-checked against sum(w d) before solving. Also: - Fix cumulative summary vectors (WOPT, ...) being 86400x too large in METRIC/FIELD (JutulDarcy integrates per-day rates over seconds). This changes the values returned for cumulative data types. - Detect LAB units. - Use isapprox for the report-time match in the rate objective. - Share perm-gradient and adjoint-storage setup between both adjoint modes. - Tests: agreement with per-datum sensitivities, linearity in callable weights, Stein's lemma check, and option validation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 26, 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.
What this adds
The wrapper's adjoint mode returns the sensitivity of every requested datum to the parameters, at the cost of one
adjoint solve per datum. A method that only needs the gradient of a scalar, such as the data misfit, does not need
that Jacobian.
With the new option
weighted_adjoint = {parameters = [...]}the wrapper does one adjoint solve per member andreturns the gradient of
sum_i w_i d_ifor given weightsw, as apandas.Serieswith one full-grid gradient perparameter. The weights are set as
adjoint_weights: a DataFrame laid out like the forward output, or a callableadjoint_weights(forward_df, member)that is called after each forward run, so that the weights can depend on thesimulated data. With
w = C_d⁻¹ (d_obs − d)the result is the gradient of the log-likelihood.weighted_adjointcannot be combined withadjoints, and it requiresadjoint_mode = "sensitivities".Also in this commit
WOPT,FOPT, …)came back 86,400 times too large, because JutulDarcy integrates per-day rates over seconds. They are now divided
by that factor. Anyone who reads cumulative data types from this wrapper gets different numbers after this PR.
isapprox, since ministep times are floating-point sums.Tests
tests/test_jutul_darcy.pygains tests that the weighted adjointand a test that cumulative output is in volume units.
Run locally on the bundled TINY model: all 16 tests of
tests/test_jutul_darcy.pypass when the six new ones are run in a process of their own (-k "weighted or cumulative"). Run in one process after the other tests, five of the new ones error at the set-up of their forward-run fixture, inside Julia ("an error occurred while setting an error"); the cause is not known.Relation to #18 and #19
#18 adds a weighted adjoint to this wrapper through a new method,
run_vjp(state, weights), and #19 does the samefor OPM Flow. #18 and this PR give the same quantity,
Hᵀw, through different interfaces, and both changejutul_darcy.py, so they conflict as they stand.run_fwd_simtogether with the forward output, and the weights can be acallable of that member's forward output. A method whose weights depend on the member's own prediction, such as
the misfit weights
C_d⁻¹ (d_obs − d), then costs one forward and one adjoint run per member.that the call runs itself, and the supported data are metric producer rates.
This is opened as a draft so that the two can be reconciled before either is merged.
Related
The PET side, which reads this adjoint and supplies the weights of the data misfit:
Python-Ensemble-Toolbox/PET#205.
🤖 Generated with Claude Code