Repository navigation
Fix implicit midpoint time, convergence reporting and pytree states - #18
Open
rogeriojorge wants to merge 4 commits into
Open
rogeriojorge wants to merge 4 commits into
rogeriojorge wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
rogeriojorge
force-pushed
the
agent/pytree-implicit-midpoint
branch
from
September 26, 2026 21:04
833dbb3 to
94ffda3
Compare
rogeriojorge
changed the base branch from
agent/structure-diffrax-state
to
main
September 26, 2026 21:04
This was referenced Sep 26, 2026
rogeriojorge
added a commit
that referenced
this pull request
Sep 26, 2026
rogeriojorge
added a commit
that referenced
this pull request
Sep 26, 2026
Member
Author
|
Rebased as a stack so the PRs merge in sequence without conflicts: merge (with a merge commit) #48, #46, #50, #51, #9, #12, #13, #34, #52, #53, then #18, #21, #44. Until the earlier ones land this diff also shows their commits. The conflicts with #13/#50 (same |
…d iterate The Newton loop set not_converged = norm >= 1 and returned its complement, so a NaN residual (False for both comparisons) ended the step as successful, and the flag described the residual before the last update rather than the iterate returned. Convergence is now decided on the residual of the returned iterate, which must be finite; a nonfinite residual or update ends the step as nonlinear_divergence, an exhausted budget as nonlinear_max_steps_reached. A failed step returns an infinite error estimate, so an adaptive controller rejects and retries it and a constant-step solve ends with the failure. Tests: NaN/Inf right-hand side, NaN after an update, failed inner solve, max iterations, last allowed update, zero iterations, constant/adaptive solves, and a harmonic oscillator checked for energy and the (2/dt)arctan(w dt/2) phase.
rogeriojorge
force-pushed
the
agent/pytree-implicit-midpoint
branch
from
October 3, 2026 14:38
60ca682 to
806c2e4
Compare
This was referenced Oct 4, 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.
Target: main. Head:
806c2e4, two commits on mainab87385. Old head:60ca682, a 25-commit integration merge carrying #9/#12/#13/#34/#46/#48/#50/#51/#52/#53.Dependencies: none. The step uses
jax.tree.map, so it works with the flat state on main and with #13's(Ck, Fk)tuple state. #21 builds on this solver.Problem
ImplicitMidpointon main:t1instead oft_n + dt/2;successful;The previous fix for (b) set
not_converged = norm >= 1and returned its complement. A NaN residual is False for both< 1and>= 1, so a NaN step ended as success. The flag also described the residual before the last update, not the iterate that was returned.Change (
spectrax/midpoint_solver.pyonly)t_mid, and all state arithmetic usesjax.tree.map. This is the original commit, kept.rtol=1e-6,atol=1e-8, same scaled norm).nonlinear_divergence. This also covers a failed inner GMRES solve. An exhausted Newton budget ends asnonlinear_max_steps_reached.max(1, min(20, max_iters // 2)). Before,max_iters=1gave zero GMRES restarts, so the single allowed update was a no-op.Tests (local, macOS CPU, Python 3.12, jax 0.11.2, diffrax 0.7.2, at
806c2e4)python -m pytest -q -n 2 tests: 21 passed. WithJAX_ENABLE_X64=1: 21 passed.New file
tests/test_midpoint_solver.py, 10 tests. Run against the previous #18 solver, the 9 failure-path tests all fail.nonlinear_divergenceand the error estimate is inf.custom_jvpwith a NaN tangent gives a failure, never success.y'=-y³, one update is not enough, and a converged run satisfies the midpoint equation to 1e-9.y'=-ywithmax_iters=1succeeds with the exact(1-dt/2)/(1+dt/2).rtol=1e-12):(2/dt) arctan(ω dt/2)to 1e-9;ω³dt²t/12within the expected O((ω dt)²) correction (2.3% here).Evidence on a Landau case (not in CI)
Setup: 1D Landau, Nx=4, Nn=40, ν=0, t=20, consistent initial field as in
Examples/1D_Landau_damping.py. Reference: Dopri8 at tol 1e-10. Midpoint uses constant steps withrtol=1e-10.LocalLinearInterpolationdoes not conserve energy (about 1e-9 at dt=0.1).(ω/ω̃ - 1) ω t, ω̃ = (2/dt) arctan(ω dt/2)Notes for review
y_error = y1 − (Euler predictor)is an O(dt²) local estimate for a second-order method, so adaptive midpoint steps are conservative. This is unchanged here.lax.while_loop, so it is not reverse-differentiable. Use Dopri8 forjax.grad.GitHub CI: see the checks on this head. The local results above are not CI results.