Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1fd783f
Replace the benchmark scripts with one benchmark_native.py
rogeriojorge Nov 10, 2026
76ef9ac
Share kernel setup helpers, drop the Boozer CUDA path, fix the JAX 0.…
rogeriojorge Nov 10, 2026
68410a6
Keep top-bit uint64 literals on the host in scalar lowering
rogeriojorge Nov 10, 2026
430626e
Merge simplify/native-ad into simplify/native-trim
rogeriojorge Nov 11, 2026
5ef0c17
Test the native Dopri trajectories against diffrax
rogeriojorge Nov 11, 2026
df7ac40
Test native slowing-down and energy relaxation against Spitzer
rogeriojorge Nov 11, 2026
c8133ad
Bound the Spitzer slowing-down test to one slowing-down time
rogeriojorge Nov 11, 2026
f90086d
Compare native and diffrax adaptive trajectories at the tolerance
rogeriojorge Nov 11, 2026
1d842eb
Record native GPU throughput and memory and the Spitzer slowing-down …
rogeriojorge Nov 11, 2026
5b6820e
Apply the radial speed drift as a perpendicular kick in the guiding-c…
rogeriojorge Nov 12, 2026
ef0733a
Merge branch 'simplify/native-ad' into simplify/native-trim
rogeriojorge Nov 13, 2026
d4178b7
Merge remote-tracking branch 'origin/simplify/native-ad' into simplif…
rogeriojorge Nov 13, 2026
7ac9d2f
Merge remote-tracking branch 'origin/simplify/native-ad' into simplif…
rogeriojorge Nov 13, 2026
035971c
Merge simplify/native-ad into simplify/native-trim
rogeriojorge Nov 13, 2026
87f0d1f
Slim the native stack: drop committed results, figures and QI ALM exa…
rogeriojorge Nov 14, 2026
f806596
Merge simplify/native-ad into simplify/native-trim
rogeriojorge Nov 14, 2026
589f257
Merge simplify/native-ad into simplify/native-trim
rogeriojorge Nov 16, 2026
315296a
Remove native AD and the independent split kernel; fall back to the p…
rogeriojorge Nov 17, 2026
e06d15d
Merge branch 'simplify/native-ad' into simplify/native-trim
rogeriojorge Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 21 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,12 @@ field, standard dense output and I control, and stops VMEC orbits at the LCFS.
and retains its existing electric-field, stopping and exterior-continuation
interfaces. The generic `essos.rk.solve_rk` also accepts an arbitrary array RHS.

For Boozer, use `trace_boozer(..., integrator="essos_dopri8",
native_execution="cuda")`. Its CUDA adapter supports fixed cosine Fourier
fields with K=0; the portable path also supports sine spectra, angle tables
and PI. GPU arrays are private solver views of the original field data;
the public field classes are unchanged. This addition is forward-only:
split collisions and accepted-step reverse AD belong to separate changes.
For Boozer, use `trace_boozer(..., integrator="essos_dopri8")`. Boozer runs on
the portable path only (`native_execution="cuda"` raises): a fused kernel was
slower than the vmapped one. If the installed JAX cannot lower the fused kernel,
`prepare_solver(..., execution="cuda")` warns and uses the portable path. GPU
arrays are private solver views of the original field data; the public field
classes are unchanged.

### Forward comparison

Expand All @@ -365,8 +365,6 @@ VMEC/Boozer use reactor-scale QA at 4 keV and 20 us. Compare backends within row

| Field / model | Stepping | Native / Diffrax warm ms | Native / Diffrax buffers MiB | Measured |
|---|---|---:|---:|---|
| boozer / gc | adaptive | 1.659 / 3.769 | 0.026 / 0.151 | 2026-10-26 |
| boozer / gc | fixed | 18.201 / 50.142 | 0.026 / 0.154 | 2026-10-26 |
| coils / gc | adaptive | 84.426 / 160.362 | 0.026 / 5.980 | 2026-10-24 |
| coils / gc | fixed | 419.872 / 676.766 | 0.026 / 5.970 | 2026-10-24 |
| coils / lorentz | adaptive | 29.429 / 70.426 | 0.070 / 0.731 | 2026-10-24 |
Expand All @@ -381,60 +379,23 @@ Boozer; velocity errors include both absolute and birth-speed-normalized values
against a tighter Diffrax reference. The measured gains include the private
field adapters and describe the complete forward implementation.

Generate all eight comparison workloads and their files on a CUDA machine:
Time the shared and CUDA forward workloads on a CUDA machine:

```sh
python -m examples.benchmarks.benchmark_native_orbits --suite \
--execution cuda --output output/native_forward
for field in coils vmec; do
python -m examples.benchmarks.benchmark_native --suite orbit --field $field \
--execution both --out output/native_forward/$field
done
```

Choose a fresh output folder. The script creates per-workload `comparison.json`
and `comparison.csv`, plus aggregate `forward.csv` and `forward.md`. Generated
results are kept under `output/` and are not versioned. Three blocked warm
samples alternate backend order after startup; setup, compilation and the tighter
reference are excluded. Compilation may use a persistent cache and is not
reported as a cold measurement. Reports include inputs, source hashes, step
counts, failures, error metrics and compiler buffers.

Defaults reproduce the table's 64 particles, 4 keV, seed 42, eight saves,
rtol=atol=1e-9 and 20 us GC workloads. Fixed VMEC/Boozer use 160 steps, coil GC
224, and coil Lorentz 1792 over 2 us. For one workload, omit `--suite` and select
`--field vmec`, `--field boozer` or `--field coils --model gc/lorentz`, with
`--stepping adaptive/fixed`. A matching Boozer transform can be supplied with
`--field-cache`; otherwise the optional `essos[booz]` dependency computes it.

### QA Boozer alpha workload

Previously recorded full workload: 8192 alphas, 3.52 MeV, birth s=0.3,
seed 42, 20 ms, 101 saves, 16 direct Fourier modes. The preceding profiling
run identified an A100/JAX 0.7.2; the full console logs identify a CUDA device.
Compilation and warm execution are separated. This is a CATAPULT-sized
workload, not a new measurement against CATAPULT.

| Method | Control | Compile s | Warm s | Accepted / rejected | Lost / failed |
|---|---|---:|---:|---:|---:|
| Native Dopri5 | I, rtol=atol=1e-10 | 4.247 | 21.554 | 895113025 / 63143676 | 110 / 0 |
| Native Dopri8 | I, rtol=atol=1e-10 | 5.069 | 18.448 | 351025279 / 62226975 | 111 / 0 |
| Native Dopri8 | I, rtol=atol=1e-8 | 4.985 | 9.223 | 189259503 / 7909253 | 106 / 0 |
| Existing RK4 | Fixed dt=1.25e-7 s | 2.728 | 20.244 | 1310720000 grid slots / 0 | 108 / 0 |

These full-workload measurements predate the current extraction and have not
been rerun after the VMEC and initialization updates. RK4 checks loss at endpoints;
native adaptive methods refine the LCFS crossing. The differing loss counts are
not an accuracy proof. Regenerate the workload with the script below when ready.

Run on the machine's normal JAX backend (the alpha example selects CUDA
execution automatically when available):

```sh
python -m examples.benchmarks.benchmark_native_boozer_alpha \
--integrator essos_dopri8 --particles 8192 --horizon .02 \
--rtol 1e-10 --atol 1e-10 --output output/native_boozer_alpha
```

The example saves its Boozer transform, births, trajectories, statistics,
timings and a diagnostic plot. Reuse its `boozer_inputs.npz` with
`--field-cache`; select `essos_rk45` or `rk4` for the corresponding baseline.
Choose a fresh output folder per workload. The script writes `result.json` (compile time,
first execution, warm median, particles per second, compiler buffers, peak memory, lost and
failed counts) and, with `--save-states`, `states.npz`. Generated results are kept under
`output/` and are not versioned. The Diffrax comparison and error columns of the table above
came from an earlier script that has been removed. Defaults are 64 particles, 4 keV, seed 42,
eight saves and rtol=atol=1e-9; fixed steps default to 224 over 20 us (GC) and 1792 over 2 us
(`--model lorentz`). Select `--stepping adaptive/fixed`. The Boozer field needs the optional
`essos[booz]` dependency and always uses the portable JAX path.

## Native split orbit and collisions

Expand All @@ -450,37 +411,10 @@ result = trace_split(field, particles, species, tmax=tmax, timestep=dt) # check

The interval and tolerance controls are local; refine `timestep` and `collision_dtmax` to check
the splitting error. VMEC fields use their own geometry, Boozer fields need
`spatial_geometry=BoozerGeometry.from_booz_xform(booz)`. `execution="independent"` runs one
persistent GPU kernel per particle (float64, Dopri8, zero electric field); `interpret=True` runs it
on CPU. `tests/test_native_split.py` checks Spitzer slowing down, the Lorentz eigenvalues,
`spatial_geometry=BoozerGeometry.from_booz_xform(booz)`. `tests/test_native_split.py` checks Spitzer slowing down, the Lorentz eigenvalues,
Ito/Stratonovich consistency and the absent-bath and lost-particle limits;
`examples/particle_tracing_collisions/native_split_slowing_down.py` prints the Spitzer comparison.

## Accepted-map native reverse AD

`solve_rk(..., adjoint="accepted")` and `trace_split(..., adjoint="accepted")` give gradients of the
accepted-step map: the forward solve keeps accepted intervals, Wiener increments, rejection decisions
and event fractions, and reverse differentiates the stages, dense saves and collision maps
([essos/native_ad.py](essos/native_ad.py)). First-hit times and the adaptive mesh are not differentiated,
so a finite difference that reruns adaptation measures a different map.

```python
def objective(dofs):
out = trace_split(field(dofs), particles, species, tmax=tmax, timestep=dt, adjoint="accepted",
adjoint_max_accepted_steps=4096, adjoint_max_orbit_steps=4096)
return loss(out.ys)
gradient = jax.grad(objective)(dofs)
```

Collisionless orbits use `Tracing(..., native_adjoint="accepted")`. The tape capacities
`adjoint_max_accepted_steps` and `adjoint_max_orbit_steps` raise during reverse when exceeded;
`adjoint_checkpoint_steps` (default 16) trades replay workspace against stored checkpoints and does not
change the gradient. Direct coil fields can use the persistent GPU reverse kernel with
`execution="independent"`; VMEC and Boozer fields use checkpointed JAX. `tests/test_native_ad.py` checks
gradients against forward mode and finite differences through the frozen schedule, the adjoint identity,
checkpoint independence and the persistent kernel against shared reverse.
`examples/coil_optimization/optimize_coils_native_ad.py` minimizes the final minor radius of alpha
guiding centers over the coil dofs. `examples/benchmarks/benchmark_native_ad.py` times value-and-gradient against forward.
`examples/benchmarks/benchmark_native.py` times the orbit and collision suites (`--help`).

## Testing

Expand Down
8 changes: 1 addition & 7 deletions essos/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,13 +1055,7 @@ def __init__(self, trajectories_input=None, initial_conditions=None, times_to_tr
max_steps=1_000_000, exterior_field=None, wall=None, max_returns=16, reentry_depth=None,
particle_batch_size=None, integrator="diffrax", native_error_control="physics",
orbit_length_scale=1., orbit_speed_scale=None,
native_controller="i", native_pcoeff=.4, native_icoeff=.3,
native_adjoint="none", native_adjoint_checkpoint_steps=16,
native_adjoint_max_accepted_steps=None, native_adjoint_parameter_accumulation="segment", adjoint=None):

self.native_adjoint, self.native_adjoint_checkpoint_steps = native_adjoint, native_adjoint_checkpoint_steps
self.native_adjoint_max_accepted_steps = native_adjoint_max_accepted_steps
self.native_adjoint_parameter_accumulation = native_adjoint_parameter_accumulation
native_controller="i", native_pcoeff=.4, native_icoeff=.3, adjoint=None):

from essos.rk import _configure_tracing as configure
configure(self, integrator, model, solver, native_error_control, orbit_length_scale,
Expand Down
Loading
Loading