Expand description
§sparse-ir
A high-performance Rust implementation of the SparseIR (Sparse Intermediate Representation) library, providing analytical continuation and sparse representation functionality for quantum many-body physics calculations.
§Features
- Intermediate Representation (IR) basis for fermionic and bosonic statistics
- Independent Discrete Lehmann Representation (DLR) basis for fermionic and bosonic statistics
- ESPRIT and MiniPole pole reconstruction
- Sparse Sampling in imaginary time and Matsubara frequencies
§Documentation
The Rust User Guide provides
browser-readable tutorials with figures, including
MiniPole contour selection.
The guide and current API reference
follow main (Rust 1.96+). For AI-assisted Rust use, load the SparseIR
Rust usage skill
when choosing crates, imports, or numerical conventions. Follow the guide’s
Git installation instructions
to run its examples; the crates.io release API may differ.
§Installation
§As a Rust Library
Add to your Cargo.toml:
[dependencies]
sparse-ir = "0.11.0"§Optional: System BLAS Support
By default, sparse-ir uses Faer (pure Rust) for matrix operations in fit and evaluate routines. To use system BLAS instead (e.g., OpenBLAS, Intel MKL) for better performance, enable the system-blas feature:
[dependencies]
sparse-ir = { version = "0.11.0", features = ["system-blas"] }Note: When system-blas is enabled, fit and evaluate operations will use BLAS. When not linked, Faer is used as the fallback.
§Usage
§Basic Example
use sparse_ir::*;
fn main() -> Result<(), sparse_ir::Error> {
// Create a finite temperature basis
let beta = 10.0;
let lambda = 10.0; // beta * omega_max
let kernel = LogisticKernel::new(lambda)?;
let basis = FermionicBasis::new(kernel, beta, None, None)?;
// Generate sampling points
let sampling = TauSampling::new(&basis)?;
// Use the basis for calculations
let tau_points = sampling.sampling_points();
println!("Generated {} sampling points", tau_points.len());
Ok(())
}§SVE Example
use sparse_ir::*;
fn main() -> Result<(), sparse_ir::Error> {
// Create a kernel for analytical continuation
let kernel = LogisticKernel::new(1.0)?;
// Compute the SVE to an accuracy of 1e-12, keeping at most 100 singular values
let sve_result = compute_sve(kernel, Some(1e-12), None, Some(100), TworkType::Auto)?;
println!("SVE computed with {} singular values", sve_result.s().len());
Ok(())
}§API Documentation
The released API documentation is available at docs.rs/sparse-ir.
For the current main API, use the guide’s API reference.
§Performance
This implementation is optimized for high performance:
- Pure Rust: No external C/C++ dependencies for core functionality
- SIMD Optimized: Uses Faer for matrix-matrix products (evaluate and fit routines). Optionally, system BLAS can be used for these operations for better performance.
§Dependencies
- Tensors and linear algebra: tenferro-rs (CPU) + Faer
- Extended Precision: xprec-rs
§License
This crate is dual-licensed under the terms of the MIT license and the Apache License (Version 2.0).
- You may use this crate under the terms of either license, at your option:
§Third-Party Licenses
The col_piv_qr module 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
- Original source:
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).
§Contributing
Contributions are welcome! Please see our 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
§sparse-ir: Rust implementation of SparseIR functionality
A high-performance implementation of the SparseIR (Sparse Intermediate Representation) library in Rust, providing analytical continuation and sparse representation functionality for quantum many-body physics calculations.
This crate re-exports the crates it is made of, under their usual paths:
sparse-ir-core: statistics, errors, GEMM, fitters, theBasistrait and sparse sampling;sparse-ir-basis: kernels, the SVE and the IR basisFiniteTempBasis;sparse-ir-dlr: the discrete Lehmann representation;sparse-ir-minipole: ESPRIT and minimal pole representations.
Modules§
- basis
- Finite temperature basis for SparseIR
- basis_
trait - Basis trait for IR and DLR representations
- dlr
- Discrete Lehmann Representation (DLR)
- error
- Error type of the public API
- esprit
- Matrix ESPRIT (port of
mini_pole/esprit.py). - fitters
- Fitters for least-squares problems with various matrix types
- fpu_
check - FPU state checking and correction for numerical stability
- freq
- Matsubara frequency implementation for SparseIR
- gauss
- Gauss quadrature rules for numerical integration
- gemm
- Column-major GEMM with a pluggable BLAS backend.
- ir_dlr
- Discrete Lehmann representations built from an IR basis
- kernel
- Kernel implementations for SparseIR
- kernelmatrix
- Kernel matrix discretization for SparseIR
- matrix
- Small column-major dense containers for internal numerics.
- matsubara_
sampling - Sparse sampling in Matsubara frequencies
- minipole
- Port of the minimal pole method of Green-Phys/MiniPole.
- numeric
- Custom numeric traits for high-precision computation
- poly
- Piecewise Legendre polynomial implementations for SparseIR
- polyfourier
- Piecewise Legendre polynomial Fourier transform implementation for SparseIR
- sampling
- Sparse sampling in imaginary time
- special_
functions - Special functions implementation ported from C++ libsparseir
- sve
- Singular Value Expansion (SVE) module
- taufuncs
- Imaginary time τ normalization utilities
- traits
- Common trait definitions for SparseIR
- tsvd
- High-precision truncated SVD implementation using nalgebra
Macros§
- debug_
warn - Print a warning to stderr only when the
SPARSEIR_DEBUGenvironment variable enables debug diagnostics (seeis_debug_enabledfor the accepted values).
Structs§
- Bosonic
- Bosonic statistics marker type
- CentrosymmSVE
- Centrosymmetric SVE computation
- Discrete
Lehmann Representation - Discrete Lehmann Representation (DLR)
- Discretized
Kernel - This structure stores a discrete kernel matrix along with the corresponding Gauss quadrature rules for x and y coordinates. This enables easy application of weights for SVE computation and maintains the relationship between matrix elements and their corresponding quadrature points.
- DlrBuilder
- Builder for the independent (interpolative-decomposition) DLR.
- DynRank
- Dynamic tensor rank marker.
- Fermionic
- Fermionic statistics marker type
- Finite
Temp Basis - Finite temperature basis for imaginary time/frequency Green’s functions
- IrDlr
Transform - Linear map between the coefficients of an IR basis and of a DLR on the same domain.
- Logistic
Kernel - Logistic kernel for fermionic and bosonic analytical continuation
- LogisticSVE
Hints - SVE hints for LogisticKernel
- Matsubara
Freq - Matsubara frequency for a specific statistics type
- Matsubara
Sampling - Matsubara sampling for full frequency range (positive and negative)
- Matsubara
Sampling Positive Only - Matsubara sampling for positive frequencies only
- Piecewise
LegendreFT - Piecewise Legendre polynomial with Fourier transform capability
- Piecewise
LegendreFT Vector - Vector of PiecewiseLegendreFT polynomials
- Piecewise
Legendre Poly - A single piecewise Legendre polynomial
- Piecewise
Legendre Poly Vector - Vector of piecewise Legendre polynomials
- Power
Model - Power model for asymptotic behavior
- Rank
- Static tensor rank marker.
- Regularized
Bose Kernel - Regularized bosonic analytical continuation kernel
- Regularized
BoseSVE Hints - SVE hints for RegularizedBoseKernel
- Rule
- Quadrature rule for numerical integration.
- SVDResult
- Result of SVD decomposition
- SVEResult
- Result of Singular Value Expansion computation
- SamplingSVE
- Sampling-based SVE computation
- TSVD
Config - Configuration for TSVD computation
- TauSampling
- Sparse sampling in imaginary time
- Typed
Tensor - Typed
Tensor View - Read-only borrowed view of typed tensor storage with arbitrary strides.
- Typed
Tensor View Mut - Mutable borrowed view of typed tensor storage with arbitrary strides.
Enums§
- Array
Role - Which array of an operation has the wrong shape, in
Error::ShapeMismatch - Error
- Error returned by the fallible public functions of this crate
- Error
Kind - Category of an
Error - SVDStrategy
- SVD computation strategy
- Statistics
- Statistics type enumeration
- Symmetry
Type - Twork
Type - Working precision type for SVE computations
Traits§
- Abstract
Kernel - Trait for general kernels (both centrosymmetric and non-centrosymmetric)
- Basis
- Common trait for basis representations in imaginary-time/frequency domains
- Centrosymm
Kernel - Trait for centrosymmetric kernels
- Custom
Numeric - Custom numeric trait for high-precision numerical computation
- DlrFrom
Ir - Constructors of a
DiscreteLehmannRepresentationfrom an IR basis - Inplace
Fitter - Evaluation and fitting along one axis of an N-dimensional tensor, writing into a caller-provided output view.
- IrBasis
- A basis with a kernel: the IR basis
FiniteTempBasis - Kernel
Properties - Trait for kernel type properties (static characteristics)
- SVEHints
- Trait for SVE (Singular Value Expansion) hints
- SVEStrategy
- Trait for SVE computation strategies
- Statistics
Marker - Trait for types that can represent statistics at runtime
- Statistics
Type - Statistics type trait for compile-time type-level distinction
- Tensor
Scalar - Sealed trait for scalar types that can be stored in a
Tensor.
Functions§
- bosonic_
single_ pole - Compute bosonic single-pole Green’s function at imaginary time τ
- compute_
logistic_ kernel - compute_
sve - Main SVE computation function for centrosymmetric kernels
- fermionic_
single_ pole - Compute fermionic single-pole Green’s function at imaginary time τ
- giwn_
single_ pole - Generic single-pole Green’s function at Matsubara frequency
- gtau_
single_ pole - Generic single-pole Green’s function at imaginary time τ
- is_
debug_ enabled - Returns
trueif theSPARSEIR_DEBUGenvironment variable enables debug diagnostics. - legendre
- Create a Gauss-Legendre quadrature rule with n points on [-1, 1].
- legendre_
custom - Create a Gauss-Legendre quadrature rule with n points on [-1, 1] (CustomNumeric version).
- legendre_
twofloat - Create a Gauss-Legendre quadrature rule with n points on [-1, 1] (Df64 version).
- matrix_
from_ gauss - Compute matrix from Gauss quadrature rules (legacy version without segments)
- matrix_
from_ gauss_ noncentrosymmetric - Compute matrix from Gauss quadrature rules for non-centrosymmetric kernels
- matrix_
from_ gauss_ with_ segments - Compute matrix from Gauss quadrature rules with segments from SVEHints
- svd_
decompose - Perform SVD decomposition using nalgebra with sorted singular values
- tsvd
- Main TSVD function using QR + SVD approach
- tsvd_
df64 - Convenience function for Df64 TSVD
- tsvd_
df64_ from_ f64 - Convenience function for Df64 TSVD from f64 matrix
- tsvd_
f64 - Convenience function for f64 TSVD
Type Aliases§
- Bosonic
Basis - Type alias for bosonic basis with LogisticKernel
- Bosonic
Freq - Bosonic
Piecewise LegendreFT - Bosonic
Piecewise LegendreFT Vector - Df64
- Compensated f64 (emulated quad precision) type.
- Fermionic
Basis - Type alias for fermionic basis with LogisticKernel
- Fermionic
Freq - Fermionic
Piecewise LegendreFT - Fermionic
Piecewise LegendreFT Vector - Matrix
- Dense column-major host matrix used by the public API.
- Result
- Result type of the fallible public functions of this crate