Skip to content

Add SIMSOPT MHD-energy Optimizable#60

Open
krystophny wants to merge 32 commits into
developfrom
ad-23-simsopt-mhd-energy
Open

Add SIMSOPT MHD-energy Optimizable#60
krystophny wants to merge 32 commits into
developfrom
ad-23-simsopt-mhd-energy

Conversation

@krystophny

Copy link
Copy Markdown
Member

Wraps GVEC as a SIMSOPT Optimizable for the fixed-boundary MHD energy.

  • GvecEnergyProblem re-solves the interior equilibrium for a boundary vector with a target-preserving scipy hybr root solve and caches the solved state per boundary vector.
  • GvecEnergy.J() returns the MHD energy at the solved equilibrium; dJ() returns the analytic reverse boundary adjoint gradient through adjoint_boundary_gradient, exact when the build provides Enzyme derivatives and FD otherwise.
  • make_simsopt_optimizable(state) raises a typed ImportError without SIMSOPT; the problem class itself works without SIMSOPT.
  • Tests skip SIMSOPT-dependent cases when SIMSOPT is missing and validate the adjoint gradient against centered boundary-perturbation finite differences with interior re-solves.

Closes #24.

Verification

Test fails on main

$ bash -lc 'test -f test-CI/unit-pygvec/test_ad_simsopt.py || { echo "missing SIMSOPT wrapper test before AD-23"; exit 2; }'
missing SIMSOPT wrapper test before AD-23

Test passes after fix

Enzyme-off isolated build (FD path):

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

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

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

test_simsopt_wrapper_reuses_cached_equilibrium asserts one equilibrium solve for repeated dJ() and a new solve after a boundary change. test_simsopt_gradient_matches_fd_resolve checks sampled boundary DOFs against (J(x+δ)-J(x-δ))/2δ with full interior re-solves.

@krystophny krystophny force-pushed the ad-23-simsopt-mhd-energy branch from 1cf0fa8 to 154b811 Compare July 9, 2026 22:22
@krystophny krystophny force-pushed the ad-23-simsopt-mhd-energy branch from 154b811 to acdd31a 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