API Reference

Top-level package

Differentiable JAX-native magnetic field toolkit.

Precision follows your JAX configuration: arrays use JAX’s default float dtype (float32 unless you enable x64). For bit-level parity with magpylib (which is float64), enable double precision before using the library:

import jax
jax.config.update("jax_enable_x64", True)
import magpylib_jax as mpj

This package never mutates the global JAX config on import.

The public names (getB, getH, getJ, getM, getFT, Collection, Sensor, and the source classes) are documented in the sections below.

Functional API

Functional public interface and compatibility dispatch.

This module is a thin re-export facade. The implementation now lives in the magpylib_jax.fields package (api, prepare, engine and eager submodules). Every historical from magpylib_jax.functional import X and functional.X access keeps resolving through the re-exports below.

magpylib_jax.functional.getB(source, observers=None, *, position=(0.0, 0.0, 0.0), orientation=None, squeeze=True, sumup=False, pixel_agg=None, output='ndarray', in_out='auto', **kwargs)[source]

Return B-field in Tesla from source type strings or source objects.

Parameters:
  • source (str | object)

  • observers (Any | None)

  • position (Any)

  • orientation (Any | None)

  • squeeze (bool)

  • sumup (bool)

  • pixel_agg (str | None)

  • output (str)

  • in_out (str)

  • kwargs (Any)

Return type:

Array

magpylib_jax.functional.getFT(sources, targets, pivot='centroid', eps=1e-05, squeeze=True, meshreport=False, return_mesh=False)[source]

Differentiable magnetic force and torque on targets from sources.

Computes the force F (N) and torque T (N.m) exerted on each target by each source. Magnet targets use the exact field gradient from jax.jacfwd() (F = grad(m . B), T = m x B); current targets use the Laplace force (F = (I dL) x B, T = 0). SI units throughout.

Parameters:
  • sources (Source | Collection | list[Source | Collection]) – One or more magpylib_jax sources generating the field. A Collection is treated as a single source: its member fields are summed into one force on each target (matching magpylib).

  • targets (Target | list[Target] | Collection) –

    Objects the field acts on. Supported target types:

    • Dipole (magnet, single cell)

    • Sphere (magnet, single cell)

    • Cuboid (magnet, grid meshing via target.meshing; default 1 cell)

    • Cylinder (magnet, cylindrical meshing via target.meshing)

    • CylinderSegment (magnet, cylindrical-segment meshing via target.meshing)

    • Tetrahedron (magnet, barycentric meshing via target.meshing)

    • TriangularMesh (magnet, inside-mask grid meshing via target.meshing)

    • Circle (current, polygon meshing via target.meshing; default 100)

    • Polyline (current; target.meshing points, default 1 per segment)

    • TriangleStrip (current, triangle-bisection meshing via target.meshing)

    • TriangleSheet (current, triangle-bisection meshing via target.meshing)

    Cell centers and per-cell moments/current-vectors replicate magpylib’s target_meshing exactly, so results match magpy.getFT for a matching meshing. Any other target type raises NotImplementedError. Collection targets are flattened and their members summed into one target column.

  • pivot ('centroid' | None | array-like, default 'centroid') – Point about which the force contributes to the torque via (x_cell - pivot) x F. 'centroid' uses each target’s .centroid (falling back to .position). None omits the term. Arrays of shape (3,), (t, 3) or (t, p, 3) set explicit pivots.

  • eps (float, default 1e-5) – Accepted for API compatibility with magpy.getFT but unused: the magnet gradient is computed by autodiff, so the result is independent of eps and exact (an advantage over magpylib’s finite differences).

  • squeeze (bool, default True) – If True, remove length-1 dimensions from the outputs.

  • meshreport (bool, default False) – If True, print a short per-target report of the number of mesh cells used, then continue with the force/torque computation.

  • return_mesh (bool, default False) – If True, skip the force/torque computation and instead return the per-target meshes as a list of dictionaries (one per flattened target). Each dict has key "pts" (cell centers in the target local frame, shape (n, 3)) and either "moments" (magnet targets, cell magnetic moments in A.m^2) or "cvecs" (current targets, current vectors I . dL in A.m).

Returns:

(F, T) with shape (s, p, t, 3) before squeezing, where s is the number of sources, p the path length and t the number of targets. If return_mesh is True, a list of per-target mesh dictionaries is returned instead.

Return type:

tuple[jax.Array, jax.Array]

magpylib_jax.functional.getH(source, observers=None, *, position=(0.0, 0.0, 0.0), orientation=None, squeeze=True, sumup=False, pixel_agg=None, output='ndarray', in_out='auto', **kwargs)[source]

Return H-field in A/m from source type strings or source objects.

Parameters:
  • source (str | object)

  • observers (Any | None)

  • position (Any)

  • orientation (Any | None)

  • squeeze (bool)

  • sumup (bool)

  • pixel_agg (str | None)

  • output (str)

  • in_out (str)

  • kwargs (Any)

Return type:

Array

magpylib_jax.functional.getJ(source, observers=None, *, position=(0.0, 0.0, 0.0), orientation=None, squeeze=True, sumup=False, pixel_agg=None, output='ndarray', in_out='auto', **kwargs)[source]

Return J-field from source type strings or source objects.

Parameters:
  • source (str | object)

  • observers (Any | None)

  • position (Any)

  • orientation (Any | None)

  • squeeze (bool)

  • sumup (bool)

  • pixel_agg (str | None)

  • output (str)

  • in_out (str)

  • kwargs (Any)

Return type:

Array

magpylib_jax.functional.getM(source, observers=None, *, position=(0.0, 0.0, 0.0), orientation=None, squeeze=True, sumup=False, pixel_agg=None, output='ndarray', in_out='auto', **kwargs)[source]

Return M-field from source type strings or source objects.

Parameters:
  • source (str | object)

  • observers (Any | None)

  • position (Any)

  • orientation (Any | None)

  • squeeze (bool)

  • sumup (bool)

  • pixel_agg (str | None)

  • output (str)

  • in_out (str)

  • kwargs (Any)

Return type:

Array

Force and torque

JAX-native, autodiff magnetic force and torque (getFT).

This module implements getFT(), a differentiable analogue of magpylib’s magpy.getFT (magpylib 5.2.x). The force on a magnet cell is the gradient of the magnetic dipole energy m . B computed with jax.jacfwd() (exact autodiff, no finite differences), and the force on a current cell is the Laplace force (I dL) x B. Because the whole pipeline is built from the differentiable magpylib_jax.getB() plus jacfwd, getFT is itself differentiable and can be used directly inside optimisation loops.

Advantage over magpylib: magpylib evaluates the field gradient of magnet targets with symmetric finite differences of step eps; here the gradient is obtained by forward-mode autodiff, so the magnet result does not depend on eps and is exact to machine precision.

magpylib_jax.fields.force.getFT(sources, targets, pivot='centroid', eps=1e-05, squeeze=True, meshreport=False, return_mesh=False)[source]

Differentiable magnetic force and torque on targets from sources.

Computes the force F (N) and torque T (N.m) exerted on each target by each source. Magnet targets use the exact field gradient from jax.jacfwd() (F = grad(m . B), T = m x B); current targets use the Laplace force (F = (I dL) x B, T = 0). SI units throughout.

Parameters:
  • sources (Source | Collection | list[Source | Collection]) – One or more magpylib_jax sources generating the field. A Collection is treated as a single source: its member fields are summed into one force on each target (matching magpylib).

  • targets (Target | list[Target] | Collection) –

    Objects the field acts on. Supported target types:

    • Dipole (magnet, single cell)

    • Sphere (magnet, single cell)

    • Cuboid (magnet, grid meshing via target.meshing; default 1 cell)

    • Cylinder (magnet, cylindrical meshing via target.meshing)

    • CylinderSegment (magnet, cylindrical-segment meshing via target.meshing)

    • Tetrahedron (magnet, barycentric meshing via target.meshing)

    • TriangularMesh (magnet, inside-mask grid meshing via target.meshing)

    • Circle (current, polygon meshing via target.meshing; default 100)

    • Polyline (current; target.meshing points, default 1 per segment)

    • TriangleStrip (current, triangle-bisection meshing via target.meshing)

    • TriangleSheet (current, triangle-bisection meshing via target.meshing)

    Cell centers and per-cell moments/current-vectors replicate magpylib’s target_meshing exactly, so results match magpy.getFT for a matching meshing. Any other target type raises NotImplementedError. Collection targets are flattened and their members summed into one target column.

  • pivot ('centroid' | None | array-like, default 'centroid') – Point about which the force contributes to the torque via (x_cell - pivot) x F. 'centroid' uses each target’s .centroid (falling back to .position). None omits the term. Arrays of shape (3,), (t, 3) or (t, p, 3) set explicit pivots.

  • eps (float, default 1e-5) – Accepted for API compatibility with magpy.getFT but unused: the magnet gradient is computed by autodiff, so the result is independent of eps and exact (an advantage over magpylib’s finite differences).

  • squeeze (bool, default True) – If True, remove length-1 dimensions from the outputs.

  • meshreport (bool, default False) – If True, print a short per-target report of the number of mesh cells used, then continue with the force/torque computation.

  • return_mesh (bool, default False) – If True, skip the force/torque computation and instead return the per-target meshes as a list of dictionaries (one per flattened target). Each dict has key "pts" (cell centers in the target local frame, shape (n, 3)) and either "moments" (magnet targets, cell magnetic moments in A.m^2) or "cvecs" (current targets, current vectors I . dL in A.m).

Returns:

(F, T) with shape (s, p, t, 3) before squeezing, where s is the number of sources, p the path length and t the number of targets. If return_mesh is True, a list of per-target mesh dictionaries is returned instead.

Return type:

tuple[jax.Array, jax.Array]

Display

Matplotlib-backed 3D visualization for magpylib_jax objects.

The public entry point is show(), which renders any mix of source objects, Sensor instances and Collection containers into a single mpl_toolkits.mplot3d axes. Each object is drawn at its current pose (position + orientation); objects that carry a path (position length > 1) additionally show the path as a faint trailing line.

Matplotlib is imported lazily inside show() so that the rest of the package does not depend on it at import time; a helpful error is raised if it is missing. Surface resolutions are deliberately low to keep rendering (and the test suite) fast.

magpylib_jax.display.show(*objects, backend='matplotlib', ax=None, return_fig=False, style=None, **kwargs)[source]

Render magpylib_jax objects in a single 3D matplotlib axes.

Parameters:
  • *objects (Any) – Sources, Sensor instances and/or Collection containers to draw. At least one object is required.

  • backend (str) – Only "matplotlib" is supported.

  • ax (Any) – Existing 3D axes to draw on. If None a new figure/axes is created.

  • return_fig (bool) – When True return the matplotlib.figure.Figure (and never call plt.show()); useful for tests and headless rendering.

  • style (Any) – Optional mapping of display options. title sets the axes title.

  • **kwargs (Any) – Accepted for magpylib compatibility; title is honored.

Returns:

The figure when return_fig is True, otherwise None.

Return type:

matplotlib.figure.Figure or None

Object containers

Collection compatibility layer for mixed source/sensor containers.

class magpylib_jax.collection.Collection(*children, position=(0.0, 0.0, 0.0), orientation=None, override_parent=False, style_label=None, **_kwargs)[source]

Container for source and sensor objects with Magpylib-like behavior.

Parameters:
  • children (object)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • override_parent (bool)

  • style_label (str | None)

property children_all: list[object]

All descendants (sources, sensors, and collections), recursively.

property collections: list[Collection]

Direct child collections.

property collections_all: list[Collection]

All collection descendants, recursing into sub-collections.

property sensors_all: list[Sensor]

All sensor descendants, recursing into sub-collections.

property sources_all: list[BaseSource]

All source descendants, recursing into sub-collections.

Sensor compatibility layer.

class magpylib_jax.sensor.Sensor(pixel=None, position=(0.0, 0.0, 0.0), orientation=None, handedness='right', style=None, style_label=None, **kwargs)[source]

Sensor with one or multiple pixel locations.

Parameters:
  • pixel (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • handedness (str)

  • style_label (str | None)

Current sources

Differentiable circular current loop source object.

class magpylib_jax.current.circle.Circle(current=None, diameter=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

Circular current loop in the local xy-plane.

Parameters:
  • current (ArrayLike | None)

  • diameter (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

Differentiable polyline current source.

class magpylib_jax.current.polyline.Polyline(current=None, vertices=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

Piecewise-linear current path through vertices.

Parameters:
  • current (ArrayLike | None)

  • vertices (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

Differentiable triangular current-sheet source.

class magpylib_jax.current.triangle_sheet.TriangleSheet(vertices=None, faces=None, current_densities=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

Surface current densities flowing over indexed triangular faces.

Parameters:
  • vertices (ArrayLike | None)

  • faces (ArrayLike | None)

  • current_densities (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

Differentiable triangular-strip current source.

class magpylib_jax.current.triangle_strip.TriangleStrip(vertices=None, current=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

Current flowing through adjacent triangles defined by a vertex strip.

Parameters:
  • vertices (ArrayLike | None)

  • current (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

Magnet sources

Differentiable cuboid magnet source.

class magpylib_jax.magnet.cuboid.Cuboid(dimension=None, polarization=None, magnetization=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

Homogeneously polarized cuboid.

Parameters:
  • dimension (ArrayLike | None)

  • polarization (ArrayLike | None)

  • magnetization (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

Differentiable cylinder magnet source.

class magpylib_jax.magnet.cylinder.Cylinder(dimension=None, polarization=None, magnetization=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

Homogeneously polarized cylinder with diameter-height dimensions.

Parameters:
  • dimension (ArrayLike | None)

  • polarization (ArrayLike | None)

  • magnetization (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

Differentiable cylinder-segment magnet source.

class magpylib_jax.magnet.cylinder_segment.CylinderSegment(dimension=None, polarization=None, magnetization=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

Uniformly polarized cylinder segment (r1, r2, h, phi1_deg, phi2_deg).

Parameters:
  • dimension (ArrayLike | None)

  • polarization (ArrayLike | None)

  • magnetization (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

Differentiable sphere magnet source.

class magpylib_jax.magnet.sphere.Sphere(diameter=None, polarization=None, magnetization=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

Homogeneously polarized sphere with scalar diameter.

Parameters:
  • diameter (ArrayLike | None)

  • polarization (ArrayLike | None)

  • magnetization (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

Differentiable tetrahedron magnet source.

class magpylib_jax.magnet.tetrahedron.Tetrahedron(vertices=None, polarization=None, magnetization=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

Homogeneously polarized tetrahedron defined by four vertices.

Parameters:
  • vertices (ArrayLike | None)

  • polarization (ArrayLike | None)

  • magnetization (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

Differentiable triangular-mesh magnet source.

class magpylib_jax.magnet.triangular_mesh.TriangularMesh(vertices=None, faces=None, polarization=None, magnetization=None, position=(0.0, 0.0, 0.0), orientation=None, reorient_faces=True, check_open='warn', check_disconnected='warn', check_selfintersecting='warn', in_out='auto', style=None, style_label=None, **kwargs)[source]

Uniformly polarized magnet defined by mesh vertices and triangular faces.

Parameters:
  • vertices (ArrayLike | None)

  • faces (ArrayLike | None)

  • polarization (ArrayLike | None)

  • magnetization (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • reorient_faces (bool)

  • check_open (bool | str)

  • check_disconnected (bool | str)

  • check_selfintersecting (bool | str)

  • in_out (str)

  • style_label (str | None)

getB(*observers, in_out=None, squeeze=True, sumup=False, output='ndarray', pixel_agg=None)[source]

Magnetic flux density B in tesla at the given observers.

getH(*observers, in_out=None, squeeze=True, sumup=False, output='ndarray', pixel_agg=None)[source]

Magnetic field strength H in A/m at the given observers.

getJ(*observers, in_out=None, squeeze=True, sumup=False)[source]

Magnetic polarization J in tesla at the given observers.

getM(*observers, in_out=None, squeeze=True, sumup=False)[source]

Magnetization M in A/m at the given observers.

Miscellaneous sources

Differentiable dipole source object.

class magpylib_jax.misc.dipole.Dipole(moment=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

Magnetic dipole source with optional rigid transform.

Parameters:
  • moment (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

Differentiable triangular magnetic surface source.

class magpylib_jax.misc.triangle.Triangle(vertices=None, polarization=None, magnetization=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

Triangular magnetic surface with homogeneous polarization.

Parameters:
  • vertices (ArrayLike | None)

  • polarization (ArrayLike | None)

  • magnetization (ArrayLike | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

Custom source stub for compatibility with Magpylib collections.

class magpylib_jax.misc.custom.CustomSource(field_func=None, position=(0.0, 0.0, 0.0), orientation=None, style=None, style_label=None, **kwargs)[source]

User-defined source that can optionally supply a callable field function.

Parameters:
  • field_func (callable | None)

  • position (ArrayLike)

  • orientation (ArrayLike | None)

  • style_label (str | None)

getB(*observers, **_kwargs)[source]

Magnetic flux density B in tesla at the given observers.

Parameters:

observers (Any)

Return type:

Array

getH(observers, **kwargs)[source]

Magnetic field strength H in A/m at the given observers.

Parameters:

observers (Any)

Return type:

Array

getJ(observers, **kwargs)[source]

Magnetic polarization J in tesla at the given observers.

Parameters:

observers (Any)

Return type:

Array

getM(observers, **kwargs)[source]

Magnetization M in A/m at the given observers.

Parameters:

observers (Any)

Return type:

Array

Core internals

Geometry helpers for frame transforms and coordinate conversions.

magpylib_jax.core.geometry.broadcast_pose(*, position=(0.0, 0.0, 0.0), orientation=None)[source]

Broadcast position/orientation path lengths with singleton expansion.

Parameters:
  • position (Any)

  • orientation (Any | None)

Return type:

tuple[Array, Array]

magpylib_jax.core.geometry.cart_to_cyl(observers)[source]

Convert Cartesian coordinates to cylindrical coordinates.

Parameters:

observers (Array)

Return type:

tuple[Array, Array, Array]

magpylib_jax.core.geometry.cyl_field_to_cart(phi, hr, hphi_or_hz, hz=None)[source]

Convert cylindrical field components to Cartesian field vectors.

Backward-compatible call forms: - cyl_field_to_cart(phi, hr, hz) assumes Hphi=0 - cyl_field_to_cart(phi, hr, hphi, hz) uses full cylindrical vector

Parameters:
  • phi (Array)

  • hr (Array)

  • hphi_or_hz (Array)

  • hz (Array | None)

Return type:

Array

magpylib_jax.core.geometry.ensure_observers(observers)[source]

Normalize observers to a rank-2 array of shape (n, 3).

Parameters:

observers (Any)

Return type:

Array

magpylib_jax.core.geometry.normalize_orientation(orientation)[source]

Return a 3x3 rotation matrix.

Parameters:

orientation (Any | None)

Return type:

Array

magpylib_jax.core.geometry.normalize_orientations(orientation=None)[source]

Return orientations as shape (p, 3, 3).

Parameters:

orientation (Any | None)

Return type:

Array

magpylib_jax.core.geometry.normalize_positions(position=(0.0, 0.0, 0.0))[source]

Return positions as shape (p, 3).

Parameters:

position (Any)

Return type:

Array

magpylib_jax.core.geometry.to_global_field(field_local, rotation_matrix)[source]

Map local-frame vectors back to global coordinates.

Parameters:
  • field_local (Array)

  • rotation_matrix (Array)

Return type:

Array

magpylib_jax.core.geometry.to_local_coordinates(observers, *, position=(0.0, 0.0, 0.0), orientation=None)[source]

Map global observer coordinates into source-local frame.

Parameters:
  • observers (Any)

  • position (Any)

  • orientation (Any | None)

Return type:

tuple[Array, Array]

JAX-native differentiable magnetic field kernels.

This package splits the former kernels.py and kernels_extended.py modules into cohesive per-source-family submodules. Every public (and select private) name previously importable from magpylib_jax.core.kernels is re-exported here so existing imports keep resolving unchanged.

magpylib_jax.core.kernels.current_circle_bfield(observers, diameter, current)[source]

B-field of a current circle (Tesla).

Parameters:
  • observers (Any)

  • diameter (Any)

  • current (Any)

Return type:

Array

magpylib_jax.core.kernels.current_circle_bfield_jit(observers, diameter, current)[source]

JIT-specialized circle B-field for fixed observer counts.

Parameters:
  • observers (Any)

  • diameter (Any)

  • current (Any)

Return type:

Array

magpylib_jax.core.kernels.current_circle_hfield(observers, diameter, current, *, singular_tol=1e-15)[source]

H-field of circular current loops centered at the origin in the xy plane.

Parameters:
  • observers (Any)

  • diameter (Any)

  • current (Any)

  • singular_tol (float)

Return type:

Array

magpylib_jax.core.kernels.current_polyline_bfield_jit(observers, segments_start, segments_end, currents)[source]

JIT-specialized polyline B-field for fixed observer + segment counts.

Parameters:
  • observers (Any)

  • segments_start (Any)

  • segments_end (Any)

  • currents (Any)

Return type:

Array

magpylib_jax.core.kernels.current_polyline_bfield_masked(observers, segments_start, segments_end, currents, segment_mask)[source]

B-field of current segments with segment masking.

Parameters:
  • observers (Any)

  • segments_start (Any)

  • segments_end (Any)

  • currents (Any)

  • segment_mask (Any)

Return type:

Array

magpylib_jax.core.kernels.current_polyline_hfield(observers, segments_start, segments_end, currents)[source]

H-field of straight current segments.

Parameters:
  • observers (Any)

  • segments_start (Any)

  • segments_end (Any)

  • currents (Any)

Return type:

Array

magpylib_jax.core.kernels.current_trisheet_bfield_jit(observers, vertices, faces, current_densities)[source]

JIT-specialized triangle sheet B-field for fixed observer counts.

Parameters:
  • observers (Any)

  • vertices (Any)

  • faces (Any)

  • current_densities (Any)

Return type:

Array

magpylib_jax.core.kernels.current_trisheet_bfield_masked(observers, triangles, current_densities, face_mask)[source]

B-field of triangle sheet with face masking.

Parameters:
  • observers (Any)

  • triangles (Any)

  • current_densities (Any)

  • face_mask (Any)

Return type:

Array

magpylib_jax.core.kernels.current_tristrip_bfield_jit(observers, vertices, current)[source]

JIT-specialized triangle strip B-field for fixed observer counts.

Parameters:
  • observers (Any)

  • vertices (Any)

  • current (Any)

Return type:

Array

magpylib_jax.core.kernels.dipole_bfield(observers, moments)[source]

B-field of a dipole (Tesla).

Parameters:
  • observers (Any)

  • moments (Any)

Return type:

Array

magpylib_jax.core.kernels.dipole_hfield(observers, moments)[source]

H-field of dipole moments located at the origin.

Parameters:
  • observers (Any)

  • moments (Any)

Return type:

Array

magpylib_jax.core.kernels.magnet_cuboid_bfield(observers, dimensions, polarizations)[source]

B-field of homogeneously polarized cuboids centered at the origin.

Parameters:
  • observers (Any)

  • dimensions (Any)

  • polarizations (Any)

Return type:

Array

magpylib_jax.core.kernels.magnet_cuboid_hfield(observers, dimensions, polarizations)[source]

H-field for homogeneously polarized cuboids.

Parameters:
  • observers (Any)

  • dimensions (Any)

  • polarizations (Any)

Return type:

Array

magpylib_jax.core.kernels.magnet_cuboid_jfield(observers, dimensions, polarizations)[source]

J-field for homogeneously polarized cuboids.

Parameters:
  • observers (Any)

  • dimensions (Any)

  • polarizations (Any)

Return type:

Array

magpylib_jax.core.kernels.magnet_cuboid_mfield(observers, dimensions, polarizations)[source]

M-field for homogeneously polarized cuboids.

Parameters:
  • observers (Any)

  • dimensions (Any)

  • polarizations (Any)

Return type:

Array

magpylib_jax.core.kernels.magnet_cylinder_axial_bfield(z0, r, z)[source]

B-field in cylindrical coordinates for axially polarized cylinders.

Parameters:
  • z0 (Array)

  • r (Array)

  • z (Array)

Return type:

Array

magpylib_jax.core.kernels.magnet_cylinder_bfield(observers, dimensions, polarizations)[source]

B-field of homogeneously polarized cylinders centered at the origin.

Parameters:
  • observers (Any)

  • dimensions (Any)

  • polarizations (Any)

Return type:

Array

magpylib_jax.core.kernels.magnet_cylinder_diametral_hfield(z0, r, z, phi)[source]

H-field in cylindrical coordinates for diametral polarization.

Parameters:
  • z0 (Array)

  • r (Array)

  • z (Array)

  • phi (Array)

Return type:

Array

magpylib_jax.core.kernels.magnet_cylinder_hfield(observers, dimensions, polarizations)[source]

H-field of homogeneously polarized cylinders centered at the origin.

Parameters:
  • observers (Any)

  • dimensions (Any)

  • polarizations (Any)

Return type:

Array

magpylib_jax.core.kernels.magnet_cylinder_jfield(observers, dimensions, polarizations)[source]

J-field for homogeneously polarized cylinders.

Parameters:
  • observers (Any)

  • dimensions (Any)

  • polarizations (Any)

Return type:

Array

magpylib_jax.core.kernels.magnet_cylinder_mfield(observers, dimensions, polarizations)[source]

M-field for homogeneously polarized cylinders.

Parameters:
  • observers (Any)

  • dimensions (Any)

  • polarizations (Any)

Return type:

Array

magpylib_jax.core.kernels.magnet_cylinder_segment_bfield_jit(observers, dimensions, polarizations, in_out='auto')[source]

JIT-specialized cylinder-segment B-field for fixed observer counts.

Parameters:
  • observers (Any)

  • dimensions (Any)

  • polarizations (Any)

  • in_out (str)

Return type:

Array

magpylib_jax.core.kernels.magnet_cylinder_segment_bfield_jit_faces(observers, dimensions, polarizations, in_out='auto')[source]

JIT-specialized cylinder-segment B-field for fixed observer + face counts.

Parameters:
  • observers (Any)

  • dimensions (Any)

  • polarizations (Any)

  • in_out (str)

Return type:

Array

magpylib_jax.core.kernels.magnet_sphere_bfield(observers, diameters, polarizations)[source]

B-field of homogeneously polarized spheres centered at the origin.

Parameters:
  • observers (Any)

  • diameters (Any)

  • polarizations (Any)

Return type:

Array

magpylib_jax.core.kernels.magnet_trimesh_bfield(observers, mesh, polarizations, in_out='auto')[source]

B-field of uniformly polarized closed triangular meshes.

Parameters:
  • observers (Any)

  • mesh (Any)

  • polarizations (Any)

  • in_out (str)

Return type:

Array

magpylib_jax.core.kernels.magnet_trimesh_bfield_jit(observers, mesh, polarizations, in_out='auto')[source]

JIT-specialized triangular mesh B-field for fixed observer counts.

Parameters:
  • observers (Any)

  • mesh (Any)

  • polarizations (Any)

  • in_out (str)

Return type:

Array

magpylib_jax.core.kernels.magnet_trimesh_bfield_jit_faces(observers, mesh, polarizations, in_out='auto')[source]

JIT-specialized triangular mesh B-field for fixed observer + face counts.

Parameters:
  • observers (Any)

  • mesh (Any)

  • polarizations (Any)

  • in_out (str)

Return type:

Array

magpylib_jax.core.kernels.magnet_trimesh_bfield_jit_faces_precomp(observers, mesh, polarizations, nvec, L, l1, l2, in_out='auto')[source]

JIT-specialized triangular mesh B-field using precomputed geometry.

Parameters:
  • observers (Any)

  • mesh (Any)

  • polarizations (Any)

  • nvec (Any)

  • L (Any)

  • l1 (Any)

  • l2 (Any)

  • in_out (str)

Return type:

Array

magpylib_jax.core.kernels.magnet_trimesh_bfield_precomp_masked(observers, mesh, polarizations, nvec, L, l1, l2, face_mask, in_out_flag)[source]

B-field of triangular mesh using precomputed geometry with face masking.

Parameters:
  • observers (Any)

  • mesh (Any)

  • polarizations (Any)

  • nvec (Any)

  • L (Any)

  • l1 (Any)

  • l2 (Any)

  • face_mask (Any)

  • in_out_flag (int)

Return type:

Array

magpylib_jax.core.kernels.precompute_cylinder_segment_geometry(dimension, *, n_phi=96, n_r=1, n_z=1)[source]

Precompute cylinder segment mesh + geometry terms.

Parameters:
  • dimension (Any)

  • n_phi (int)

  • n_r (int)

  • n_z (int)

Return type:

tuple[Array, Array, Array, Array, Array]

magpylib_jax.core.kernels.precompute_trimesh_geometry(mesh)[source]

Precompute triangle mesh geometry terms for reuse.

Parameters:

mesh (Any)

Return type:

tuple[Array, Array, Array, Array, Array]

magpylib_jax.core.kernels.tetrahedron_bfield_jit(observers, vertices, polarizations, in_out='auto')[source]

JIT-specialized tetrahedron B-field for fixed observer counts.

Parameters:
  • observers (Any)

  • vertices (Any)

  • polarizations (Any)

  • in_out (str)

Return type:

Array

magpylib_jax.core.kernels.triangle_bfield(observers, vertices, polarizations)[source]

B-field of magnetically charged triangular surfaces.

Parameters:
  • observers (Any)

  • vertices (Any)

  • polarizations (Any)

Return type:

Array

magpylib_jax.core.kernels.triangle_bfield_jit(observers, vertices, polarizations)[source]

JIT-specialized triangle B-field for fixed observer counts.

Parameters:
  • observers (Any)

  • vertices (Any)

  • polarizations (Any)

Return type:

Array

Field engine

Public field API, config constants and low-level helpers.

This module is a leaf of the fields package: it depends only on the standard library and JAX so that every other fields submodule can import its constants and helpers without creating an import cycle. The public getB/getH/getJ/getM entry points and the _compute_field router lazy-import the heavier engine/eager submodules inside their bodies.

magpylib_jax.fields.api.getB(source, observers=None, *, position=(0.0, 0.0, 0.0), orientation=None, squeeze=True, sumup=False, pixel_agg=None, output='ndarray', in_out='auto', **kwargs)[source]

Return B-field in Tesla from source type strings or source objects.

Parameters:
  • source (str | object)

  • observers (Any | None)

  • position (Any)

  • orientation (Any | None)

  • squeeze (bool)

  • sumup (bool)

  • pixel_agg (str | None)

  • output (str)

  • in_out (str)

  • kwargs (Any)

Return type:

Array

magpylib_jax.fields.api.getH(source, observers=None, *, position=(0.0, 0.0, 0.0), orientation=None, squeeze=True, sumup=False, pixel_agg=None, output='ndarray', in_out='auto', **kwargs)[source]

Return H-field in A/m from source type strings or source objects.

Parameters:
  • source (str | object)

  • observers (Any | None)

  • position (Any)

  • orientation (Any | None)

  • squeeze (bool)

  • sumup (bool)

  • pixel_agg (str | None)

  • output (str)

  • in_out (str)

  • kwargs (Any)

Return type:

Array

magpylib_jax.fields.api.getJ(source, observers=None, *, position=(0.0, 0.0, 0.0), orientation=None, squeeze=True, sumup=False, pixel_agg=None, output='ndarray', in_out='auto', **kwargs)[source]

Return J-field from source type strings or source objects.

Parameters:
  • source (str | object)

  • observers (Any | None)

  • position (Any)

  • orientation (Any | None)

  • squeeze (bool)

  • sumup (bool)

  • pixel_agg (str | None)

  • output (str)

  • in_out (str)

  • kwargs (Any)

Return type:

Array

magpylib_jax.fields.api.getM(source, observers=None, *, position=(0.0, 0.0, 0.0), orientation=None, squeeze=True, sumup=False, pixel_agg=None, output='ndarray', in_out='auto', **kwargs)[source]

Return M-field from source type strings or source objects.

Parameters:
  • source (str | object)

  • observers (Any | None)

  • position (Any)

  • orientation (Any | None)

  • squeeze (bool)

  • sumup (bool)

  • pixel_agg (str | None)

  • output (str)

  • in_out (str)

  • kwargs (Any)

Return type:

Array