Skip to content

SketchedExpand doesn't work on FiniteMPS with a composite physical space (multiple site indices) #494

Description

@VinceNeede

Hi all, thanks for all the great work on this package!

I'm building an LPTN library on top of MPSKit, and while testing time evolution with SketchedExpand I ran into an error. Here's a minimal example:

using MPSKit, TensorKit
include("test/setup/testsetup.jl")
using .TestSetup

L = 10
P =^2
Dummy =^2
Dstart = 2
Dcap = 16
dt = 0.05

H = heisenberg_XXX(ComplexF64, Trivial; spin = 1 // 2, L)

# site tensors are `GenericMPSTensor{ComplexSpace,3}`: (Vl, P, Dummy) <- Vr
ψ₀ = FiniteMPS(rand, ComplexF64, L, P  Dummy, ℂ^Dstart)
alg = TDVP(;
    alg_expand = SketchedExpand(; trunc = truncrank(Dstart), oversampling = 4),
    trunc = truncrank(Dcap)
)
for _ in 1:6
    timestep!(ψ₀, H, 0.0, dt, alg)
end

Error message:

ERROR: SpaceMismatch: Direct sum of a vector space and its dual does not exist
Stacktrace:
 [1] ⊕
   @ ~/.julia/packages/TensorKit/zSHBV/src/spaces/complexspace.jl:57 [inlined]
 [2] changebond!(site::Int64, ::Val{…}, ψ::FiniteMPS{…}, H::FiniteMPOHamiltonian{…}, alg::SketchedExpand{…}, envs::MPSKit.FiniteEnvironments{…}; normalize::Bool)
   @ MPSKit ~/MPSKit.jl/src/algorithms/changebonds/sketchedexpand.jl:123
 [3] changebond!
   @ ~/MPSKit.jl/src/algorithms/changebonds/sketchedexpand.jl:92 [inlined]
 [4] timestep!(ψ::FiniteMPS{…}, H::FiniteMPOHamiltonian{…}, t::Float64, dt::Float64, alg::TDVP{…}, envs::MPSKit.FiniteEnvironments{…}; imaginary_evolution::Bool)
   @ MPSKit ~/MPSKit.jl/src/algorithms/timestep/tdvp.jl:156
 [5] timestep!
   @ ~/MPSKit.jl/src/algorithms/timestep/tdvp.jl:120 [inlined]
 [6] timestep!(ψ::FiniteMPS{…}, H::FiniteMPOHamiltonian{…}, t::Float64, dt::Float64, alg::TDVP{…})
   @ MPSKit ~/MPSKit.jl/src/algorithms/timestep/tdvp.jl:120
 [7] top-level scope
   @ ~/MPSKit.jl/trial.jl:22
Some type information was truncated. Use `show(err)` to see complete types.

I think the issue is here:

nc_space = (codomain(right_tail)[1] space(Q, 3)') domain(right_tail)

space(Q, 3)' looks like it assumes Q has exactly one physical-like leg, so the flat index 3 happens to land on its new-bond-direction space only when there's a single physical leg. For a state whose site tensors carry more than one physical-like leg (as in my case, GenericMPSTensor{S,3}), index 3 lands somewhere else instead. Since Q always has exactly one domain leg regardless of how many codomain legs it has, I believe domain(Q)[1] is the leg-count-agnostic fix.

I tried this change locally and it resolves the error for me. Happy to open a PR with it if that would help!

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