Add Enzyme objective state gradient#62
Open
krystophny wants to merge 34 commits into
Open
Conversation
909b42c to
51d9773
Compare
51d9773 to
be9d952
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.
Makes one non-energy objective differentiable with respect to the flat state.
EvalBsqVarianceFlatKernel: volume-weighted variance of|B|^2, computed single-pass from the same flat context and with the same argument signature as the energy kernel.gvec_mhd3d_flat_bsq_variance_gradientthrough the existing__enzyme_autodiffinterface; cached-context wrapperseval_bsq_varianceandeval_bsq_variance_gradient.State.objective_value("bsq_variance", q)andState.objective_state_gradient("bsq_variance", q, method="exact"|"fd"); the FD path differentiates the fixed-state objective, never an equilibrium re-solve.MissingQuantityError; non-Enzyme builds raiseUnsupportedFeatureError.Closes #26.
Verification
Test fails before
Test passes after
Enzyme-on isolated build (fixed RZ, LLVM/Flang 22.1.6):
test_objective_state_gradient_matches_fdchecks the exact reverse-mode gradient against per-component centered differences atrtol=1e-5.test_objective_value_bsq_variancereconstructs the objective from the exported diagnostics atrtol=1e-10.Enzyme-off isolated build:
Fresh fixed-RZ Enzyme build has exactly one
gvec_mhd3d_flat_bsq_varianceand onegvec_mhd3d_flat_bsq_variance_gradientsymbol; ctest 6/6.