Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

MeanFi

MeanFi solves self-consistent tight-binding models with density-density interactions, at zero or finite temperature, including superconducting BdG models. Define the Hamiltonian and interaction, supply an initial mean field, and solve:

import numpy as np
import meanfi

# A spinful chain: nearest-neighbor hopping and on-site repulsion.
hopping = -np.eye(2)
h_0 = {(0,): np.zeros((2, 2)), (1,): hopping, (-1,): hopping.T.conj()}
h_int = {(0,): np.array([[0., 1.], [1., 0.]])}
model = meanfi.Model(h_0, h_int, filling=1, kT=0.2)

guess = model.random_meanfield(rng=0, scale=0.1)
result = meanfi.solver(model, guess)
assert result.converged
h_mf = model.hamiltonian_from_meanfield(result.mean_field)
print(result.internal_energy)

Dictionary keys are lattice displacements; each value is an orbital matrix. EnergyDIIS() is the default solver and mixes densities using internal energy. SCF iterations and EDIIS use internal energy only. Entropy and free energy are optional: pass compute_free_energy=True to evaluate them after SCF terminates.

Final results report energies and entropy per cell per physical orbital, with entropy in units of Boltzmann's constant: free_energy = internal_energy - kT * entropy. Filling counts electrons per cell. A BdG Hamiltonian of size 2N still has N physical orbitals.

See the tutorials and API walkthrough for densities, observables, reference subtraction, restarts, BdG, sparse calculations, and Kwant conversion. The theory and algorithms explain the physics and numerical methods.

Integration

Normal zero-temperature calculations default to FermiSimplex(), backed by FermiSimplex. Dense finite-temperature calculations default to UniformGrid() with direct diagonalization and coarse/fine grid refinement.

# Choose a total point count or request accuracy-controlled integration.
integration = meanfi.UniformGrid(nk=4096)
integration = meanfi.UniformGrid(initial_nk=256)
result = meanfi.solver(model, guess, integration=integration, tol=1e-5)

An explicit nk fixes the mesh; integration targets then do not apply. For example, nk=4096 gives 64² periodic points in 2D. Prescribed meshes do not estimate integration error. initial_nk chooses a starting mesh for refinement, using the same total-point units; it cannot be combined with nk. The solver's tol still controls filling and SCF convergence. Zero-temperature UniformGrid supports fixed-mu evaluation only, with explicit nk for periodic systems. Its fixed-filling searches (including SCF) raise NotImplementedError; use FermiSimplex for normal zero-temperature models. FermiSimplex starts at an exact dyadic initial_grid_level (default 2); level L has 2**L+1 vertices per axis and is reported in the result statistics. For individual targets, pass an ErrorTolerances record as tol; method objects contain mesh, backend and resource settings only.

Sparse finite-temperature calculations use UniformGrid(nk=..., matrix_function=RationalFOE()). AAA approximates the Fermi function using selected inverse entries from MUMPS. The default tolerance policy uses fixed fractions of tol, independent of orbital count. result.errors.matrix_function_error reports the achieved approximation estimate (or None for methods without this estimate). See the accuracy and integration guide for supported combinations, mesh rounding, and changes from previous APIs.

Installation

This development revision supports Python 3.11–3.13. Use Pixi to install the pinned dependencies and native compiler:

git clone https://gitlab.kwant-project.org/qt/meanfi.git
cd meanfi
pixi install --locked
pixi run python -c "import meanfi; print(meanfi.__version__)"

FermiSimplex builds from a pinned Git revision and includes its own AdaptiveSimplex mesh engine. Installing this checkout with pip install . also works when Git and a suitable C++ compiler are available. See the development guide for native requirements and the remaining PyPI release prerequisite.

Optional extras are pip install ".[sparse]" for MUMPS and pip install ".[kwant]" for conversion helpers. The test-sparse Pixi environment supplies both packages and their native libraries. The default dense and FermiSimplex paths do not require MUMPS.

pixi run -e test-py312 tests
pixi run benchmark
pixi run -e docs docs-build

The design document describes the code's structure and contracts; AGENTS.md records the coding guidelines.

Citing MeanFi

@misc{meanfi,
  author = {Vilkelis, Kostas and Zijderveld, R. Johanna and Akhmerov, Anton R. and Manesco, Antonio L.R.},
  doi = {10.5281/zenodo.11149850},
  month = {5},
  title = {MeanFi},
  year = {2024}
}

Metadata

Release files for meanfi 2.0.0b1

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

Source distribution (sdist)

Source distribution for meanfi 2.0.0b1
File Size Uploaded Provenance
meanfi-2.0.0b1.tar.gz 176.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for meanfi 2.0.0b1
File Interpreter ABI Platform
meanfi-2.0.0b1-py3-none-any.whl Python 3 none any Details

Total release size: 272.3 kB

Release files / meanfi-2.0.0b1.tar.gz

Download URL meanfi-2.0.0b1.tar.gz
Size 176.3 kB
Tags Source
SHA-256 checksum
How to use checksums
907d3141495cb0f391f480f1d656c121b41391089b0003ad68dc16b14156a24b
BLAKE2b-256 checksum
How to use checksums
b48415d6ef06b7e84f4c1a964463e9179fadb71f4b856a5408d99c3e9bc863b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / meanfi-2.0.0b1-py3-none-any.whl

Download URL meanfi-2.0.0b1-py3-none-any.whl
Size 96.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70ecf5fd25255cb4d40d22e3a466a13454b77d02d78a19e66d09a5b58f48c051
BLAKE2b-256 checksum
How to use checksums
b5e02cc3e9d9975cf8acadbb984bce6b79e08dc1e9ce99fc6e5c2f614410c6da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for meanfi 2.0.0b1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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