Skip to content

Add non-energy boundary adjoint example#63

Open
krystophny wants to merge 35 commits into
developfrom
ad-26-objective-boundary-adjoint
Open

Add non-energy boundary adjoint example#63
krystophny wants to merge 35 commits into
developfrom
ad-26-objective-boundary-adjoint

Conversation

@krystophny

Copy link
Copy Markdown
Member

Chains the non-energy objective gradient through the equilibrium boundary adjoint.

  • simsopt_gvec_objective.py composes GvecEnergyProblem's cached interior re-solve with State.objective_state_gradient and adjoint_boundary_gradient, giving an analytic boundary gradient for bsq_variance with no finite-difference re-solves.
  • SIMSOPT Optimizable wrapper GvecObjective with J()/dJ() and an L-BFGS-B optimize_boundary loop.
  • Sampled validation against centered boundary perturbations with full interior re-solves.

Closes #27.

Verification

Test fails before

$ pytest test-CI/unit-pygvec/test_ad_simsopt.py -q --require-pygvec
5 passed in 1.18s   # no non-energy gradient tests, simsopt_gvec_objective.py missing

Test passes after

Enzyme-on isolated build (fixed RZ, LLVM/Flang 22.1.6):

$ pytest test-CI/unit-pygvec/test_ad_simsopt.py -q --require-pygvec
7 passed in 1.63s

test_non_energy_boundary_gradient_sampled re-solves the interior for every boundary DOF and requires cosine similarity above 0.99 and rtol=5e-3 between the adjoint gradient and the finite-difference truth.

Enzyme-off isolated build:

$ pytest test-CI/unit-pygvec/test_ad_simsopt.py -q --require-pygvec
5 passed, 2 skipped in 2.00s

@krystophny krystophny force-pushed the ad-26-objective-boundary-adjoint branch from 65c5d37 to c543810 Compare July 9, 2026 22:48
@krystophny krystophny force-pushed the ad-26-objective-boundary-adjoint branch from c543810 to 22c5608 Compare July 9, 2026 23:02
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.

1 participant