Skip to content

Shared JutulDarcy weighted adjoints for PET GN and SVGD - #21

Merged
KriFos1 merged 3 commits into
Python-Ensemble-Toolbox:mainfrom
KriFos1:integration/jutul-weighted-adjoints
Nov 27, 2026
Merged

KriFos1 merged 3 commits into
Python-Ensemble-Toolbox:mainfrom
KriFos1:integration/jutul-weighted-adjoints

Conversation

@KriFos1

@KriFos1 KriFos1 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Companion to Python-Ensemble-Toolbox/PET#207. Integrates #18 and #20 with their original commits. #19 is independent (OPM Flow). @MathiasMNilsen, review of the shared solve and summary-unit behavior would be welcome.

Entry points and behavior

  • JutulDarcy.run_vjp(state, weights) returns named (k, n) PET-state blocks. Several directions share one centre simulation. JutulDarcy.run_fwd_sim in weighted_adjoint mode evaluates the weights callback on the live member output and returns the named gradient Series with the forecast. Both use the same weighted well objective, gradient extraction and well-index chain rule. Weighted objectives are METRIC only. The existing per-datum adjoints interface remains available.
  • JutulDarcy.__call__ runs serial calls directly and starts fresh processes for parallel ensembles, avoiding a fork of an initialized Julia runtime.
  • extract_datatypes now reads surface production/injection rates and totals from the SI summary and converts to the deck’s units, including well injection totals and field liquid production. This avoids hardcoding a correction to Jutul’s non-SI cumulative implementation. Previously METRIC/FIELD cumulative volumes in JutulDarcy 0.3.11 were 86,400× too large. LAB rates are per hour and volumes are cm³; SI is per second. Recheck workarounds applied to historical forecasts.

Local verification

  • 17/17 passed in one pytest invocation: tests/test_jutul_darcy.py tests/test_jutul_vjp.py, using JutulDarcy 0.3.11 and bundled TINY. Covers a common weight vector through both interfaces, two batched directions versus finite differences, weighted versus per-datum adjoints, the parallel Stein check, and field/well rates and totals against SI across four reporting unit systems on one trajectory.
  • Outside JutulDarcy, test_npv_missing_columns_error expects a KeyError but the NPV code warns and fills zeros. Reproduced on an untouched 8e730a4 checkout. No NPV or OPM changes.

MathiasMNilsen and others added 3 commits November 26, 2026 08:48
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>
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.

2 participants