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

particle_flux_m2_s, heat_flux_W_m2

Outputs

bootstrap current and parallel flow

parallel_current_A_T_m2, FSABjHat

Drives, RHS modes and moments

ambipolar \(E_r\) and every root branch

ambipolar_root_kV_m, ambipolar_root_type

Radial electric field and ambipolarity

thermal transport matrix (RHSMode 2)

transportMatrix

Drives, RHS modes and moments

monoenergetic \(D_{11}^*\), \(D_{31}^*\), \(D_{33}^*\) (RHSMode 3)

transportMatrix

Reduced models

in-surface potential \(\Phi_1\) and impurity fluxes

Phi1Hat, per-species fluxes

\Phi_1, quasineutrality and impurities

derivatives of any of the above

jax.grad, jax.jacrev

Differentiation

How the documentation is organized

Section

Read it to

Installation

install DKX and check the environment

Learn DKX: the tutorial track

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

User guide

look up every input field, output array, CLI command and Python entry point

How DKX works

see the pipeline from a case to a result, module by module

Physics

read the equations, collision operators, drives, electric field, \(\Phi_1\) and geometry models

Numerics

understand the discretization, the solver routes, preconditioners, factor reuse and adjoints

Benchmarks

check the analytic limits, the SFINCS, MONKES and YANCC comparisons and the performance record

Features, Design decisions

see what the code can do and why it is built the way it is

API reference, Changelog

the reference API and the release history

Evidence at a glance

DKX against SFINCS v3 on the upstream example decks

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.