Skip to content

GlobalDiffEq: add GlobalErrorTransport global error estimation and control - #3956

Closed
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:globaldiffeq-transport
Closed

ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:globaldiffeq-transport

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Jul 18, 2026 •

Copy link
Copy Markdown
Member

[!IMPORTANT]

Rebased onto current master (which now includes the merged GLEE methods, #3954) and bumped to v1.4.0; verified against released SciMLBase (Core: Companion 14/14 + GLEE 37/37; QA 23/1).
Ignore this PR until it has been reviewed by @ChrisRackauckas.

Independent PR — a single commit on current master (GlobalDiffEq v1.4.0), with no dependency on the other GlobalDiffEq PRs; reviewable and mergeable on its own. Contains only GlobalErrorTransport. (It adds src/companion.jl, byte-identical to the copy in #3957, so the two still merge cleanly in any order.)

Summary

Adds GlobalErrorTransport — global error estimation and gtol-based control by the linearized error-transport (first variational) equation, addressing SciML/GlobalDiffEq.jl#5 (Shampine 1986 / Berzins 1988 / Lang–Verwer 2007). After a dense forward solve with interpolant P(t), the companion linear ODE ε' = J(P(t))ε + d(t) with the dense-output defect d(t) = f(P(t)) − P'(t) is integrated from ε(t₀)=0; ‖ε(T)‖₂ estimates the endpoint global error. The Jacobian is applied matrix-free via DifferentiationInterface (any ADTypes backend; default AutoForwardDiff()). global_error_estimate(prob, alg) is the standalone estimator.

Review direction (this is the architectural thread)

Recording the plan from @ChrisRackauckas's comment so it's on record, split out from this PR:

  1. A global-error interface in SciMLBase — a has_global_error(alg)::Bool trait (default false); a sol.global_error field (array-of-arrays matching u, nothing when the method doesn't compute it); uniform accessors. (SciMLBase PR; public API + docs together.)
  2. GLEE as its own solver library, feeding the interface — move the RK GEE methods (GlobalDiffEq: add GLEE23/GLEE24/GLEE35 and MM5GEE global-error-estimating solvers #3954) into a dedicated OrdinaryDiffEq solver sublibrary; savevalues! splits the partitioned (y, ε) ArrayPartition so the user gets a normal sol.u and the ε register lands in sol.global_error; has_global_error returns true. Documented as an OrdinaryDiffEq.jl feature.
  3. Wrappers on the same interface — GlobalErrorTransport (this PR), GlobalDefectCorrection (GlobalDiffEq: add GlobalDefectCorrection global error estimation and control #3957), and GlobalAdjoint (GlobalDiffEq: add adjoint-based global error control as a SciMLSensitivity extension #3953) compute the estimate differently but populate the same sol.global_error.
  4. Adjoint every-step mode (GlobalDiffEq: add adjoint-based global error control as a SciMLSensitivity extension #3953) — loss over the sum of steps + matching adjoint problem, filling sol.global_error along the trajectory.

Sequencing: SciMLBase interface → GLEE solver library → migrate wrappers → adjoint every-step. I'll open these as separate PRs and link them here. This PR will be revised to populate sol.global_error once (1) lands.

Validation (run locally, current master)

  • ODEDIFFEQ_TEST_GROUP=Core: pass — Basic 1/1, Algorithm traits 3/3, Companion error estimators 14/14, BigFloat 2/2.
  • ODEDIFFEQ_TEST_GROUP=QA: pass — 23 passed, 1 pre-existing declared broken.
  • On Lotka–Volterra vs a 1e-13 reference: estimate/true-error ratios within 10% at tolerances 1e-4 and 1e-6, in-place and out-of-place; gtol = 1e-7 control delivered a true endpoint error of ~1e-8.

🤖 Generated with Claude Code

@ChrisRackauckas

Copy link
Copy Markdown
Member

The GLEE methods should be a solver library.

And we should make the global error actually an interface in SciMLBase: a trait for whether a method computes the global error, a global error field (which is nothing when a method doesn't compute it), and then it should be a matching array of arrays. The savevalues on this type of method should properly split the ArrayPartition so that the user gets back a normal solution in u and put the u.x[2] into the global error save. Then this should be documented as an OrdinaryDiffEq.jl thing.

The adjoint method could use this same interface just computed differently?

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Thanks — this reframes the direction. Summarizing the plan so it's on record, split from this PR:

1. A global-error interface in SciMLBase. Add to SciMLBase:

  • a solver trait, e.g. has_global_error(alg)::Bool (default false), that a method sets true when it computes a global error estimate;
  • a global_error field on ODESolution (an array-of-arrays matching u, or nothing when has_global_error(alg) is false);
  • accessor(s) so downstream code reads it uniformly (sol.global_error, and a per-time getter).

This is a SciMLBase PR (public API + docs together, minor bump).

2. GLEE as its own solver library, feeding the interface. Move GLEE23/24/35/MM5GEE out of GlobalDiffEq into a dedicated OrdinaryDiffEq solver sublibrary. The partitioned (y, ε) stepping stays internal; savevalues! splits the ArrayPartition so the user gets a normal solution in sol.u and the u.x[2] register lands in sol.global_error. has_global_error returns true for these algs. Documented as an OrdinaryDiffEq.jl feature (not a user-visible ArrayPartition).

3. GlobalErrorTransport / GlobalDefectCorrection / GlobalAdjoint on the same interface. These wrappers compute the estimate differently (companion ODE / adjoint) but populate the same sol.global_error, so the user-facing surface is uniform regardless of method.

4. Adjoint every-step mode (PR #3953 comment). Extend the adjoint estimator from an endpoint functional to a per-step one by making the loss the sum over saved steps and building the matching adjoint problem, so sol.global_error is filled along the trajectory rather than only at the endpoint. Fits naturally once the interface in (1) exists.

Proposed sequencing: land the SciMLBase interface first (1), then the GLEE solver library on top of it (2), then migrate the wrappers (3), then the adjoint every-step mode (4). I'll open these as separate PRs and link them here. This PR (GlobalErrorTransport) will be revised to populate sol.global_error once (1) lands.

Ignore until reviewed by @ChrisRackauckas.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Step 1 of the plan is up: SciML/SciMLBase.jl#1531 adds the global-error interface — a has_global_error(alg) trait (default false) and a global_error field on ODESolution (default nothing, an array matching u when present), threaded through build_solution/setproperties/solution_slice with nothing defaults so nothing existing changes. Verified against the SciMLBase Core suite.

Next: wire the GLEE methods (#3954) to set has_global_error = true and split their internal (y, ε) ArrayPartition in savevalues! so the user gets a normal sol.u and the ε register lands in sol.global_error; then migrate the transport/correction/adjoint wrappers onto the same field; then the adjoint every-step mode.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Step 2 is up: #4267 migrates the GLEE/MM5GEE solvers onto the interface. has_global_error is true, the extended (y, ε) solve is split in __solve, and a projecting interpolation reuses the high-order dense output so the user gets an ordinary solution (sol.u, sol(t), sol(t, Val{1}), in-place all return the solution at full order) with the estimate in sol.global_error. Depends on SciML/SciMLBase.jl#1531 (SciMLBase ≥ 3.48); stacked on #3954; verified locally (GLEE suite 91/91).

Remaining: migrate the GlobalErrorTransport/GlobalDefectCorrection/GlobalAdjoint wrappers onto sol.global_error, and the adjoint every-step mode. (The "GLEE as its own solver sublibrary" reorg is a mechanical follow-up once the sublibrary settles — the interface behavior it needs is in #4267.)

Standalone (unstacked) sublibrary addition: the linearized
error-transport estimator (SciML/GlobalDiffEq.jl#5; Shampine 1986 /
Berzins 1988 / Lang-Verwer 2007). After a dense forward solve, the
companion linear ODE ε' = Jε + d(t) driven by the dense-output defect
d(t) = f(P(t)) - P'(t) is integrated for the endpoint global error,
with matrix-free Jacobian-vector products through
DifferentiationInterface. gtol-controlled solves tighten local
tolerances; global_error_estimate(prob, alg) is the standalone
estimator. Carries a self-contained copy of the companion machinery
(src/companion.jl) shared with the GlobalDefectCorrection PR.

Verified locally on current master: Core (companion estimators 14/14)
and QA (23 pass, 1 pre-existing declared broken).

Co-Authored-By: Chris Rackauckas <[email protected]>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Superseded by #4492, which unifies the two defect-companion estimators (GlobalErrorTransport and GlobalDefectCorrection) into a single GlobalErrorEstimation(alg; equation, mode) parameterized by orthogonal GlobalErrorEquation (DefectCorrection | ErrorTransport) and GlobalErrorMode (InterpolatingMode | SimultaneousMode) enums. Closing in favor of that.

ChrisRackauckas added a commit that referenced this pull request Sep 10, 2026
…4492)

Replace the separate GlobalDefectCorrection and GlobalErrorTransport wrappers
with a single GlobalErrorEstimation(alg; equation, mode) parameterized by two
orthogonal enums:

  - equation (GlobalErrorEquation): DefectCorrection (nonlinear
    ε' = f(P+ε) - P') or ErrorTransport (linearized ε' = J(P)ε + d, matrix-free
    JVP via DifferentiationInterface).
  - mode (GlobalErrorMode): InterpolatingMode (store the dense solution,
    integrate the companion in a second pass) or SimultaneousMode (advance the
    companion inline over each step for O(1) extra memory and no second solve).

Both axes share one defect-companion implementation. Supersedes #3956 and #3957.



Agent-Harness: Claude Code
Agent-Model: claude-opus-4-8
Agent-Session: https://claude.ai/code/session_01MfUh8tgp3iBmMv9nkBqoyY

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Claude <[email protected]>
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