Skip to content

Add native Dopri5/Dopri8 orbit tracing and CUDA adapters - #187

Open
eduardolneto wants to merge 12 commits into
mainfrom
feat/native_dopri
Open

eduardolneto wants to merge 12 commits into
mainfrom
feat/native_dopri

Conversation

@eduardolneto

Copy link
Copy Markdown
Contributor

Adds optional native Dopri5/Dopri8 forward tracing for Boozer, VMEC guiding-centre, and Cartesian coil guiding-centre/full-orbit models, using the existing equations and field representations. This is upfated form of PR #169 which will be closed when this branch is merged.

  • Shared solver: fixed/adaptive stepping, FSAL derivative reuse, standard dense interpolation, physical/chart error control, event root-finding and bounded failure handling.
  • Public integration: available through Tracing, trace_boozer and prepare_solver, while retaining the existing Diffrax path.
  • CUDA execution: independent particle loops and private field adapters for coils, VMEC and fixed cosine-Fourier Boozer fields.
  • VMEC performance: automatic one/four-warp selection based on spectrum size. Initial derivative evaluation shares the RK stage loop, reducing compilation cost while preserving reuse after rejection.
  • Diagnostics: per-particle accepted/rejected counts and solver statuses, alongside existing Boozer terminal diagnostics.
  • Benchmarks: scripts regenerate matched native/Diffrax comparisons with identical inputs and error budgets, separating compilation from warm execution. Generated results and temporary files are excluded; .gitignore matches main.

@eduardolneto

Copy link
Copy Markdown
Contributor Author

@rogeriojorge This is ready to be merged.

@rogeriojorge rogeriojorge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be merged LGTM

@rogeriojorge

Copy link
Copy Markdown
Member

Eduardo, a short status on this one.

Main has moved a lot this week (loss API, tracing defaults, CI matrix from Python 3.10/JAX 0.6.2 to 3.14). Your branch already has main merged and has no conflicts.

I opened #195 against this branch with the simplifications I'd like before merging:

  • one dense-output path built from the Butcher tableau, shared by Dopri5 and Dopri8
  • the separate Boozer alpha benchmark removed, since benchmark_native_orbits.py covers it
  • a test that jax.jacfwd of a harmonic-oscillator solve equals the analytic rotation matrix

With #195 merged in, this PR goes from +2594 to +2247 lines. Public behaviour of Tracing, trace_boozer and prepare_solver is unchanged.

Still open: the CUDA/Pallas adapters in rk.py (about 670 lines). The README shows about 2x over Diffrax on an RTX 5060. I'm re-measuring that on the A4000s here, with profiles down to the kernels, before deciding what stays.

If #195 looks fine to you, please merge it into this branch.

@rogeriojorge

Copy link
Copy Markdown
Member

Main moved and this PR now conflicts in essos/dynamics.py. I did not push to your branch. #250 merges main into feat/native_dopri and targets it, so you can take it as is.

The conflict was in the exterior-segment term and the segment solve: main added _masked around the exterior guiding-center field and a finite placeholder for non-finite segment starts, and your branch moved the same code into _terms and _solve. Both changes are combined in your structure. In essos/rk.py, _vmec_radial now continues past the last grid point with the same parabola as main's VMEC interpolation.

Tests under JAX_ENABLE_X64=1: test_native_orbit.py 19 passed, test_dynamics.py 116 passed. Merging #250 clears the conflict here.

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.

2 participants