DKX¶
Differentiable neoclassical transport for stellarators and tokamaks, in JAX.
DKX solves the radially local, linearized drift-kinetic equation of SFINCS v3 on
toroidal flux surfaces. From a magnetic geometry and plasma profiles it computes
particle and heat fluxes, parallel flows, the bootstrap current, transport
matrices, monoenergetic coefficients and the ambipolar radial electric field, on
CPU or GPU. Every output can be differentiated with jax.grad, and SFINCS v3
input decks run unchanged.
Quickstart¶
A calculation is one case: a mapping with a geometry, species profiles, a physics model, an electric field, a phase-space resolution and a solver choice (Case files lists every field). This one is an analytic tokamak at a teaching resolution; it runs in seconds and is not converged.
import dkx
case = dkx.Case.from_mapping({
"name": "tokamak", "run": {"workflow": "profile", "progress": False},
"geometry": {"format": "analytic", "file": "tokamak", "surfaces": [0.16, 0.25, 0.36]},
"species": [{"name": "deuterium", "charge": 1, "mass_amu": 2.014,
"density_m3": [8.0e19, 7.0e19, 6.0e19], "temperature_keV": [1.0, 0.8, 0.6]}],
"physics": {"model": "full_local", "collisions": "pitch_angle_scattering", "magnetic_drifts": "dkes", "phi1": "off"},
"electric_field": {"mode": "prescribed", "value_kV_m": 0.0},
"resolution": {"theta": 9, "zeta": 1, "pitch": 8, "speed": 4}, "solver": {"method": "auto", "relative_tolerance": 1e-8},
})
result = dkx.run(case)
print("solver route:", result.metadata["solver_route"])
print(float(result.arrays["particle_flux_m2_s"][1, 0])) # particle flux, m^-2 s^-1
The same case lives in examples/tutorials/02_cli_case.toml. Before quoting a
number, run dkx converge examples/tutorials/02_cli_case.toml: it refines every
phase-space axis and exits zero only when the observables stop moving and every
returned state satisfies the kinetic equation (Convergence).
What DKX computes¶
Quantity |
Result array or SFINCS variable |
Page |
|---|---|---|
particle and heat fluxes per species |
|
|
bootstrap current and parallel flow |
|
|
ambipolar \(E_r\) and every root branch |
|
|
thermal transport matrix (RHSMode 2) |
|
|
monoenergetic \(D_{11}^*\), \(D_{31}^*\), \(D_{33}^*\) (RHSMode 3) |
|
|
in-surface potential \(\Phi_1\) and impurity fluxes |
|
|
derivatives of any of the above |
|
How the documentation is organized¶
Section |
Read it to |
|---|---|
install DKX and check the environment |
|
learn DKX: a step-by-step track from a first run to ambipolar \(E_r\), transport coefficients, \(\Phi_1\), bootstrap current, gradients and optimization, with the equations at each step |
|
look up every input field, output array, CLI command and Python entry point |
|
see the pipeline from a case to a result, module by module |
|
read the equations, collision operators, drives, electric field, \(\Phi_1\) and geometry models |
|
understand the discretization, the solver routes, preconditioners, factor reuse and adjoints |
|
check the analytic limits, the SFINCS, MONKES and YANCC comparisons and the performance record |
|
see what the code can do and why it is built the way it is |
|
the reference API and the release history |
Evidence at a glance¶
Upstream decks whose SFINCS v3 reference runtime clears a 10 s
reference-runtime-window, so process-launch and JIT-amortization noise does not
dominate the bars (Agreement with SFINCS v3).¶
The solver route decides the outcome: the structured direct route is faster than SFINCS v3 on 9 of 9 decks, the recycled Krylov route on 7 of 23, and memory is the weak axis. On the 744,610-unknown HSX pitch-angle-scattering case the warm solve takes 27.2 s against 229.5 s for SFINCS on two ranks (Performance and memory). Every number in these pages names the test, script or deck that produces it.