api: Symmetric interp gradients - #3001
Open
mloubout wants to merge 5 commits into
Open
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
The symmetric placement costs an extra inline evaluation of the block, so it is wanted on the handful of equations that need it rather than on a whole operator. `Eq` takes an `interp_mode` and passes it down when it evaluates, leaving `sym_opt` as the default for everything else.
Two changes to what `interp-mode='symmetric'` re-associates. A derivative is where its `x0` puts it, not where the field it differentiates lives. `div(v)` of a staggered velocity lands on the node, and reading the operand's staggering instead made a node-centred kernel look off-node, so it was re-associated onto the operands and its compact stencil replaced by an interpolated one twice as wide. A composite is off only if one of its own operands is, which is what makes a sum of derivatives -- a divergence, a trace -- read as the node-centred quantity it is. The block is then chosen among the factors that are actually off `func`, and it takes two of them for there to be anything to re-associate. With one, the single interpolation `direct` puts on it is already the transpose-consistent form -- it is what makes the `i, j` entry of a stiffness matrix the transpose of its `j, i` entry. With two, `direct` interpolates each separately, and `I(a)*I(b)` is not `I(a*b)`: the discretized operator stops being the transpose of itself, which is invisible in a forward simulation and shows up as a first-order gradient in an adjoint one. The mode also travels down the fallback now. A product that cannot itself be re-associated is routinely wrapped around one that can -- a `dt` scaling, a sum of per-component contractions -- and dropping it there evaluated all of that in `direct`.
A zero-order derivative whose weights collapse to one is the identity, and it comes back as whatever it was applied to. When that is a sum -- the engineering shear strain of a staggered velocity, say -- the rebuild asserted rather than accepting the degenerate result it already handles for a single argument. It is reachable through the symmetric placement of a stiffness contraction.
Four of the five fail without the preceding commits. The fifth guards against over-reach and passes either way: a derivative already sitting on the target must be left alone.
mloubout
force-pushed
the
symmetric-interp-gradients
branch
from
August 11, 2026 18:13
35b3ece to
750eedb
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3001 +/- ##
==========================================
+ Coverage 82.99% 83.02% +0.02%
==========================================
Files 257 257
Lines 54019 54087 +68
Branches 4619 4622 +3
==========================================
+ Hits 44832 44904 +72
+ Misses 8375 8372 -3
+ Partials 812 811 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mloubout
force-pushed
the
symmetric-interp-gradients
branch
3 times, most recently
from
August 11, 2026 19:39
b1cb3c1 to
05eba16
Compare
The staggered-interpolation notebook showed the two modes but not a case that needs the symmetric one. Add the gradient case it exists for: a nodal parameter read at a staggered location, and the matching accumulation back onto the node, where the standard placement is off by 4e-1 against 2e-7.
mloubout
force-pushed
the
symmetric-interp-gradients
branch
from
August 11, 2026 20:12
05eba16 to
a5a789c
Compare
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.
extend interp mode to cover corner cases. Needed for the recipes