Skip to main content

NeuralMag

Built to be used with AI assistants. NeuralMag is fully differentiable micromagnetics (JAX/PyTorch) that ships its own machine-readable, version-matched context, so assistants like Claude, Cursor or ChatGPT can help you write correct NeuralMag code — just run python -m neuralmag. See NeuralMag & AI assistants.

NeuralMag is a micromagnetic simulation software using the nodal finite-difference discretization scheme, designed specifically with inverse problems in mind. It uses either JAX or PyTorch as a numerical backend for tensor operations and automatic differentiation, enabling computations on both CPU and GPU systems. At the moment NeuralMag implements the most common micromagnetic effective-field contributions

  • external field
  • exchange field
  • demagnetization field
  • uniaxial/cubic anisotropy
  • DMI (interface and bulk)
  • interlayer exchange

as well as a differentiable time-domain solver for the Landau-Lifshitz-Gilbert equation.

NeuralMag is designed in a modular fashion resulting in a very high flexibility for the problem definition. For instance, all simulation parameters (e.g. material parameters) can be functions of space, time or any other simulation parameter.

At the heart of NeuralMag is a form compiler powered by SymPy that translates arbitrary functionals and linear weak forms into vectorized PyTorch or JAX code. This allows to easily add new effective-field contributions by simply stating the corresponding energy as a sympy expression.

NeuralMag & AI assistants

We treat AI assistants as first-class users of NeuralMag — both for using it and for contributing to it.

Using NeuralMag with an AI assistant. Because NeuralMag is specialized, a general LLM often guesses its API wrong. NeuralMag ships its own machine-readable, version-matched context so your assistant stays accurate:

  • Run python -m neuralmag (or call neuralmag.llm_context() in Python) and hand the output to your assistant. You get a concise guide — design philosophy, configuration, a canonical workflow, multi-domain materials, inverse-problem patterns and common pitfalls — prefixed with live facts about your install (backend, dtype, available field terms), so it never describes an API you don't have.
  • On the web, the same content is published as llms.txt / llms-full.txt, following the llms.txt convention — point a chat assistant at the URL.
  • Tip: in your own project, add a CLAUDE.md or AGENTS.md with a line like "When using neuralmag, run python -m neuralmag to load its API guide" to make this automatic.

Contributing to NeuralMag with an AI assistant. AGENTS.md is the checked-in, tool-neutral project guide (architecture, discretization schemes, backends, design principles), written to be read by AI coding agents as well as humans.

  • Cursor and most agentic IDEs read AGENTS.md from the repo root directly.

  • Claude Code reads a CLAUDE.md. The repo doesn't ship one (keep it personal), but setup is one line — create CLAUDE.md in the repo root that imports the shared guide:

    @AGENTS.md
    

    Claude Code then loads AGENTS.md into context automatically.

The same information is in the documentation: Using NeuralMag with AI assistants.

Documentation

The documentation of NeuralMag including a reference to all classes as well as several examples can found here.

NeuralMag in the cloud

Experience NeuralMag without installing it locally by accessing it directly in the cloud via Binder. Simply click the badge to get started: Binder

Using NeuralMag on Binder allows you to experience its features, without the hassle of setting up your local environment. It provides a quick and accessible way to test and experiment with the software from any device with a web browser. It is important to note that the Binder-hosted version is a CPU-only JAX implementation, and it will run slower than a local installation. Sessions are temporary and may time out after a period of inactivity, and any files created or modified during your session will not be saved. To avoid losing your work, please remember to download any files you create or edit before your session ends.

Download and Install

NeuralMag is a Python package and requires Python >=3.8 (>=3.10 for JAX backend). To install the latest version with pip either run

pip install "neuralmag[jax]"

to install NeuralMag with JAX as a backend or

pip install "neuralmag[torch]"

to install NeuralMag with PyTorch as a backend. You can also install NeuralMag with both backends and choose the backend at runtime.

How to cite

If you use NeuralMag in scientific work, please cite the accompanying paper:

C. Abert, F. Bruckner, A. Voronov, M. Lang, S. A. Pathak, S. Holt, R. Kraft, R. Allayarov, P. Flauger, S. Koraltan, T. Schrefl, A. Chumak, H. Fangohr, D. Suess, "NeuralMag: an open-source nodal finite-difference code for inverse micromagnetics", npj Comput. Mater. 11, 193 (2025). doi:10.1038/s41524-025-01688-1

BibTeX:

@article{Abert2025NeuralMag,
  author  = {Abert, Claas and Bruckner, Florian and Voronov, Andrii and
             Lang, Martin and Pathak, Swapneel Amit and Holt, Sam and
             Kraft, Roman and Allayarov, Rustam and Flauger, Paul and
             Koraltan, Sabri and Schrefl, Thomas and Chumak, Andrii and
             Fangohr, Hans and Suess, Dieter},
  title   = {{NeuralMag}: an open-source nodal finite-difference code for
             inverse micromagnetics},
  journal = {npj Computational Materials},
  volume  = {11},
  pages   = {193},
  year    = {2025},
  doi     = {10.1038/s41524-025-01688-1},
}

Contribute

Thank you for considering contributing to our project! We welcome any contributions, whether they are in the form of bug fixes, feature enhancements, documentation improvements, or any other kind of enhancement. NeuralMag is licensed under the MIT License. By contributing to this project, you agree to license your contributions under the terms of the MIT License.

See CONTRIBUTING.md for how to set up a development environment and run the tests. For an overview of the architecture, discretization schemes, backends, and the design principles that new code should follow, see AGENTS.md; for using it with AI coding assistants, see NeuralMag & AI assistants above.

Release files for neuralmag 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for neuralmag 1.0.0
File Size Uploaded
neuralmag-1.0.0.tar.gz 87.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for neuralmag 1.0.0
File Interpreter ABI Platform
neuralmag-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 197.5 kB

Release files / neuralmag-1.0.0.tar.gz

Download URL neuralmag-1.0.0.tar.gz
Size 87.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8a1b0669c5cdca77d37a2213ab8026392333f5efd6eec49f598d1153d5c4d60d
BLAKE2b-256 checksum
How to use checksums
37bcbf37b2a84e18153fa022dd91bec9906df6bdb397a44e96322591b09f8603
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / neuralmag-1.0.0-py3-none-any.whl

Download URL neuralmag-1.0.0-py3-none-any.whl
Size 110.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9fba4ba0dd61227a700f3b383437b505a65e64ec3f1b4f0eb73083a8b7315a7
BLAKE2b-256 checksum
How to use checksums
59957f36d155fc38f08184b9987d016b5674291cf68a2069a31226387aa04ae8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page