Differentiable finite-element electromagnetics for RF, microwave, mm-wave and superconducting quantum devices. gfem runs on NGSolve for discretization and JAX for everything differentiable.
gfem 0.1.0 is the first release. The API may still change before 1.0.
Install
pip install gfem
Each optional extra goes in brackets after gfem:
pip install "gfem[mkl]" # a faster CPU direct solver, MKL PARDISO (Linux x86_64, Windows); read the licence first
pip install "gfem[cuda12]" # the direct solver on an NVIDIA GPU, cuDSS (Linux x86_64, Windows); cuda13 for CUDA 13
pip install "gfem[xarray]" # results as xarray datasets (.to_xarray())
pip install "gfem[viz]" # fields as PyVista grids (.to_pyvista())
pip install "gfem[mpi]" # one solve across MPI ranks (Linux x86_64; Open MPI from your machine)
Supported platforms: Linux x86_64 (glibc >= 2.28), macOS arm64 and Windows x86_64, Python >= 3.12.
Importing gfem turns on JAX double precision (jax_enable_x64), which every gfem solve requires.
A first solve
A parallel-plate line 40 mm long, 6 mm wide and 1 mm high joins two lumped ports matched to it. Its middle 20 mm is filled with a ceramic of relative permittivity 10. How much of the incident power reaches port 2 at 2, 5 and 8 GHz?
import urllib.request
import gfem
url = "https://raw.githubusercontent.com/benvial/gfem/main/docs/tutorials/data/line.msh"
urllib.request.urlretrieve(url, "line.msh")
mesh = gfem.Mesh.from_gmsh("line.msh", length_unit="mm")
z_line = 376.73 / 6 # ohm: the 6 mm wide, 1 mm high parallel-plate line in air
model = gfem.Model(
mesh,
materials={"feed": gfem.Material(), "design": gfem.Material(eps_r=10.0)},
boundaries=[gfem.PEC("bottom"), gfem.PEC("top")],
ports=[
gfem.LumpedPort("p1", "port1", "+z", impedance=z_line),
gfem.LumpedPort("p2", "port2", "+z", impedance=z_line),
],
)
result = gfem.solve(model, gfem.Driven(frequency=(2e9, 5e9, 8e9), excite="p1"))
print(abs(result.s["p2", "p1"])) # |S21| at 2, 5 and 8 GHz
[0.83062238 0.90133217 0.60517471]
Get started explains each line, checks the numbers by hand and differentiates the result.
Documentation
The documentation is at https://bvial.info/gfem/. Good places to start:
- Get started: install, a first solve and its gradient.
- Tutorials: a band-stop filter, a coplanar line matched to 50 Ω, photonic waveguide bends and a metagrating, each designed with gradients.
- Heaters and thermo-optic phase: steady and transient heat conduction, Joule heating from a DC current, and the phase a heater puts on a waveguide, in 2D and 3D.
- PETSc and SLEPc: the PETSc and SLEPc solvers, which need a source build.
- Distributed solve: one driven, electrostatic or eigenmode solve across the ranks of an MPI job.
Licence
MIT. gfem depends on NGSolve (LGPL-2.1), whose PyPI wheels also contain GPL-2.0+ SuiteSparse code (UMFPACK, CHOLMOD
Supernodal); keep that in mind when redistributing a whole gfem environment. The mkl and cuda12/cuda13
extras pull proprietary vendor libraries: see Licence.
Contributing
To build gfem, run its tests or rebuild the docs, see Contributing.
Metadata
Release files for gfem 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gfem-0.1.0.tar.gz | 747.1 kB | With provenance | Details for gfem-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gfem-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for gfem-0.1.0-py3-none-any.whl |
Total release size: 1.5 MB
Release files / gfem-0.1.0.tar.gz
| Download URL | gfem-0.1.0.tar.gz |
|---|---|
| Size | 747.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
16b18b4e3d76fad06caaeadb83fc4b7a600e1f46290a753495e3c796c9d9dcd6
|
|
BLAKE2b-256 checksum How to use checksums |
d05e96e4b8fb7b207276c1c11b9c54e62286006cceabb78cdc39737d7c78ca36
|
| 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 20, 2026.
Transparency logRelease files / gfem-0.1.0-py3-none-any.whl
| Download URL | gfem-0.1.0-py3-none-any.whl |
|---|---|
| Size | 802.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6452127df1578d8f039c070b952f9bf66e529b6109e53b91d4f65bdf397a219b
|
|
BLAKE2b-256 checksum How to use checksums |
d5c9b8ef0cb6ac8b1ee3399ddcfda92f07cfb25dcae917817228973cac8899dc
|
| 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 20, 2026.
Transparency logSecurity for gfem 0.1.0
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.
Attestation for gfem-0.1.0.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 20, 2026.
Transparency logA 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.