Examples

This gallery is organized by what you want to do, not by source family. Every page pairs a short tutorial with runnable snippets, and links the matching scripts in the top-level examples/ folder — each script runs standalone and prints (or plots) its result.

Tip

New here? Start with the Quickstart, then come back and pick a task below. Enable jax.config.update("jax_enable_x64", True) before running anything you want to compare against Magpylib — see Precision.

Browse by task

🧱 Object API

Build sources, collections, and sensors; use motion paths and pixel grids.

🔢 Functional API

Call getB/getH/getJ/getM directly with descriptors and arrays.

⚙️ Force & torque

Differentiable force and torque between objects with getFT.

🎨 Visualization

Render geometry, polarization, and paths in 3D with show.

🎯 Optimization

Inverse design and geometry fitting with jax.grad.

🚀 Performance

Profiling, JIT, vmap, and large-coil workloads.

The examples/ folder

The scripts are grouped by theme on GitHub:

Folder

Contents

basics/

First field, collections & sensors, motion paths, custom sources, the source gallery.

shapes/

Triangle meshes, convex hulls, current sheets, superposition.

force/

Force intro, dipole–dipole, holding force.

visualization/

show scenes, magnet rendering, field streamplots.

applications/

Air coils, Helmholtz pairs, discrete Halbach arrays.

differentiable/

Inverse design, geometry optimization, field Jacobians, getFT optimization, jit/vmap.