sparse-ir 0.16.0

IR basis, DLR, ESPRIT/MiniPole and sparse sampling for imaginary-time Green's functions
Documentation

sparse-ir

Crates.io Documentation License: MIT OR Apache-2.0

IR basis, DLR, ESPRIT/MiniPole and sparse sampling for imaginary-time Green's functions, in pure Rust.

Features

All of these are in the current release on crates.io:

  • Intermediate representation (IR) basis for fermionic and bosonic statistics
  • Discrete Lehmann representation (DLR), built independently of an IR basis (DiscreteLehmannRepresentation::new, DlrBuilder) or from one (from_ir)
  • ESPRIT and MiniPole pole reconstruction (sparse_ir::esprit, sparse_ir::minipole)
  • Sparse sampling in imaginary time and Matsubara frequencies

Documentation

The Rust User Guide has tutorials with figures and runnable examples, written against the current release; start with its installation and conventions pages. The API reference for the release is on docs.rs/sparse-ir; the guide also hosts the API reference built from main. For AI-assisted Rust use, load the SparseIR Rust usage skill when choosing crates, imports, or numerical conventions.

Installation

sparse-ir requires Rust 1.96 or newer. Add it to your Cargo.toml:

[dependencies]
sparse-ir = "0.16.0"

Optional: system BLAS

By default, sparse-ir uses faer (pure Rust) for the matrix products in fit and evaluate. To route them through the LP64 BLAS installed on your system (e.g. OpenBLAS, Intel MKL), enable the system-blas feature:

[dependencies]
sparse-ir = { version = "0.16.0", features = ["system-blas"] }

Both backends implement the same transforms and memory-order contract; the feature only changes which implementation multiplies the matrices. The results are not guaranteed to be bit-identical: rounding can differ, and an ill-conditioned step such as the DLR coefficient transforms can amplify the difference (about 1e-12 was measured, SpM-lab/sparse-ir-rs#326).

Usage

Matsubara frequencies are indexed by the reduced integer n, with iν_n = i n π/β (n odd for fermions, even for bosons). Imaginary-time sampling points lie in [−β/2, β/2]. See the guide's conventions page for details.

Quick start: fit and evaluate with the IR basis

Build an IR basis, sample a Green's function G(τ) on the basis's τ points, fit its IR coefficients g_l, and evaluate them on the Matsubara sampling points. The model is a single pole at ω = 0.5, whose exact values are known on both axes.

use sparse_ir::{
    FermionicBasis, LogisticKernel, MatsubaraSampling, TauSampling, fermionic_single_pole,
    giwn_single_pole,
};

fn main() -> Result<(), sparse_ir::Error> {
    let (beta, wmax, omega) = (10.0, 1.0, 0.5);

    // IR basis for Λ = β ω_max, truncated at s_l / s_0 < 1e-10
    let kernel = LogisticKernel::new(beta * wmax)?;
    let basis = FermionicBasis::new(kernel, beta, Some(1e-10), None)?;

    // G(τ) on the τ sampling points → IR coefficients g_l
    let tau_sampling = TauSampling::new(&basis)?;
    let g_tau = tau_sampling
        .sampling_points()
        .iter()
        .map(|&tau| fermionic_single_pole(tau, omega, beta))
        .collect::<Result<Vec<_>, _>>()?;
    let g_l = tau_sampling.fit(&g_tau)?;

    // g_l → G(iν_n) on the Matsubara sampling points
    let matsubara_sampling = MatsubaraSampling::new(&basis)?;
    let g_iw = matsubara_sampling.evaluate_real(&g_l)?;
    for (freq, value) in matsubara_sampling.sampling_points().iter().zip(&g_iw) {
        let exact = giwn_single_pole(freq, omega, beta)?;
        assert!((value - exact).norm() < 1e-8);
    }
    Ok(())
}

DLR without an IR basis

The DLR represents G as a sum of poles ω_p with coefficients c_p. DiscreteLehmannRepresentation::new(beta, wmax, eps) chooses the poles directly, without building an IR basis, and works with the same sampling types.

use sparse_ir::{
    DiscreteLehmannRepresentation, Fermionic, MatsubaraSampling, TauSampling,
    fermionic_single_pole, giwn_single_pole,
};

fn main() -> Result<(), sparse_ir::Error> {
    let (beta, wmax, omega) = (10.0, 1.0, 0.5);

    let dlr = DiscreteLehmannRepresentation::<Fermionic>::new(beta, wmax, 1e-10)?;
    println!("{} poles", dlr.poles().len());

    // G(τ) on the DLR's τ nodes → pole coefficients c_p
    let tau_sampling = TauSampling::new(&dlr)?;
    let g_tau = tau_sampling
        .sampling_points()
        .iter()
        .map(|&tau| fermionic_single_pole(tau, omega, beta))
        .collect::<Result<Vec<_>, _>>()?;
    let c_p = tau_sampling.fit(&g_tau)?;

    // c_p → G(iν_n) on the DLR's Matsubara nodes
    let matsubara_sampling = MatsubaraSampling::new(&dlr)?;
    let g_iw = matsubara_sampling.evaluate_real(&c_p)?;
    for (freq, value) in matsubara_sampling.sampling_points().iter().zip(&g_iw) {
        let exact = giwn_single_pole(freq, omega, beta)?;
        assert!((value - exact).norm() < 1e-8);
    }
    Ok(())
}

More examples, including IR ↔ DLR transforms, MiniPole and applied calculations, are in the user guide.

Crate layout

sparse-ir re-exports the crates it is made of, under their usual paths; you can also depend on them directly:

  • sparse-ir-sve: the singular value expansion of integral kernels, with the ACA-accelerated truncated SVD;
  • sparse-ir-core: statistics, errors, GEMM, fitters, the Basis trait and sparse sampling;
  • sparse-ir-basis: the kernels and the IR basis FiniteTempBasis;
  • sparse-ir-dlr: the discrete Lehmann representation;
  • sparse-ir-minipole: ESPRIT and minimal pole representations.

Dependencies

License

This crate is dual-licensed under the terms of the MIT license and the Apache License (Version 2.0).

Third-party licenses

The col_piv_qr module of sparse-ir-sve is based on code from the nalgebra library, which is licensed under the Apache License 2.0:

  • nalgebra: Apache License 2.0
    • Original source: nalgebra/src/linalg/col_piv_qr.rs
    • Copyright 2020 Sébastien Crozet
    • See Apache License 2.0 for details

Modifications and additions to the nalgebra code (including early termination support) are available under the same dual license as this crate (MIT OR Apache-2.0); see sparse-ir-sve/LICENSE-THIRD-PARTY.

The ESPRIT and MiniPole code of sparse-ir-minipole is a port of MiniPole (MIT License); see sparse-ir-minipole/LICENSE-THIRD-PARTY.

Contributing

Contributions are welcome! Please see the development guide for details.

References

  • sparse-ir: optimal compression and sparse sampling of many-body propagators
    Markus Wallerberger, Samuel Badr, Shintaro Hoshino, Fumiya Kakizawa, Takashi Koretsune, Yuki Nagai, Kosuke Nogaki, Takuya Nomoto, Hitoshi Mori, Junya Otsuki, Soshun Ozaki, Rihito Sakurai, Constanze Vogel, Niklas Witt, Kazuyoshi Yoshimi, Hiroshi Shinaoka
    arXiv:2206.11762 | SoftwareX 21, 101266 (2023)
  • Python wrapper: sparse-ir
  • Julia wrapper: SparseIR.jl