PyMHM
pymhm couples user-defined local and global variational equations through
explicitly oriented trace coordinates. Declare the forms, choose a local
provider, then call assemble or solve. Scalar, vector and mixed fields use
the same interface; a local operator can itself be another multiscale problem.
NumPy/SciPy coefficients and optional FEniCS/UFL forms share this contract.
Basix supplies finite-element bases and tabulation.
Version 1.3.0 is an official release of PyMHM. Built-in workflows include triangular and polygonal meshes, Cartesian quadrilaterals, tetrahedra, affine prisms, star-shaped polyhedra and mapped hexahedra. Available equations and approximation spaces depend on the geometry; the documentation states each verified scope and distinguishes it from extensions described in the literature.
Available Methods
Choose the variational method and its admissible approximation spaces independently of the linear solver and execution backend. When publishing results obtained with PyMHM, cite the original publications of every method, reconstruction or estimator used, together with the PyMHM version. The Theoretical Background states degree, geometry and regularity conditions; each linked tutorial follows the mathematical formulation in code.
Recovery and adaptive strategies complement those discretizations:
| Strategy | Purpose | Original analysis |
|---|---|---|
| Flux and potential recovery | RT0 equilibration, moment H(div) reconstruction and conforming potentials | Barrenechea et al. (2026) |
| Error indicators | Field-specific residual and reconstructed-energy diagnostics | Araya et al. (2013) |
| Adaptive approximation | Independent macro, face, degree and local controls | Araya et al. (2021) |
| Recursive MHM | A multiscale local operator with its own global/local hierarchy | Harder and Valentin (2016) |
The table identifies implemented families, not every theorem or historical experiment in their papers. The Gallery records verified spaces and remaining limitations. RT0 equilibration and moment reconstruction are distinct operators; a generic indicator does not inherit the reliability proof of a complete published estimator.
Installation
Use Python 3.11–3.13 on Linux, macOS or Windows:
python -m pip install pymhm
The base package provides the coefficient interface with NumPy, SciPy and Basix.
Native UFL assembly also requires DOLFINx; installing the symbolic
fenics-ufl package with pip does not provide its native assembler. Follow the
native UFL installation instructions
for a Conda environment or the locked Pixi fem and introduction profiles.
Optional extras add CPU AMG,
PARDISO, MPI, CUDA solvers, meshing or visualization; for example,
python -m pip install "pymhm[amg]" adds PyAMG.
The installation guide covers virtual environments,
Windows commands, upgrades and native backend requirements.
Quick start
Start with the step-by-step UFL overview and the introductory course with executed plots. They connect the mathematical local and global formulations to the code for scalar, vector and mixed problems.
Install the notebook dependencies, download a notebook from the catalogue and open it in Jupyter:
python -m pip install "pymhm[notebooks]"
jupyter lab primal_galerkin.ipynb
The distribution contains only the pymhm library. A downloaded notebook's
first cell verifies and extracts its separate companion ZIP of importable helpers
and small configurations into a writable workspace. Its data and recorded fields
use separate verified downloads. This workflow needs no checkout or Pixi. Native UFL examples also need the DOLFINx installation described above.
Use the locked checkout environments
for development and the repository's qualified dependency combinations.
The portable coefficient interface follows the same mesh-to-solution workflow:
import numpy as np
from pymhm import (
CartesianMacroMesh, Equation, FaceSpace, LocalContext, LocalEquations,
MeshHierarchy, SkeletonSpace, assemble, bind_interface, bind_problem, solve,
)
macro = CartesianMacroMesh(1, 1)
hierarchy = MeshHierarchy(macro, (macro.submesh(0, 2),))
skeleton = SkeletonSpace(macro, tuple(FaceSpace.uniform(0) for _ in macro.faces))
interface = bind_interface(skeleton, convention="value")
def local(context: LocalContext) -> LocalEquations:
"""Declare independent volume and interface equations."""
return context.equations(
a=[[2.0]], L=[1.0], b=np.ones((1, 4)), c=-np.ones((4, 1)),
d=np.eye(4),
)
problem = bind_problem(hierarchy, interface, local, global_equation=Equation(0, 0))
system = assemble(problem)
solution = solve(system)
print(solution.trace, solution.fields) # every coordinate is 1/6
This small algebraic example declares $2u+\sum_F\lambda_F=1$ and $-u+\lambda_F=0$ on each face. The binding owns the shared numbering and geometric maps; the user supplies both equations. The variational guide describes UFL forms, retained modes, physical constraints and recursive problems, and states the supported limits. For complete control, see the custom-space tutorial, which declares a nonorthogonal basis and its independent trial/test maps.
The wheel contains every pymhm runtime module, typing and distribution metadata.
The source distribution also carries the README, license and build metadata
needed to rebuild that wheel independently. Neither archive contains notebooks,
example helpers, case registries, configurations, datasets, computed fields,
figures or comparison tools. These repository files have separate
notebook companions and data downloads, with declared SHA-256
identities, provenance and terms. Optional native backends require their separate
dependencies.
The Windows guide describes native portable-core execution,
SciPy/PyPardiso selection, process workers, installed-wheel checks and the
native DOLFINx/UFL profile. Local FEM assembly uses DOLFINx's CSR/vector
interfaces independently of PETSc; choose compatible numerical solvers through
SolverConfig. The locked fem-intel profile combines FEM assembly with
PARDISO on Linux and Windows. Native Windows requires an MPI runtime and a
Visual Studio JIT compiler. PETSc/MUMPS solvers and distributed PETSc workflows
use the Unix stack, including WSL2 on a Windows host. CI reports qualify each
platform separately.
Verified discretizations and integrations
The physical formulations compose public finite-element, material, trace and
linear-algebra operations. Importable providers in examples.formulations
declare their local and global equations without invoking predefined solvers;
the variational guide identifies these operations and
their numerical conventions. Existing solver entry points remain available.
Numerical records and stored coefficient contracts document the verified
discretizations, materials and boundary data; they do not qualify arbitrary
user-defined forms.
- Primal Pk, general triangular RT/BDM and enriched rectangular RT Darcy; anisotropic permeability, mixed boundary data and physical pure-Neumann gauges.
- Cartesian Qk Darcy, discrete point wells, and SPE10 Model 2 slices with explicit units, checked downloads and geometric material-interface integration.
- Taylor–Hood and residual-consistent equal-order USFEM Stokes–Brinkman/Oseen, including spatially variable tensor resistance and prescribed convection.
- Displacement–pressure GaLS elasticity through the incompressible limit, Taylor–Hood elasticity, and weakly symmetric enriched BDM/RT stress elasticity. All local rigid motions, material derivatives and physical constraints are explicit.
- Conservative variable-coefficient RAD with Galerkin or consistent SUPG locals, high-order heat diffusion, backward Euler and Darcy/dispersion coupling.
- Polygonal local partitions and star-shaped polyhedra with original polygonal face spaces; tetrahedral Pk operators, tetrahedral/prismatic mixed H(div) families, and mapped hexahedral RT Darcy fields.
- MsHHO cell/face moment constructions, recursive local problems, material-fitted integration, moment reconstruction, and equation-specific error estimation and adaptation.
- MH²M pressure traces, Robin-local MH, residual Petrov–Galerkin MHM and unusual reaction–diffusion stabilization, with independent finite element checks.
- Three-dimensional Taylor–Hood/USFEM flow, GaLS elasticity, MsHHO and tetrahedral RT reconstruction with dimension-dependent estimator spaces.
- Full anisotropic mixed stress on polygonal macrocells, arbitrary planar material cuts and independently controlled normal/interior H(div) orders.
- Three-dimensional weakly symmetric AFW stress elasticity, including the incompressible limit, and Newmark MHM elastodynamics with local subcycling.
- Complex Helmholtz waves with absorbing boundaries and perfectly matched layers; transient Maxwell TM and three-dimensional vector fields with explicit CFL controls.
- Independent face partitions and degrees, including continuous subface traces; physical local kernel constraints, source/trace factorization reuse and conservative RT0 flux equilibration.
- User-defined UFL local operators, explicit local/global form descriptions and callable providers; optional mesh import/export with physical tags.
- Basix reference elements, nodal simplex/tensor bases and RT/BDM tabulation, with explicit native basis ordering, transformations and coefficient digests.
- PyVista/VTK export and rendering, including broken finite-element fields and
actual macro-mesh overlays (
python -m pip install "pymhm[visualization]"). - SciPy, PETSc, PARDISO, CuPy and cuDSS solvers; CPU PyAMG and optional GPU AmgX. AMG local Neumann solves use a compatible SPD complement.
- Deterministic serial/thread/process local execution with bounded batches and native thread limits; the coordinator reduces shared-face contributions in cell order and retains mesh/DOF metadata for reconstruction.
- Distributed PETSc/MPI assembly, reusable offline operators, resident GPU P1 batches and augmented CPU/GPU AMG saddle preconditioners.
The scientific scope maps each article to implemented paths, verification evidence and remaining reproduction limits. The stated geometry, space compatibility and estimator hypotheses are part of each capability. See theory, Bibliography, Gallery and performance for assumptions and evidence.
The visual case gallery compares computed fields with analytical references, error maps, profiles and convergence expectations. The MSL field comparison checks primal Darcy fields against MSL_MHM with MSL_CG and MSL_Core. The NeoPZ comparison checks RT0/P0 fields against NeoPZ and distinguishes that assembly from Labmec/MHM's higher-order controller. Each case records the actual spaces and boundary conventions used in the comparison. The GaLS elasticity comparison matches MSL fields over five mesh levels and three local polynomial degrees. The SPE10 case identifies the published layers, spaces and boundary conditions and compares pressure profiles directly with article data. The quarter-five-spot case includes point wells, an analytical series, and MSL/NeoPZ comparisons for a low-permeability obstacle.
Reproducible calculations
Git contains sources, scientific JSON records, three compact SPE10 input layers
and the selected figures used by the published documentation. Large computed
fields and intermediate outputs are generated locally and stay outside Git.
The installed distribution contains only the pymhm library. Notebook sources,
companions and acquisition metadata are separate repository and website files.
Selected data and recorded figures use verified downloads; current fields and
intermediate outputs are generated in the user's working directory. An
ordinary package installation and core tests require no computed field archives.
ROADMAP.md sets implementation and validation priorities,
dependencies and acceptance criteria for the next milestones.
Generate only the cases being evaluated, using their documented public commands; then check their numerical acceptance before plotting or reporting reproduction. The notebook catalogue groups examples by physical problem and lists their methods. Start with a small analytical example:
python -m scripts.run_notebooks darcy/primal_galerkin.ipynb
python -m scripts.run_notebooks flow/introductory_methods.ipynb
# The same examples in the locked checkout environment:
pixi run --locked -e notebooks notebooks-run darcy/primal_galerkin.ipynb
pixi run --locked -e notebooks notebooks-run flow/introductory_methods.ipynb
Executed copies retain the problem folders under build/notebooks. Historical
numeric IDs also select their notebooks. Analytical patches introduce the API;
they do not replace a published benchmark reproduction.
Inspect the declared calculations before a complete study:
python -m scripts.run_notebooks 68 --study --plan
Current inputs are prepared by their public recipes using the active Python environment. Pinned raw datasets are downloaded only when the selected case needs them; checksum and size conventions remain explicit. Complete studies retain their original cost and numerical scope. Historical external field archives require their original supplied payloads and are identified separately. Regenerating a scientific case or replaying its fields requires its documented calculations; package builds and core tests do not require computed field archives.
Development
pixi run --locked -e test-core lint
pixi run --locked -e test-core typecheck
pixi run --locked -e test-core coverage-run
pixi run --locked -e fem test-fem
pixi run --locked -e fem-intel test-fem-portable
pixi run --locked -e meshing test-meshing
pixi run --locked -e packaging build
pixi run --locked -e packaging check-dist
After generating and accepting the selected scientific cases, execute their
notebooks and run pixi run --locked -e docs docs-check. Inspect the rendered figures and
MathJax in the browser. CI checks documentation markup; scientific acquisition,
notebook execution and full gallery generation require their separate acceptance.
The portable test-core environment supports Linux, Windows and macOS. The
complete test environment includes the native CPU and GPU integrations and
requires a Linux CUDA host with two NVIDIA devices. Its pinned AmgX setup and
mandatory dependency checks are described in the development guide.
Both suites use all available CPU workers and isolate tests marked serial.
CI tests the portable core on Linux x86-64, Windows x86-64 and macOS Apple Silicon (ARM64). It enforces independent 99% line and branch coverage gates on the combined Linux core and native FEM measurements from the same revision. The development guide provides the local commands. Executable notebooks and their companion helpers are separate repository and website downloads. Optional dependency contracts and actual native-backend integrations are reported separately.
Dedicated Tests,
Lint and Quality
and Docs workflows
run independently on pull requests and main-branch pushes. The complete two-GPU
suite is opt-in through manual dispatch. On a validated release tag,
Publish to PyPI
validates metadata and runs Tests, Quality and Docs checks in parallel, then
publishes the checked distributions to PyPI, creates the GitHub Release and
deploys the documentation to GitHub Pages.
The Docs workflow also supports manual publication from main or a release tag
by enabling its publish input.
Maintainers configure the PyPI trusted publisher for publish-pypi.yml, Pages
with GitHub Actions as its source and the github-pages environment to accept
release tags; see development.
Prepare release notes and synchronize current versions with
pixi run --locked -e release release-prepare VERSION, after running
release-fetch in the same environment. The task uses git-cliff and preserves
handwritten notes. Official releases use X.Y.Z versions and matching vX.Y.Z
tags; for example, prepare 1.1.0 and tag v1.1.0. Use --initial only when no
canonical release tag exists in the fetched main-branch history.
The software is licensed under LGPL-2.1-only. Citation metadata is in CITATION.cff.
Original documentation figures and diagrams are licensed under
CC BY 4.0, with attribution to
IPES Research Group. Commercial reuse and adaptations are permitted with
attribution and an indication of changes; see the
figure reuse guide.
Institutional Support
PyMHM is developed by the Innovative Parallel numErical Solvers (IPES) research group and receives institutional support from the Laboratório Nacional de Computação Científica (LNCC), a research unit of the Ministério da Ciência, Tecnologia e Inovação (MCTI), Brazil.
Metadata
Release files for pymhm 1.3.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 | |
|---|---|---|---|
| pymhm-1.3.0.tar.gz | 516.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pymhm-1.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.2 MB
Release files / pymhm-1.3.0.tar.gz
| Download URL | pymhm-1.3.0.tar.gz |
|---|---|
| Size | 516.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b702b6539c0b8ef2eb7ef1dcc633147f7da1fff7439e54289f0d96b56b507355
|
|
BLAKE2b-256 checksum How to use checksums |
03fd03b7b780f3a9b8c8654d82b83bbf73dec78e7351fc259f9da0d8d3c26eaa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 9, 2026.
Transparency logRelease files / pymhm-1.3.0-py3-none-any.whl
| Download URL | pymhm-1.3.0-py3-none-any.whl |
|---|---|
| Size | 722.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27fddb4e9bf24023b0973d45d8d49959e11668d82d9cc4ecbefe0d0fa5a020ba
|
|
BLAKE2b-256 checksum How to use checksums |
4eb3b6e2944d7178eddd800c5102846901f301a578b3c2037af7906f3ddb3be2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 9, 2026.
Transparency log