Skip to content

feat: add use_positive_taus parameter and statistics-dependent periodicity#66

Merged
shinaoka merged 2 commits into
mainlinefrom
feature/unify-positive-tau-range
Dec 17, 2025
Merged

feat: add use_positive_taus parameter and statistics-dependent periodicity#66
shinaoka merged 2 commits into
mainlinefrom
feature/unify-positive-tau-range

Conversation

@shinaoka
Copy link
Copy Markdown
Member

Summary

This PR unifies the behavior of tau sampling points to use the positive range [0, β] by default and implements statistics-dependent periodicity for augmentation functions, ensuring consistency with the Julia implementation (SparseIR.jl).

Key Changes

  1. Added use_positive_taus parameter to default_tau_sampling_points

    • Default value: True (use [0, β] range)
    • When True, applies np.mod(points, β) and sorts the result
    • Propagates through FiniteTempBasis, AugmentedBasis, DiscreteLehmannRepresentation, and TauSampling
  2. Implemented statistics-dependent periodicity for augmentation functions

    • Added normalize_tau(statistics, tau, beta) function in _util.py
    • Handles Fermionic anti-periodic: G(τ + β) = -G(τ)
    • Handles Bosonic periodic: G(τ + β) = G(τ)
    • Follows Rust taufuncs.rs implementation for consistency
  3. Updated augmentation functions with statistics support

    • TauConst(beta, statistics='B'): now accepts statistics parameter, handles [-β, β] range
    • TauLinear(beta, statistics='B'): now accepts statistics parameter, handles [-β, β] range
    • MatsubaraConst(beta, statistics=None): updated range check to accept [-β, β]
    • All augmentation functions use normalize_tau for proper periodicity handling
  4. Added comprehensive tests

    • test_normalize_tau_bosonic/fermionic: tests for periodicity rules
    • test_tau_const/linear_periodicity: statistics-dependent behavior tests
    • test_matsubara_const_range: [-β, β] range verification
    • test_tau_const/linear_with_statistics: factory method and direct creation tests
    • test_backward_compatibility: ensures old API still works

Backward Compatibility

  • Default constructors maintain compatibility: TauConst(beta), TauLinear(beta) default to statistics='B' (Bosonic)
  • use_positive_taus defaults to True (consistent with Julia implementation)
  • All existing tests pass (95 passed, 8 skipped)

Cross-language Consistency

This implementation ensures consistency with:

  • SparseIR.jl (Julia): Same use_positive_taus parameter and default behavior
  • sparse-ir-rs (Rust): Follows the same normalize_tau logic from taufuncs.rs

Files Changed

  • src/sparse_ir/_util.py: Added normalize_tau function (73 lines)
  • src/sparse_ir/basis.py: Added use_positive_taus parameter to default_tau_sampling_points
  • src/sparse_ir/augment.py: Updated TauConst, TauLinear, MatsubaraConst with statistics support
  • src/sparse_ir/sampling.py: Propagate use_positive_taus parameter
  • src/sparse_ir/dlr.py: Accept kwargs in default_tau_sampling_points
  • tests/test_augment.py: Added 10 new comprehensive tests

Test Plan

  • Run full test suite: 95 passed, 8 skipped
  • Verify normalize_tau function for both Bosonic and Fermionic cases
  • Test statistics-dependent periodicity for TauConst and TauLinear
  • Verify [-β, β] range acceptance for all augmentation functions
  • Verify backward compatibility with old API
  • Cross-check behavior with Julia implementation

Related Issues

This PR implements the same functionality as SparseIR.jl PR #100.

…icity

This commit unifies the behavior of tau sampling points to use the positive
range [0, β] by default and implements statistics-dependent periodicity for
augmentation functions, ensuring consistency with the Julia implementation.

Changes:

1. Added use_positive_taus parameter to default_tau_sampling_points
   - FiniteTempBasis.default_tau_sampling_points(use_positive_taus=True)
   - AugmentedBasis.default_tau_sampling_points(use_positive_taus=True)
   - DiscreteLehmannRepresentation propagates kwargs
   - TauSampling automatically propagates the parameter

2. Implemented statistics-dependent periodicity
   - Added normalize_tau(statistics, tau, beta) function in _util.py
   - Handles Fermionic anti-periodic: G(τ + β) = -G(τ)
   - Handles Bosonic periodic: G(τ + β) = G(τ)
   - Follows Rust taufuncs.rs implementation

3. Updated augmentation functions with statistics support
   - TauConst(beta, statistics='B'): now accepts statistics parameter
   - TauLinear(beta, statistics='B'): now accepts statistics parameter
   - MatsubaraConst(beta, statistics=None): accepts [-β, β] range
   - All use normalize_tau for proper periodicity handling

4. Added comprehensive tests
   - test_normalize_tau_bosonic/fermionic: periodicity tests
   - test_tau_const/linear_periodicity: statistics-dependent behavior
   - test_matsubara_const_range: [-β, β] range verification
   - test_backward_compatibility: ensures old API still works

Backward compatibility:
- Default constructors maintain compatibility (default to Bosonic)
- use_positive_taus defaults to True (consistent with Julia)
- All existing tests pass (95 passed, 8 skipped)

This implementation ensures consistency with SparseIR.jl and follows
the same design patterns for cross-language compatibility.
Resolved conflicts:
- src/sparse_ir/augment.py: Keep use_positive_taus implementation
- tests/test_augment.py: Keep all new tests for periodicity
@shinaoka shinaoka merged commit 43c5275 into mainline Dec 17, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant