Skip to main content

gfem

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.2.0 is the current 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.2.0

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

Source distribution (sdist)

Source distribution for gfem 0.2.0
File Size Uploaded Provenance Actions
gfem-0.2.0.tar.gz 836.5 kB With provenance Details for gfem-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.7 MB

Release files / gfem-0.2.0.tar.gz

Download URL gfem-0.2.0.tar.gz
Size 836.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3be9d7c9ae92b7583b915c23faf13d20147e053580a8b4818c6ed33029d46c07
BLAKE2b-256 checksum
How to use checksums
1d4a244f7a24eb8b472dedae60e378c85bebed3dc2a1dba53bf0f6d1105844da
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 23, 2026.

Transparency log

Release files / gfem-0.2.0-py3-none-any.whl

Download URL gfem-0.2.0-py3-none-any.whl
Size 900.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec5166f3ec56d00cae04650c37b1b08799a7b01af6e25d36afa4df8b1fb66cff
BLAKE2b-256 checksum
How to use checksums
0eacc555584f2c7cdea71536aadefa41372c929a64a71acdb9c7d65b62982fc7
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 23, 2026.

Transparency log

Security for gfem 0.2.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.

Select from 2 files

Attestation for gfem-0.2.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 23, 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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