The first end-to-end differentiable micromagnetic GPU code.

NeuralMag turns a plain-language problem description into a correct, runnable simulation. Fully differentiable physics on JAX & PyTorch, a SymPy form compiler, and machine-readable context so your AI assistant writes NeuralMag code that actually runs.

End-to-end
differentiable
JAX · TorchCPU / GPU
backends
npj 2025Peer-reviewed
method
Describe → Generate → Run

From a sentence to a solved simulation

You describe the physics. The assistant writes correct NeuralMag, runs it on the GPU, and hands back the dynamics — because the library ships the context an LLM needs to get it right.

01

Describe the problem

"Simulate the switching of a 500×125×3 nm permalloy thin film under a reversal field." Plain language — no boilerplate.

02

Generate the script

The assistant uses version-matched llms.txt to write a real NeuralMag script: mesh, material, field terms, LLG solver.

03

Run & differentiate

Execute on GPU, log the trajectory, plot the dynamics — and back-propagate through the whole solve for inverse design.

Why NeuralMag

A micromagnetic engine designed to be differentiated

Nodal finite-difference physics, expressed as energy functionals and compiled to fast vectorized kernels — gradients included, by construction.

End-to-end differentiable

Back-propagate through the full LLG time integration to solve inverse problems — materials, geometry and field design by gradient descent.

JAX & PyTorch · GPU

One model, two backends. Run on CPU or CUDA, pick NM_BACKEND and NM_DTYPE, and plug into your existing ML stack.

SymPy form compiler

Define physics as energy expressions; the form compiler auto-generates optimized, vectorized code — cached and reused across runs.

Full field-term library

Exchange, demagnetization, uniaxial & cubic anisotropy, interface & bulk DMI, interlayer exchange and external fields — composable out of the box.

Nodal FD discretization

Regular cuboid mesh with a field-interpolated (FIC) variant, validated against the µMAG standard problems.

Peer-reviewed & open

Published method in npj Computational Materials (2025), MIT-licensed, reproducible, with a runnable example for every feature.

AI-native by design

It ships the context your assistant needs

Most libraries leave the LLM guessing at the API. NeuralMag distributes its own machine-readable, version-matched documentation — so generated code matches the version you actually have installed.

  • Version-matched llms.txt — full machine-readable context following the llmstxt.org convention, regenerated per release.
  • One command to load itpython -m neuralmag prints the context straight into your assistant's window.
  • Agent-ready repoAGENTS.md and CLAUDE.md for agentic contributions and Claude Code.
Works with Claude Cursor ChatGPT Claude Code
load-context.sh
# pull NeuralMag's own LLM context
$ python -m neuralmag > neuralmag.txt

# or fetch the hosted, version-matched file
$ curl -O docs.neuralmag.org/llms.txt

# hand it to your assistant and ask:
#   "simulate µMAG standard problem 4
#    for a permalloy thin film"
# → correct, runnable NeuralMag.
Quickstart

Install once, simulate anywhere

Python ≥ 3.11. Choose a backend and you are ready to run — or let an assistant scaffold the first script for you.

install
# JAX backend (GPU-ready)
$ pip install "neuralmag[jax]"

# …or PyTorch
$ pip install "neuralmag[torch]"
standard_problem_4.py
import neuralmag as nm

mesh  = nm.Mesh([100,25,1], [5e-9,5e-9,3e-9])
state = nm.State(mesh)
state.material.Ms = 8e5      # permalloy
state.material.A  = 1.3e-11

nm.ExchangeField().register(state, "exchange")
nm.DemagField().register(state, "demag")

llg = nm.LLGSolver(state)
llg.relax()            # → s-state, then switch
Gallery

Real results, every one reproducible

From the classic switching benchmark to skyrmions, chiral textures and gradient-based topology optimization — each shipped as a runnable example.

npj Computational Materials · 11, 193 (2025)

NeuralMag: an open-source differentiable micromagnetic GPU code

Abert, Bruckner, Lang, Pathak, Holt & Fangohr. doi:10.1038/s41524-025-01688-1

Read the paper ↗
Start in one line

Describe a simulation. Let it write the rest.

Differentiable micromagnetics, GPU-accelerated, and ready for your AI assistant.