Skip to content

Renormalizer interface for TRG (attempt 2)#195

Draft
Yue-Zhengyuan wants to merge 5 commits into
QuantumKitHub:masterfrom
Yue-Zhengyuan:iterable-trg-clean
Draft

Renormalizer interface for TRG (attempt 2)#195
Yue-Zhengyuan wants to merge 5 commits into
QuantumKitHub:masterfrom
Yue-Zhengyuan:iterable-trg-clean

Conversation

@Yue-Zhengyuan

Copy link
Copy Markdown
Member

Motivation

  • The current run! interface mixes algorithm configuration (truncation, stopping criterion, finalizers) with execution.
  • Intermediate states are inaccessible without writing custom Finalizer callbacks. This makes it hard to inspect what happens during an RG flow or to capture observables mid-run.

What this PR adds

Renormalizer — an iterator that separates algorithm parameters from tensor state:

params = TRGParams(; trunc = truncrank(24), stop = maxiter(25))
renorm = Renormalizer(params, T)

# Iterate: each step yields (state, data)
for (state, data) in renorm
    τ, _ = extract_tau_and_c(state.T; fast = false)
    # inspect observables or break at any step. no need for finalizers.
end

# Or advance one step at a time
rgstep!(renorm)

# Or run to completion
state, data = run!(renorm; verbosity = 1)

Architecture

TNRParams        ← pure algorithm config (truncation, stopping criterion)
Renormalizer     ← RG iterator (params + state + data + step counter)
TRG{E,S,TT}      ← unchanged existing type, now serves as Renormalizer state
TRGParams        ← TRG-specific params (@kwdef, sensible defaults)

Backward compatibility

The 3-argument run! for TRG is preserved as a thin wrapper that constructs TRGParams + Renormalizer internally and delegates:

scheme = TRG(T)
data = run!(scheme, truncrank(16), maxiter(20))  # unchanged

The new interface is a parallel layer that can be adopted incrementally.

  • Finalizer support is removed from TRG's run!. Also, the initial tensors are always normalized (finalized). Users who previously used a Finalizer to capture per-step data can instead use the iterator interface, which gives direct access to intermediate states without callback machinery. The Finalizer infrastructure remains in the codebase for other schemes (LoopTNR, etc.) and is tagged with TODO markers for eventual migration.

Side improvements

  • gs_degeneracy.jl: tensor-level methods + shared helper (huge deduplication)
  • cft.jl: extracted _row_transfer_matrix helper, reused by CFT and GSD paths
  • Tests: free energy, intermediate τ and CFT data captured in a single RG run instead of running twice

- New Renormalizer{A,S,D} iterable state machine with Base.iterate
- TNRParams abstract type for pure algorithm descriptors
- TRGParams <: TNRParams with trunc and stop fields
- Generic iteration: step!(state, trunc) + finalize!(state) + push!
- Old TRG{E,S,TT} <: TNRScheme{E,S} preserved as state type
- Legacy run!(::TRG, trunc, criterion) delegates to Renormalizer
- rgstep! exported for single-step advancement
- gs_degeneracy.jl: tensor-level methods, shared helper (-110 lines)
- cft.jl: extract _row_transfer_matrix helper
- Finalizer infrastructure marked with TODO for future removal
- 10 files, +247/-148 vs upstream/master

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Yue-Zhengyuan

Copy link
Copy Markdown
Member Author

@VictorVanthilt I have made substantial efforts to maintain backward compatibility. This PR should be much more acceptable.

@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 41.66667% with 49 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/utility/gs_degeneracy.jl 0.00% 28 Missing ⚠️
src/schemes/renormalizer.jl 54.83% 14 Missing ⚠️
src/schemes/trg.jl 63.15% 7 Missing ⚠️
Files with missing lines Coverage Δ
src/schemes/atrg.jl 73.33% <ø> (ø)
src/schemes/atrg3d.jl 0.00% <ø> (-95.56%) ⬇️
src/schemes/btrg.jl 84.61% <ø> (ø)
src/schemes/ctm/c4vctm.jl 90.27% <ø> (ø)
src/schemes/ctm/honeycomb.jl 0.00% <ø> (-93.34%) ⬇️
src/schemes/ctm/triangular.jl 0.00% <ø> (-67.40%) ⬇️
src/schemes/hotrg.jl 96.96% <ø> (ø)
src/schemes/hotrg3d.jl 0.00% <ø> (-93.66%) ⬇️
src/schemes/impurityhotrg.jl 0.00% <ø> (-100.00%) ⬇️
src/schemes/impuritytrg.jl 0.00% <ø> (-100.00%) ⬇️
... and 9 more

... and 23 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Interface suggestion: make TNR schemes iterable to access intermediate tensors

1 participant