FieldSmith is a PyTorch-based framework for designing, optimizing, and evaluating permanent-magnet arrays. It provides differentiable magnetic-field models, reusable geometry and sampling components, gradient-based optimization workflows, and tools for checking designs under realistic physics and manufacturing tolerances.
The repository currently focuses on Halbach rings and multi-ring systems, the ROMA geometry, and open-cap/dome arrays for low-field MRI applications.
The software is not qualified for use as a medical product or as part thereof. Provided 'as is' without specific verification or validation.
- Build and optimize geometries such as Halbach rings, multi-ring, ROMA, and dome magnet arrays.
- Calculate differentiable fields with fast dipole or finite cuboid models.
- Run gradient-based optimization of magnet orientations, positions, and other parameters within the PyTorch framework.
- Evaluate field strength, peak-to-peak homogeneity, and RMS deviation.
- Run Monte Carlo studies of manufacturing tolerances.
- Move magnets within bounded boxes under a clearance penalty, and export a design as printable plates with seats, lids and fastening rails.
FieldSmith requires Python 3.11 or newer. Choose one of the mutually exclusive PyTorch backends when installing the environment.
Using pip install:
pip install fieldsmithFor development using uv:
git clone https://github.com/FraunhoferMEVIS/fieldsmith.git
cd fieldsmith
uv sync --extra cpuFor CUDA 12.8 instead, run:
uv sync --extra cu128Include the same extra in subsequent uv run commands, for example
uv run --extra cpu python scripts/example_system_optimization.py. The CPU
installation avoids the CUDA runtime packages. GPU execution is recommended for
dense three-dimensional or cuboid calculations; use double precision for results
around 1,000 ppm or below.
By default, uv also installs the dev dependency group for the repository's
paper scripts, notebooks, and tests. A pip install of the built package uses
the runtime requirements from [project] in pyproject.toml. To try those
runtime requirements from a clone, run uv sync --locked --no-dev --extra cpu.
| Workflow | Entry point |
|---|---|
| Generic Halbach system example | scripts/example_system_optimization.py |
| Single Halbach ring angle optimization | scripts/paper/run_fast_halbach_ring_optimisation.py |
| Three-stage small Halbach system optimization | scripts/paper/run_small_halbach_optimisation.py |
| ROMA multi-ring system angle optimization | scripts/paper/run_fast_roma_optimisation.py |
| Open-cap/dome system optimization | scripts/run_dome_optimisation.py |
| Printable plates, lids and rails | scripts/export_plates.py |
| Manufacturing Monte Carlo | scripts/run_monte_carlo_evaluation.py |
See docs/examples.md for command examples and the geometry verification workflow.
Every optimization reported in the paper can be rerun from this repository. The reproduction guide gives each command with its parameters, random seeds and expected numbers.
| Paper result | Entry point |
|---|---|
| Single-ring orientation benchmark | scripts/paper/run_fast_halbach_ring_optimisation.py |
| Ring-radius comparison of GA, DE and gradient descent | scripts/paper/lumc/ |
| Small Halbach demonstrator | scripts/paper/run_small_halbach_optimisation.py |
| ROMA after least-squares initialization, 321 ppm | scripts/paper/roma_from_lsq_seed.sh |
| ROMA refinement at the published seats, 332 ppm | scripts/paper/roma_refined_at_seats.sh |
| Cylinder opened along one side, 672 ppm | scripts/paper/opened_cylinder.sh |
| Dome-shaped head array, 980 ppm | scripts/paper/dome_head_array.sh |
Paper experiment entry points live in scripts/paper/, with the LUMC comparison
scripts in scripts/paper/lumc/. Run them from the repository root using the
commands in the reproduction guide. Shared optimization, input-building, and
stage helpers remain in scripts/ and scripts/stages/.
The four shell scripts in scripts/paper/ run without arguments and build their own inputs.
The four reported designs are in data/paper/ as .pt configurations.
Runs write to timestamped directories below logs/ unless an output directory is
specified. TrainLoop stores periodic MagnetConfiguration checkpoints as
configurations/epoch_<N>.pt, including when W&B logging is disabled. Specialized
workflows may also write a final configuration, summary JSON, CSV history, and
plots; the command prints the selected output directory. The four shell scripts in
scripts/paper/ write their stages and the final design to runs/<name>/.
- Architecture and component responsibilities
- Field models and their mathematical formulation
- Workflow examples
- Reference experiment reproduction
- Magnet configuration and checkpoint conventions
- Testing guide
The kernels preserve PyTorch gradients and support point chunking to control memory use. Field points can come from a Cartesian grid, a masked region of interest, or an arbitrary point cloud. Optimization objectives include exact and smoothed peak-to-peak homogeneity, RMS deviation, field-strength constraints, and collision penalties.
Run the tests from the repository root:
uv run --extra cpu pytestTo generate an HTML coverage report, run:
uv run --extra cpu pytest tests --cov=fieldsmith --cov-report=htmlFieldSmith software lies under the FRAUNHOFER »fieldsmith« LICENSE FOR SCIENTIFIC NON-COMMERCIAL RESEARCH PURPOSES.
The additional notice for the utilized software in docs/licences/ summarizes the:
- MIT License for the
scripts/paper/lumc/homogeneityOptimization.pyandscripts/paper/lumc/lumc_halbach.py. Corresponding repository: HalbachOptimization. - CERN Open Hardware Licence Version 2 for the files describing the ROMA arrangement in
data/osii_rc2.1/. Corresponding repository: OSII/rc/2.1
As soon as the paper is published the citing template of the software-related paper will be added here.
For support with regard to the FieldSmith software please contact:
- Kostiantyn Lavronenko: kostiantyn.lavronenko@mevis.fraunhofer.de
- Marian Frei: marian.frei@lfb.rwth-aachen.de
