Skip to content

Interface suggestion: make TNR schemes iterable to access intermediate tensors #191

Open

Description

@Yue-Zhengyuan

Currently, the run! interface runs the TNR scheme to the end of the RG process, with only a limited information of the intermediate RG steps only accessible at the end from the returned value of Finalizer. This also negatively affects the tests (especially in test/schemes/schemes.jl): sometimes TNR are repeatedly run for different number of steps to examine different properties (free energy or CFT data). For example:

@testset "TRG - Ising Model" begin
@info "TRG ising free energy"
scheme = TRG(T)
data = run!(scheme, truncrank(24), maxiter(25))
@test free_energy(data, ising_βc) ≈ f_onsager rtol = 2.0e-6
@info "TRG ising CFT data"
scheme = TRG(T)
run!(scheme, truncrank(24), maxiter(10))
cft = sort(CFTData(scheme; shape = [1, 1, 0]).scaling_dimensions[2:end]; by = abs) .|> real

A nicer interface in my opinion is to make the TNR schemes iterable (similar to the TimeEvolver in PEPSKit or IterativeSolver in MPSKit). Each iteration returns the tensors at the current step, and the normalization factor (for free energy calculation, etc). The TRG test above then may be written as

@info "BTRG ising free energy"
scheme = TRG(T)
data = scalartype(T)[]
# may make `scheme` callable; or use other approaches
rg_runner = scheme(truncrank(24), maxiter(25))
for (n, (T, nrm)) in enumerate(rg_runner)
    push!(data, nrm)
    (n != 10) && continue
    # examine CFT data at step 10
    cft = sort(CFTData(scheme; shape = [1, 1, 0]).scaling_dimensions[2:end]; by = abs) .|> real
    # CFT tests
end
@test free_energy(data, ising_βc) ≈ f_onsager rtol = 6.0e-8

Then, no need to run TRG twice.

Activity

  1. Yue-Zhengyuan commented on Jun 12, 2026

    @Yue-Zhengyuan
    MemberAuthor

    I can make a PR next week on TRG to illustrate how this works. If you like it, we can gradually roll out the new interface to all TNR schemes.

  2. VictorVanthilt commented on Jun 16, 2026

    @VictorVanthilt
    Member

    I'm quite curious to see this in action! We could keep supporting the run! functionality but at the same time offer an "expert mode" which people can use by using the schemes as an iterable.

  3. Chenqitrg commented on Jul 7, 2026

    @Chenqitrg
    Contributor

    If do not consider the backward compatibility, I would dream to have a structure called

    struct TensorBlock{horizontal, vertical}
      Ts::Vector{AbstractTensorMap}
    end

    and a struct called

    struct RG
      ...
    end

    And define a function

    evaluate(scheme::RG, tensorblock::TensorBlock)

    which returns a tensorblock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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