Progressive framework: 1D diffusion → self-consistent tokamak equilibrium + transport
Pure PyTorch · validated at every stage
Srinath Vadlamani · SV Advanced Computing LLC
Phase 1a 1D diffusion ✓
Phase 1b coupled n,T ✓*
Phase 2a Grad-Shafranov ✓
Phase 2b cylindrical n ✓
Phase 3 tokamak n,T ✓
Phase 4 self-consistent ✓Approximate the PDE solution with a network uθ(x,t). PyTorch autograd gives exact derivatives, so the PDE residual becomes a loss term — no mesh, no discretization.
L = w_pde·‖R(x,t)‖²
+ w_bc ·‖u-g‖²
+ w_ic ·‖u-f‖²
R = ∂ₜu - D∂ₓₓu - SBake BCs/ICs into the network output so they hold exactly — zero BC/IC loss, optimizer has one objective.
ψ = r²(R²-r²)(Z²-z²)·NN
n = t(1-ρ²)·NNPick an exact solution, derive its source analytically, train against it. Exact reference, no solver.
verified: residual
→ 1e-16 (machine zero)The network is the solution field itself — a continuous, infinitely-differentiable surrogate uθ(x,t) for n, T, ψ …
u_θ : (x,t) ↦ field
physics IS the loss:
R[u_θ] = 0 everywhere
θ chosen so the surrogate
satisfies the PDE,
not so it matches samples ∂n/∂t = D ∂²n/∂x² + S_n
───── ────────── ───
density particle fueling /
evolves diffusion ionization
(3/2) ∂(nT)/∂t = χ ∂/∂x(n ∂T/∂x) + S_E
────────────── ─────────────── ───
thermal energy conductive heat heating
(3/2 nT) rate flux divergence power
(χ = diffusivity,
n weights the flux)
Nonlinearity lives in n·T and n·∂ₓT — the energy equation couples to density. Geometry (Phase 2b/3/4) adds a 1/r or 1/ρ factor from the divergence in curved coordinates.
(x, t) inputs (collocation point)
│
▼
envelope · MLP_θ hard constraint × network
│ e.g. n = n_e + x(1-x)t · NN
▼
n(x,t), T(x,t) continuous fields ◄─ the model
│
▼ torch.autograd (exact derivatives)
∂ₜn ∂ₓₓn ∂ₜ(nT) ∂ₓT ∂ₓₓT
│ [ + g(n,T) self-consistent geometry, Ph.4 ]
▼ assemble PDE residual
R_n = ∂ₜn − D∂ₓₓn − S_n R_E = 3/2 ∂ₜ(nT) − χ∂ₓ(n∂ₓT) − S_E
│
▼
L = ‖R_n‖² + ‖R_E‖² ──► Adam → L-BFGS ──► update θ
└────────────────── repeat until R → 0 ──────────────┘
z⁰ = [x, t]ᵀ ∈ ℝ² inputs (coordinates)
z¹ = tanh(W¹ z⁰ + b¹) ∈ ℝ¹²⁸ W¹ ∈ ℝ¹²⁸ˣ²
z² = tanh(W² z¹ + b²) ∈ ℝ¹²⁸ W² ∈ ℝ¹²⁸ˣ¹²⁸
⋮ 6 hidden layers, width 128 (tanh each)
z⁶ = tanh(W⁶ z⁵ + b⁶) ∈ ℝ¹²⁸
u = W⁷ z⁶ + b⁷ ∈ ℝ² W⁷ ∈ ℝ²ˣ¹²⁸ → (n,T)
every layer = an AFFINE map (Wz + b) followed by a bend (tanh)Dimension flow
2 → 128 → 128 → 128
→ 128 → 128 → 128 → 2
(x,t) features (n,T)Where the 83k numbers live
W¹: 128·2 +128 = 384
W²…W⁶: 5·(128²+128)=82 560
W⁷: 2·128 + 2 = 258
────────────────────────
θ total ≈ 83 202The model is these weights θ. Training shapes one continuous function ℝ²→ℝ² so it obeys the PDE.
one hidden unit j:
hⱼ = tanh( Σᵢ Wⱼᵢ zᵢ + bⱼ )
└ a soft step / bend,
oriented by row Wⱼ,
shifted by bⱼ
a layer = 128 bends in parallel
depth = bends composed on bends
→ arbitrarily curved
surfacesWhy the nonlinearity is essential
drop tanh ⇒ identity:
u = W⁷ W⁶ … W¹ z
= (one matrix) · z
→ only a flat plane
tanh is what lets the
stack BEND into a
PDE solution
tanh also has smooth derivatives of all orders — required to form ∂ₓₓu.
polynomial u(x) = Σ cₖ xᵏ basis fixed (monomials)
Fourier u(x) = Σ cₖ sin(kπx) basis fixed (sines)
finite elem. u(x) = Σ cₖ φₖ(x) basis fixed (hat fns)
───────────────────────────────────────────────────────────────
neural net u(x) = W⁷ tanh(… tanh(W¹x)) basis LEARNED & nonlinear
Classical methods fix a basis and solve a linear system for the coefficients c. A neural net lets the basis itself adapt — the weights reshape the building blocks and their amplitudes together.
input z = [x, t]ᵀ
⎡ 0.5 -0.3⎤ ⎡ 0.5x - 0.3t⎤
W¹ = ⎢ 0.1 0.8⎥ a = W¹z = ⎢ 0.1x + 0.8t⎥
⎣-0.6 0.2⎦ ⎣-0.6x + 0.2t⎦
h = tanh(a) ∈ ℝ³ W² = [1.2 -0.7 0.4]
u = W²h = 1.2·h₁ - 0.7·h₂ + 0.4·h₃ (scalar output)
e.g. at (x,t)=(1,0): a=[0.5,0.1,-0.6]ᵀ
h=[0.462,0.100,-0.537]ᵀ u = 0.270
u is an explicit closed-form expression in (x,t). The real network is this exact structure — just 128 wide and 6 deep.
chain rule through the toy net (tanh' = 1-h², tanh'' = -2h(1-h²)):
∂u/∂x = W² · [ (1-h²) ⊙ W¹₍:,1₎ ]
∂²u/∂x² = W² · [ -2h ⊙ (1-h²) ⊙ W¹₍:,1₎² ]
( W¹₍:,1₎ = first column = ∂a/∂x )
assemble the physics residual (1D diffusion):
R(x,t) = ∂ₜu − D ∂ₓₓu − S(x)
loss over N collocation points, minimise over the weights:
L(θ) = (1/N) Σᵢ R(xᵢ,tᵢ)² θ* = argmin_θ L(θ)
autograd evaluates exactly these expressions — we never derive them by hand. The residual is a closed-form function of θ.
| Phase | Problem | L2 error | Status |
|---|---|---|---|
| 1a | 1D slab diffusion | 6.4e-4 | ✅ PASS |
| 1b | Coupled n,T (consistent-IC fix) | n 2.7e-5 / T 2.0e-5 | ✅ PASS |
| 2a | Grad-Shafranov equilibrium | 1.1e-4 | ✅ PASS |
| 2b | Cylindrical transport | 4.6e-5 | ✅ PASS |
| 3 | Tokamak coupled n,T | n 6.7e-5 / T 4.8e-5 | ✅ PASS |
| 4 | Self-consistent eq+transport | n 7e-6 / T 3e-6 / g 2e-6 | ✅ PASS |
L2 relative error vs analytical / manufactured reference

∂n/∂t = D ∂²n/∂x² + S(x)
Density builds from zero to the steady parabolic profile balancing source against wall losses.
∂n/∂t = D ∂²n/∂x² + S_n
(3/2)∂(nT)/∂t = χ ∂ₓ(n ∂ₓT) + S_E
result: n 0.9% PASS
T 19.6% FAIL(An earlier note blamed a T_init corner conflict — the config showed T_init=0; the real cause is the degeneracy.)
Make it well-posed:
T: 19.6% → 0.002%
(≈ 10⁴× better)
n 2.7e-5 T 2.0e-5 PASS
ψrr − (1/r)ψr + ψzz = F
∂n/∂t = D(∂²n/∂r² + (1/r)∂n/∂r) + S
Parabolic profile builds to steady state as the source fills the column.
1.5D flux-surface transport (ASTRA/TRANSP model)

Pressure from transport sets the geometry; geometry feeds back into transport. Solved together:
g(ρ) = 1 + α·p(ρ)/p(0)
(computed inside the loss)
Equilibrium and transport are mutually consistent — the fixed point was found.
L2 quality labels
──────────────────────────
>50% untrained
20-50% coarse shape
5-20% structure emerging
2-5% near target
0.5-2% PASS
<0.5% EXCELLENTBake every enforceable constraint into the network; leave the optimizer one objective.
Manufactured solutions give exact references with verified sources — no solver noise.
float64 + CPU L-BFGS; MPS float32 silently stalls on nonlinear PDEs.
Phase 1b: define what you can measure (avoid p/n where n→0).
Five phases, one recipe: hard constraints + manufactured solutions + Adam→L-BFGS in float64.
1a 6.4e-4 2a 1.1e-4 2b 4.6e-5
3 6.7e-5 4 7e-6 (+ g 1.7e-6 self-consistency)
codeberg.org/srinathv/plasma-pinn