Repository navigation
feat(solver): let ns-grid solvers continue from their native state - #273
Closed
dionhaefner wants to merge 8 commits into
Closed
dionhaefner wants to merge 8 commits into
dionhaefner wants to merge 8 commits into
Conversation
# Conflicts: # mosaic/tesseracts/navier-stokes-grid/xlb/tesseract_api.py
Contributor
Author
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Relevant issue or PR
Stacked on #272 (Kolmogorov forward checks), which is stacked on #268 and #267. Re-implements the contract of #121 on current
main; #121 itself is superseded and not merged.Description of changes
The solver-in-the-loop benchmark calls a solver once per correction interval and hands the corrected state back through the canonical cell-centred velocity. For a solver on a staggered grid or a lattice, every such round trip loses information. A corrector trained across them would partly learn to undo our interface rather than the solver's error.
Solvers can now continue from their own state:
state(an opaque, solver-specific array) andreturn_state; the output gainsstate. A solver accepts them only if itsInputSchemasetssupports_native_state, and only on a periodic box. Continuing fromstate, a solver takes on only the change from the velocity it returned with that state tov0. An unchangedv0therefore continues the run exactly, and a corrector's change still reaches the solver.grid_layout.py(shared): the face↔centre averages and their inverse, the lift. The average damps mode k by cos(πk/N), which vanishes at Nyquist, so the lift caps its gain at 32. That drops the Nyquist mode, and only it on grids up to N = 100. This cap is interface numerics we own, and every staggered solver uses the same one.Closure check
I ran a chain of one-interval calls against one call over the same time. The setup is the Kolmogorov coarse configuration (64², dt = 0.01, 10 steps per interval), from the three test states of the ground truth. The table gives the relative L2 distance (median / max):
The thresholds carried over from #116 are a median of 0.5% and a 95th percentile of 1%.
forward/kolmogorovdocuments.Testing done
tests/test_grid_layout.py: the averages follow the high-face convention, and the lift inverts them below Nyquist, drops Nyquist, and works on JAX arrays.tests/test_schemas.py:stateandreturn_stateare rejected by solvers that do not opt in and outside periodic boxes.tests/test_ns_grid_native_state.py(Docker): for JAX-CFD, INS.jl and XLB, four chained calls with state match one call to 1e-5. A VJP throughv0and the state, with cotangents on the result and the returned state, matches a central difference to 2%. All pass on images built from this branch merged withmain(2026-10-28).mainfor JAX-CFD, XLB and INS.jl. This was an A/B between images beforemainwas merged in, on multimode at N = 32, TGV at N = 16 and 3D TGV at N = 16, forward and VJP with respect tov0andviscosity.