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.
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.
"Simulate the switching of a 500×125×3 nm permalloy thin film under a reversal field." Plain language — no boilerplate.
The assistant uses version-matched llms.txt
to write a real NeuralMag script: mesh, material, field terms, LLG solver.
Execute on GPU, log the trajectory, plot the dynamics — and back-propagate through the whole solve for inverse design.
Nodal finite-difference physics, expressed as energy functionals and compiled to fast vectorized kernels — gradients included, by construction.
Back-propagate through the full LLG time integration to solve inverse problems — materials, geometry and field design by gradient descent.
One model, two backends. Run on CPU or CUDA, pick NM_BACKEND and
NM_DTYPE, and plug into your existing ML stack.
Define physics as energy expressions; the form compiler auto-generates optimized, vectorized code — cached and reused across runs.
Exchange, demagnetization, uniaxial & cubic anisotropy, interface & bulk DMI, interlayer exchange and external fields — composable out of the box.
Regular cuboid mesh with a field-interpolated (FIC) variant, validated against the µMAG standard problems.
Published method in npj Computational Materials (2025), MIT-licensed, reproducible, with a runnable example for every feature.
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.
llms.txt — full machine-readable
context following the llmstxt.org convention, regenerated per release.python -m neuralmag
prints the context straight into your assistant's window.AGENTS.md and
CLAUDE.md for agentic contributions and Claude Code.# 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.
Python ≥ 3.11. Choose a backend and you are ready to run — or let an assistant scaffold the first script for you.
# JAX backend (GPU-ready) $ pip install "neuralmag[jax]" # …or PyTorch $ pip install "neuralmag[torch]"
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
From the classic switching benchmark to skyrmions, chiral textures and gradient-based topology optimization — each shipped as a runnable example.
Abert, Bruckner, Lang, Pathak, Holt & Fangohr. doi:10.1038/s41524-025-01688-1
Differentiable micromagnetics, GPU-accelerated, and ready for your AI assistant.