Skip to main content

Magnelio

CI License: LGPL v3

Magnelio is a Python library for full-wave 3D electromagnetic field simulation. Its standard workflow is broadband S-parameter extraction over waveguide ports on arbitrary 3D geometry; the workhorse solver is a time-domain Finite Integration Technique (FIT-TD) engine.

Electric field vectors in a two-pole dielectric resonator filter: two ceramic pucks stand in a metal housing, separated by a wall with a coupling window, with a probe pin at each end

Performance is a design goal, not an afterthought: no field update ever loops over cells in Python. The time-stepping kernels are fused and fully vectorised on three tiers — custom CUDA kernels on the GPU, Numba-compiled multi-threaded kernels on the CPU, and pure array stencils as the portable fallback — so a step runs at compiled-C speed, and models with hundreds of geometric primitives and correspondingly large grids stay tractable.

Features

  • FIT time-domain leapfrog solver on a structured non-uniform hexahedral grid, with conformal (sub-cell) material matrices
  • NumPy (CPU) and CuPy (CUDA GPU) backends — backend="auto" uses the GPU when available, with CUDA-graph stepping
  • Waveguide ports with exact discrete transparent boundaries (DTBC): TEM / QTEM / TE / TM / hybrid modes, multi-mode, declared on the model before meshing; lumped (RLC-backed) ports
  • Boundary conditions: PEC, PMC, CPML, periodic, and symmetry planes — declared once on the model, carried by the mesh
  • Materials: isotropic and diagonal-anisotropic, pole-residue dispersion for ε(ω)/μ(ω) with built-in vector fitting, conductor losses (perturbative or SIBC wall model), surface roughness (Hammerstad, Huray)
  • Geometry: CSG primitives + Boolean operators (a - b, a + b, a & b), exact curves and profiles, affine transforms, owned face/edge selection, and profile-based construction (loft, sweep, revolve, shell) via pythonocc-core; STEP/BREP and PCB fabrication-data import
  • Circuit elements embedded in the field solution: thin wires and lumped RLC networks
  • Field monitors (time/frequency domain, flux, wall loss), plane-wave source (TF/SF), 3D eigenmode solver
  • Interactive 3D viewer of geometry and mesh: a Jupyter widget with an axis-aligned cutting plane that opens every solid and shows the grid cells on the cut; the same call opens a browser view from a script, with a native-window fallback
  • Antennas: near-to-far-field transform recorded on a Huygens box the monitor places by itself, with image theory for ground planes and symmetry planes — directivity, gain, realized gain, radiated power and efficiency, drawn as polar cuts or a 3D pattern surface
  • Project store on disk: streamed results, bit-exact resume, post-processing on the stored data (HDF5); export_paraview() writes a ready-to-open ParaView session (coloured per-solid geometry, a cut with normalised field glyphs, the symmetry planes mirrored)
  • Interop: Touchstone (.sNp) export and scikit-rf adapter

Installation

Magnelio requires Python 3.11 or newer.

From conda-forge, which is the route to take:

conda install -c conda-forge magnelio

New to conda-forge? miniforge3 is the smallest way in; the Anaconda distribution works too.

JupyterLab is recommended for modelling and post-processing. Notebooks let you build and inspect geometry interactively, run simulations, and explore stored results and plots in the same document. Install it and the interactive viewer support in the same environment as Magnelio:

conda install -c conda-forge jupyterlab
python -m pip install "magnelio[jupyter]"
python -m jupyter lab

The jupyter extra supplies viewer widgets; JupyterLab itself is installed separately. It includes trame-pyvista, the standalone PyVista viewer integration. After installing or upgrading viewer packages in an existing notebook environment, restart its kernel before calling model.show(). Tutorials can be downloaded as notebooks from the documentation.

There is a PyPI package as well:

pip install magnelio

It installs and imports, but it cannot build a mesh from geometry: that needs pythonocc-core (the Python bindings to Open CASCADE Technology), which is published on conda-forge only. Since a model normally starts with geometry, pip is the fallback for environments where conda is not an option, not the way to run simulations.

The CUDA backend is optional on either route: install a cupy matching your CUDA version and backend="auto" picks the GPU up. Without it the solver runs on the CPU.

Time stepping defaults to single precision. Use precision="double" on the analysis when you need very low reflection floors; see the precision guide.

Working from a source checkout is described in CONTRIBUTING.md.

Quick Start

S-parameters of a WR-90 rectangular waveguide section:

import magnelio as mio
from magnelio import geo, ports

a, b, L = 22.86e-3, 10.16e-3, 40.0e-3   # WR-90 cross-section, length
f_max = 25.0e9

air = mio.Material.air()
model = mio.GeometryModel(background=air)   # walls: PEC by default
model.add(geo.Brick(origin=(0, 0, 0), size=(a, b, L), material=air))
model.add_port(ports.PortWaveguide(name="port1", plane="zmin", n_modes=3))
model.add_port(ports.PortWaveguide(name="port2", plane="zmax", n_modes=3))

mesh = mio.Mesh.from_geometry(
    model, mio.MeshControl(min_nodes_per_wavelength=15), f_max=f_max,
)

analysis = mio.AnalysisScatteringTD(mesh=mesh, f_max=f_max)
print(analysis.solve_ports()["port1"])   # mode table before the run

result = analysis.run(
    excited=[(p, m) for p in ("port1", "port2") for m in range(3)],
)
result.plot_s(("port2", "port1"), ("port1", "port1"))   # |S| over frequency
s21 = result.S("port2", "port1")         # complex S21 on result.f_axis
result.to_touchstone("wr90")             # -> wr90.s6p, 2 ports × 3 modes

Seventeen executable tutorials — from a first parallel-plate line to filters, antennas and plane-wave scattering — plus a Cassegrain reflector example live in examples/tutorials/; they are the source of the documentation's tutorial series.

Documentation

Read the release documentation or the development documentation. docs/ holds the Sphinx sources: tutorials, how-to guides, an API reference for the public surface (the core namespace and the domain namespaces, generated from the docstrings) and the technical method chapters — every numerical method with its literature source. Build it locally with:

pip install -e .[docs]
sphinx-build -b html docs docs/_build/html

Questions and feedback

Questions, ideas, things that were harder than they should have been, and models you built with Magnelio all go to GitHub Discussions — the lowest-threshold channel there is, and the one the author reads first. Nothing is too small: a confusing error message or a tutorial step that did not work as described is exactly the kind of feedback that shapes the next release.

Reporting bugs

Wrong results, crashes and refused valid input belong in the issue tracker. The bug form asks for the version, the backend and a short script — a script that reproduces the behaviour is what turns a report into a test case.

known-bugs.md is a different thing and not the place to file: it is the developer's record of investigated defects, with the measurements that pin them down, kept in the repository so a code comment can point at an entry.

Security-relevant findings take a private route — see SECURITY.md.

Development

Magnelio is being built in an AI-assisted workflow ("agentic coding"): the code is written in collaboration with LLM coding agents, with method selection, validation targets and reviews set by the author. Every numerical method is anchored to published literature in the documentation's method chapters, and the test and validation suite — not the authoring process — is the arbiter of correctness.

License

Magnelio is free software, released under the GNU Lesser General Public License v3.0 or later (LGPL-3.0-or-later) — see COPYING and COPYING.LESSER. You may use it from proprietary code; changes to magnelio itself must be published under the same license when distributed.

Metadata

Release files for magnelio 0.9.1

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

Source distribution (sdist)

Source distribution for magnelio 0.9.1
File Size Uploaded Provenance Actions
magnelio-0.9.1.tar.gz 4.4 MB With provenance Details for magnelio-0.9.1.tar.gz

Built distribution (wheel)

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

Total release size: 5.7 MB

Release files / magnelio-0.9.1.tar.gz

Download URL magnelio-0.9.1.tar.gz
Size 4.4 MB
Tags Source
SHA-256 checksum
How to use checksums
b12f8b37f26cadc231c8d1c7d31db9a04b05e545857aa4c46f0a4e71775ead31
BLAKE2b-256 checksum
How to use checksums
47b22a1bcd0e0713485fd1c4b9febd96107a5933ed6ec0fba8f1d840ef53aac0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / magnelio-0.9.1-py3-none-any.whl

Download URL magnelio-0.9.1-py3-none-any.whl
Size 1.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
6072ac4ce7af907383da1b27e78bfe72b85e30ff8d0f3cee0715cd5fd7d87e5c
BLAKE2b-256 checksum
How to use checksums
93b83b0dced9558176546fffb1bab04d5cf291c15aa0dd19d39ba1ddf8fbffca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Security for magnelio 0.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for magnelio-0.9.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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