Add a VMEX interoperability example - #62
Open
rogeriojorge wants to merge 1 commit into
Open
Conversation
ESSOS optimizes coils; the equilibrium those coils hold is what VMEX (pip install vmex) solves. The two meet without either importing the other, but nothing in the repository showed how. examples/simple_examples/equilibrium_from_coils_vmex.py takes the bundled Landreman-Paul QA Coils, tabulates their Biot-Savart field onto the cylindrical grid VMEX's free-boundary solver consumes, solves the vacuum free boundary, reads the result back as an essos.fields.Vmec and traces field lines through it. The rotational transform it measures agrees with VMEC's own iotaf to 1e-4 relative. Uses only released VMEX 0.6.0 (MgridField.from_cartesian_field, scale_input, solve_free_boundary, wout_from_state, write_wout), so it runs against the published wheel. README and getting_started gain a short section pointing at it.
Codecov Report✅ All modified and coverable lines are covered by tests. |
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.
Why
ESSOS optimizes coils. The equilibrium those coils hold is what VMEX
(
pip install vmex, a JAX implementation of VMEC) solves. The two packages fittogether without either importing the other -- coils leave ESSOS as a
Biot-Savart field tabulated onto a cylindrical grid, which is what VMEX's
free-boundary solver consumes, and the equilibrium comes back as a wout file,
which is what
essos.fields.Vmecalready reads. Nothing in the repositoryshowed that.
What this adds
examples/simple_examples/equilibrium_from_coils_vmex.py, in the directory thatalready holds the cross-package scripts (
coils_from_BOOZ_XFORM.py):Coilsand vmapsBiotSavart.Binto thebatch callable VMEX's tabulator wants;
vj.MgridField.from_cartesian_field(...)-> the external field;vj.scale_inputmaps the reactor-scale QA deck this repository ships onto theunit size those coils were optimized for, to seed the guess;
vj.solve_free_boundary(...)-> a converged vacuum equilibrium whose lastclosed surface was found by the coils, not prescribed;
vj.write_wout->essos.fields.Vmec->Tracing(model='FieldLine'), andthe rotational transform measured from the trace is compared with the one
VMEX computed from force balance.
Plus a short section in
README.mdanddocs/getting_started.rstpointing atit.
Measured output:
The figure shows the coils with the solved surface in 3-D and the Poincare
section of the traced lines.
Scope
Deliberately limited to released VMEX 0.6.0 (the PyPI wheel):
MgridField.from_cartesian_field,scale_input,solve_free_boundary,wout_from_state,write_wout. No unreleased API, and nothing here depends on#61 or on any other open ESSOS branch -- the ESSOS surface used is
Coils,BiotSavart,VmecandTracing.VMEX has a companion PR (uwplasma/vmex#146) documenting the same two seams from
its side and adding one-call helpers for both directions. Once that is released
the tabulation block here shortens to
vj.MgridField.from_coils(coils, ...);until then the explicit vmap-and-chunk wrapper is what the released wheel needs,
so it is what this example shows.
README.md's Project Structure tree is already stale (flatexamples/listing,inputs/rather thaninput_files/) and is left alone rather than half-fixed.Local verification
macOS 14.4, MacPorts Python 3.11, jax/jaxlib 0.9.2, VMEX 0.6.0 from PyPI-tagged
main, ESSOS at this branch.
pytest tests/flake8 --select=E9,F63,F7,F82on the new exampleflake8 --max-line-length=127on the new exampleE402s every ESSOS example has from theXLA_FLAGSprologueexamples/output/VMEX_EXAMPLES_CI=1The
VMEX_EXAMPLES_CIswitch is the one VMEX's own examples read; it is thesingle concession to the other repository's conventions, and it exists so the
script can be smoke-run headless.
Not verified: GPU, and any Python other than 3.11.