Repository navigation
Conversation
A simulator that computes adjoints returns the sensitivity of every observed value to the state, and the ensemble stacks these as an (nd, nx, ne) array. A simulator in weighted-adjoint mode is handed weights w and returns the gradient of sum_i w_i d_i per parameter instead, from one adjoint solve per member: a Series indexed by parameter name. _adjoint_array now takes such a Series. Each gradient is placed at its state variable's rows by name, so a parameter list in another order than the state cannot pair a gradient with the wrong variable. A log_ prefix is the simulator naming the log of the variable the state holds. Gradients that do not name the state variables one to one, or have another size, are refused. The simulator protocol describes the mode and the adjoint_weights callable a caller sets on the simulator. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A weighted adjoint is the gradient of a weighted sum of the simulator's outputs. With the weights w = C_d^-1 (d_obs - g(x)) it is G^T C_d^-1 (d_obs - g(x)), the gradient of the log-likelihood, at the cost of one adjoint solve per member whatever the number of data. DataMisfitWeights computes these weights for one member from its forward output, reading the predictions off the output as the ensemble reads them into pred_data so that they stay row for row with the observations. It takes a full or a diagonal data covariance and max-min scaled data, and it is a plain picklable object because parallel runs ship it to their workers. A caller sets it as the simulator's adjoint_weights. The test drives a linear simulator through AssimilationEnsemble.forecast and compares ensemble.adjoints with H^T C_d^-1 (d_obs - H x). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PetLogger writes a table of the run. A scheme that also wants to say what problem it solves, what an iteration did and how the run ended had to format those lines itself. The logger module now has the pieces: - heading(title) and block(title, rows), a titled list of rows with their values lined up, and a column for symbols only when a row has one; - items(title, rows), the same for a list that is written in parts; - change(name, old, new), one line for a value that moved; - format_value and format_duration, how numbers and wall times read in a log. Nothing in the existing schemes changes; the SVGD scheme is the first user. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
When a scheme reached maxiter without converging, why_stop stayed an empty dict. The result is a scipy OptimizeResult, and scipy cannot print one that holds an empty dict, so printing the result of such a run raised. The stop is now recorded as why_stop["maxiter"] = True, as the convergence criteria are. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The graph of a state variable (a given parameter_graphs entry, or the nearest-neighbour connectivity of its grid) was built by a method of the EnIF analysis. It is moved unchanged to a module-level function that takes the scheme, so that another scheme can build the same graphs; the analysis calls it. No change in behaviour. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
scheme = "svgd" with analysis = "adjoint" (Stordal et al. 2021), registered in SPECIAL_SCHEMES since it has no ensemble-Kalman analysis to choose. Each iteration moves every member along the kernel-weighted average of the members' log-posterior gradients plus the repulsion of the kernel, at the cost of one forward and one adjoint run per member. - The gradient of the data misfit is the simulator's weighted adjoint for the weights of pipt.ensembles.DataMisfitWeights, which the scheme hands to the simulator. - Kernels: the p-kernel, Gaussian, inverse multiquadric and its p-variant. - Optimizers for the step: AdaGrad (default), Adam, gradient descent, L-BFGS. - The prior gradient comes from a sample of the prior (EnsemblePrior), or from a sparse factor of its inverse fitted on the graphs of the state (GraphPrior, prior_cov_estimate = "graph"). - The run stops when the Stein direction has become small and has stopped changing (stein_tol, stein_change), and it can be resumed. docs/configuration.md lists the options; the references are added. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
KriFos1
marked this pull request as ready for review
November 26, 2026 09:48
Contributor
Author
|
The combined JutulDarcy companion is now open: Python-Ensemble-Toolbox/SimulatorWrap#21 (integrates #18 and #20 in SimulatorWrap). The two PET-facing derivative paths share the weighted solve. All 17 wrapper integration tests passed together on TINY, including the cross-path gradient, batched finite differences and SI-reference volume checks. OPM remains separate. |
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.
Proposal
Review the combined PET implementation of #204 (LowRankGN/Laplace), #205 (weighted forecast adjoints) and #206 (SVGD) here. The merge preserves the original commits from both forks; #206 already includes #205. The original drafts remain open. @MathiasMNilsen, feedback is especially welcome on the shared derivative contract and the state-coordinate convention.
Derivative contract and entry points
pipt.SVGD/("svgd", "adjoint"):DataMisfitWeightsuses the member’s forward output to seed one log-likelihood VJP during the forecast.ForecastMixinassembles the returned Series by state name into(n_state, n_members). The existing full-Jacobian forecast still yields(n_data, n_state, n_members).pipt.LowRankGN/("lowrankgn", "laplace"):run_vjp(state, weights)batches the negative-log-likelihood gradient and curvature directions at one centre; full-Jacobian mode uses whitened observation directions. Damping retries are forward-only.BaseEnsemble.calc_predictionandForecastMixin.forecastaccept keyword-onlymember_count;[dataassim.laplace].posterior_samplesdefaults toensemble.ne.DataLayout.to_framefor observation labels and check the width of every named derivative block. A singleton direction stays a vector even when there is only one observation. The forecastlog_naming convention is valid only when the PET state already holds the corresponding log coordinate; mapping a name does not transform the derivative.analysis.enif.parameter_graph(name, size, options, prior_info)serves EnIF, SVGD and the Laplace prior. Both schemes remain available through the scheme factory and registry. The PR also includes the original MiniRes adjoint changes, logging helpers, configuration docs and the two additional MiniRes benchmark entries; the published baseline rows are retained.Verification
ruff check src testsandgit diff --cached --checkpassed.Companion simulator work
The external JutulDarcy implementations are under review in Python-Ensemble-Toolbox/SimulatorWrap#18 (batched) and Python-Ensemble-Toolbox/SimulatorWrap#20 (forecast-time); the OPM batched implementation is Python-Ensemble-Toolbox/SimulatorWrap#19. Sharing JutulDarcy’s trajectory implementation belongs in SimulatorWrap and is not claimed as tested by this PET suite.