feat: add use_positive_taus parameter and statistics-dependent periodicity#66
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Added
use_positive_tausparameter todefault_tau_sampling_pointsTrue(use[0, β]range)True, appliesnp.mod(points, β)and sorts the resultFiniteTempBasis,AugmentedBasis,DiscreteLehmannRepresentation, andTauSamplingImplemented statistics-dependent periodicity for augmentation functions
normalize_tau(statistics, tau, beta)function in_util.pyG(τ + β) = -G(τ)G(τ + β) = G(τ)taufuncs.rsimplementation for consistencyUpdated augmentation functions with statistics support
TauConst(beta, statistics='B'): now accepts statistics parameter, handles[-β, β]rangeTauLinear(beta, statistics='B'): now accepts statistics parameter, handles[-β, β]rangeMatsubaraConst(beta, statistics=None): updated range check to accept[-β, β]normalize_taufor proper periodicity handlingAdded comprehensive tests
test_normalize_tau_bosonic/fermionic: tests for periodicity rulestest_tau_const/linear_periodicity: statistics-dependent behavior teststest_matsubara_const_range:[-β, β]range verificationtest_tau_const/linear_with_statistics: factory method and direct creation teststest_backward_compatibility: ensures old API still worksBackward Compatibility
TauConst(beta),TauLinear(beta)default tostatistics='B'(Bosonic)use_positive_tausdefaults toTrue(consistent with Julia implementation)Cross-language Consistency
This implementation ensures consistency with:
use_positive_tausparameter and default behaviornormalize_taulogic fromtaufuncs.rsFiles Changed
src/sparse_ir/_util.py: Addednormalize_taufunction (73 lines)src/sparse_ir/basis.py: Addeduse_positive_tausparameter todefault_tau_sampling_pointssrc/sparse_ir/augment.py: UpdatedTauConst,TauLinear,MatsubaraConstwith statistics supportsrc/sparse_ir/sampling.py: Propagateuse_positive_tausparametersrc/sparse_ir/dlr.py: Accept kwargs indefault_tau_sampling_pointstests/test_augment.py: Added 10 new comprehensive testsTest Plan
normalize_taufunction for both Bosonic and Fermionic casesTauConstandTauLinear[-β, β]range acceptance for all augmentation functionsRelated Issues
This PR implements the same functionality as SparseIR.jl PR #100.