Skip to content

Return explicit error for Matsubara sampling with non-centrosymmetric kernels #183

@shinaoka

Description

@shinaoka

Summary

The Matsubara sampling point calculation (default_matsubara_sampling_points and related methods) relies on the assumption that basis functions in Matsubara space are either pure imaginary or pure real, which is only guaranteed for centrosymmetric kernels.

For non-centrosymmetric kernels, these methods would produce incorrect results silently or panic at runtime.

Current behavior

  • FiniteTempBasis::default_matsubara_sampling_points() panics at runtime with a message about centrosymmetry (basis.rs:446-451)
  • FiniteTempBasis::default_tau_sampling_points() also panics (basis.rs:335-340)
  • MatsubaraSamplingPositiveOnly uses ComplexToRealFitter which assumes real coefficients — this is only valid when basis functions have definite parity (centrosymmetric case)

While FiniteTempBasis<K, S> requires K: CentrosymmKernel at the type level, the Basis<S> trait itself does not encode this constraint. Any future Basis implementation for a non-centrosymmetric kernel could reach these code paths.

Desired behavior

Return explicit errors (e.g., Result types or at minimum clear error messages) rather than relying on:

  1. Runtime panics that may not clearly indicate the root cause
  2. Silent incorrect results from MatsubaraSamplingPositiveOnly when coefficients are not real

Root cause

The Matsubara sampling algorithm uses sign_changes / find_extrema of uhat basis functions, which assumes each uhat_l(iωn) is either pure real or pure imaginary (a consequence of centrosymmetry). For non-centrosymmetric kernels, uhat_l are general complex-valued and these algorithms do not apply.

Affected code

  • sparse-ir/src/basis.rs: default_matsubara_sampling_points, default_tau_sampling_points, default_matsubara_sampling_points_impl
  • sparse-ir/src/matsubara_sampling.rs: MatsubaraSamplingPositiveOnly::new(), ::with_sampling_points()
  • sparse-ir/src/polyfourier.rs: sign_changes, find_extrema

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions