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.

Install Miniconda if Conda is not available yet. Current Conda includes a fast dependency solver; no separate package manager is needed.

Notebooks are recommended for modelling and post-processing. They let you build and inspect geometry interactively, run simulations, and explore stored results and plots in the same document. Create a fresh environment from conda-forge and start Notebook:

conda create -n mioenv --override-channels -c conda-forge magnelio notebook
conda activate mioenv
python -m notebook

The Conda package includes geometry support and the interactive viewer, including its notebook widgets. No Pip step or manual widget setup is needed with the dependency-complete package. Select the Python kernel from mioenv when creating a notebook. Tutorials can be downloaded as notebooks from the documentation.

Viewer dependencies are included from Conda package version 0.9.2 onward. For an existing environment, update Magnelio before starting the notebook.

Prefer JupyterLab? Replace notebook with jupyterlab in the create command and start it with python -m jupyterlab. For scripts without a notebook application, omit notebook; model.show() opens the viewer in a browser. After upgrading viewer packages, restart the notebook server and kernel.

There is a PyPI package as well:

python -m pip install "magnelio[jupyter]"

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. With Conda, install cupy and a cuda-version supported by your driver, for example conda install --override-channels -c conda-forge cupy "cuda-version=12". Then 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.2

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.2
File Size Uploaded Provenance Actions
magnelio-0.9.2.tar.gz 4.4 MB With provenance Details for magnelio-0.9.2.tar.gz

Built distribution (wheel)

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

Total release size: 5.7 MB

Release files / magnelio-0.9.2.tar.gz

Download URL magnelio-0.9.2.tar.gz
Size 4.4 MB
Tags Source
SHA-256 checksum
How to use checksums
d0822258bea3f9aa5fbddb1efd7f8dbe2b8ff2829dcf54fa55b54bcd1c17cd3a
BLAKE2b-256 checksum
How to use checksums
8c24fc7e1b2f11b2b1e20d07e72408d94155f008aaa544454e23ee2057b63ff7
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 Nov 1, 2026.

Transparency log

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

Download URL magnelio-0.9.2-py3-none-any.whl
Size 1.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
ba5710c28e2ba8e28074a44cf5cf9bcc3e7dd41ea306d57255e9c6f835d36684
BLAKE2b-256 checksum
How to use checksums
0d98b5e3bb69d84794a1730b0b68f36b5ad21c387eff13c0282fcd1bf6ea6970
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 Nov 1, 2026.

Transparency log

Security for magnelio 0.9.2

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.2.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 Nov 1, 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