Skip to main content

Crate sparse_ir

Crate sparse_ir 

Source
Expand description

§sparse-ir

Crates.io Documentation License: MIT OR Apache-2.0

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

§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 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).

§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, the Basis trait and sparse sampling;
  • sparse-ir-basis: kernels, the SVE and the IR basis FiniteTempBasis;
  • 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_DEBUG environment variable enables debug diagnostics (see is_debug_enabled for the accepted values).

Structs§

Bosonic
Bosonic statistics marker type
CentrosymmSVE
Centrosymmetric SVE computation
DiscreteLehmannRepresentation
Discrete Lehmann Representation (DLR)
DiscretizedKernel
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
FiniteTempBasis
Finite temperature basis for imaginary time/frequency Green’s functions
IrDlrTransform
Linear map between the coefficients of an IR basis and of a DLR on the same domain.
LogisticKernel
Logistic kernel for fermionic and bosonic analytical continuation
LogisticSVEHints
SVE hints for LogisticKernel
MatsubaraFreq
Matsubara frequency for a specific statistics type
MatsubaraSampling
Matsubara sampling for full frequency range (positive and negative)
MatsubaraSamplingPositiveOnly
Matsubara sampling for positive frequencies only
PiecewiseLegendreFT
Piecewise Legendre polynomial with Fourier transform capability
PiecewiseLegendreFTVector
Vector of PiecewiseLegendreFT polynomials
PiecewiseLegendrePoly
A single piecewise Legendre polynomial
PiecewiseLegendrePolyVector
Vector of piecewise Legendre polynomials
PowerModel
Power model for asymptotic behavior
Rank
Static tensor rank marker.
RegularizedBoseKernel
Regularized bosonic analytical continuation kernel
RegularizedBoseSVEHints
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
TSVDConfig
Configuration for TSVD computation
TauSampling
Sparse sampling in imaginary time
TypedTensor
TypedTensorView
Read-only borrowed view of typed tensor storage with arbitrary strides.
TypedTensorViewMut
Mutable borrowed view of typed tensor storage with arbitrary strides.

Enums§

ArrayRole
Which array of an operation has the wrong shape, in Error::ShapeMismatch
Error
Error returned by the fallible public functions of this crate
ErrorKind
Category of an Error
SVDStrategy
SVD computation strategy
Statistics
Statistics type enumeration
SymmetryType
TworkType
Working precision type for SVE computations

Traits§

AbstractKernel
Trait for general kernels (both centrosymmetric and non-centrosymmetric)
Basis
Common trait for basis representations in imaginary-time/frequency domains
CentrosymmKernel
Trait for centrosymmetric kernels
CustomNumeric
Custom numeric trait for high-precision numerical computation
DlrFromIr
Constructors of a DiscreteLehmannRepresentation from an IR basis
InplaceFitter
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
KernelProperties
Trait for kernel type properties (static characteristics)
SVEHints
Trait for SVE (Singular Value Expansion) hints
SVEStrategy
Trait for SVE computation strategies
StatisticsMarker
Trait for types that can represent statistics at runtime
StatisticsType
Statistics type trait for compile-time type-level distinction
TensorScalar
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 true if the SPARSEIR_DEBUG environment 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§

BosonicBasis
Type alias for bosonic basis with LogisticKernel
BosonicFreq
BosonicPiecewiseLegendreFT
BosonicPiecewiseLegendreFTVector
Df64
Compensated f64 (emulated quad precision) type.
FermionicBasis
Type alias for fermionic basis with LogisticKernel
FermionicFreq
FermionicPiecewiseLegendreFT
FermionicPiecewiseLegendreFTVector
Matrix
Dense column-major host matrix used by the public API.
Result
Result type of the fallible public functions of this crate