ITensor / ITensor/ITensorMPS.jl

[BUG] write_when_maxdim_exceeds not working for TDVP

Open
#176 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Julia
Stars
85
Forks
27
Avg merge
22m
Merged PRs (30d)
1

Description

Description of bug

When the flag write_when_maxdim_exceeds is activated in tdvp, the code returns an error, I suspect when it tries to read the file saved on the disk.
As a side comment, when setting "outpulevel=2", the code stops at the println line because "sweeps" is not defined (alternating_update.jl:64)

Minimal code demonstrating the bug or unexpected behavior

If applicable, provide a minimal code that can be run to demonstrate the bug or unexpected behavior.

If you are unable to construct a minimal code that demonstrates the bug or unexpected behavior, provide detailed steps for how to reproduce the behavior you are seeing.

Minimal runnable code

using ITensorMPS: MPO, OpSum, random_mps, siteinds, tdvp

let
    n = 10
    s = siteinds("S=1/2", n)

    function heisenberg(n)
        os = OpSum()
        for j in 1:(n - 1)
            os += 0.5, "S+", j, "S-", j + 1
            os += 0.5, "S-", j, "S+", j + 1
            os += "Sz", j, "Sz", j + 1
        end
        return os
    end

    H = MPO(heisenberg(n), s)
    ψ = random_mps(s, "↑"; linkdims = 10)

 
    ϕ = tdvp(
        H,
        -20.0,
        ψ;
        time_step = -1.0,
        maxdim = 30,
        cutoff = 1.0e-10,
        normalize = true,
        reverse_step = false,
        outputlevel = 1,
        write_when_maxdim_exceeds = 10
    )

    return nothing
end

Expected output or behavior

I expect "write_when_maxdim_exceed" to work in the same way it does for dmrg. I worked in the past with the c++ version of ITensor and writing temporary files on disk during TDVP runs caused no problem

Actual output or behavior

It returns the following error

Output of minimal runnable code

ERROR: LoadError: UndefRefError: access to undefined reference
Stacktrace:
  [1] checkfile
    @ ~/.julia/packages/SerializedElementArrays/cdFxy/src/SerializedElementArrays.jl:64 [inlined]
  [2] getindex(d::SerializedElementArrays.SerializedElementArray{ITensors.ITensor, 1}, I::Int64)
    @ SerializedElementArrays ~/.julia/packages/SerializedElementArrays/cdFxy/src/SerializedElementArrays.jl:71
  [3] iterate
    @ ./abstractarray.jl:1235 [inlined]
  [4] iterate
    @ ./abstractarray.jl:1233 [inlined]
  [5] copyto_unaliased!(deststyle::IndexLinear, dest::Vector{ITensors.ITensor}, srcstyle::IndexCartesian, src::SerializedElementArrays.SerializedElementArray{ITensors.ITensor, 1})
    @ Base ./abstractarray.jl:1095
  [6] copyto!(dest::Vector{ITensors.ITensor}, src::SerializedElementArrays.SerializedElementArray{ITensors.ITensor, 1})
    @ Base ./abstractarray.jl:1070
  [7] copymutable(a::SerializedElementArrays.SerializedElementArray{ITensors.ITensor, 1})
    @ Base ./abstractarray.jl:1201
  [8] copy
    @ ./abstractarray.jl:1144 [inlined]
  [9] copy(P::ITensorMPS.DiskProjMPO)
    @ ITensorMPS ~/.julia/packages/ITensorMPS/TTT5d/src/abstractprojmpo/diskprojmpo.jl:36
 [10] sub_sweep_update(direction::Base.Order.ForwardOrdering, reduced_operator::ITensorMPS.DiskProjMPO, state::ITensorMPS.MPS; updater::Function, updater_kwargs::@NamedTuple{}, which_decomp::Nothing, svd_alg::Nothing, sweep::Int64, current_time::Float64, time_step::Float64, nsite::Int64, reverse_step::Bool, normalize::Bool, observer!::ITensorMPS.EmptyObserver, outputlevel::Int64, maxdim::Int64, mindim::Int64, cutoff::Float64, noise::Bool)
    @ ITensorMPS ~/.julia/packages/ITensorMPS/TTT5d/src/solvers/sweep_update.jl:82
 [11] sweep_update(order::ITensorMPS.TDVPOrder{2, Base.Order.ForwardOrdering()}, reduced_operator::ITensorMPS.DiskProjMPO, state::ITensorMPS.MPS; current_time::Float64, time_step::Float64, kwargs::@Kwargs{updater::typeof(ITensorMPS.exponentiate_updater), updater_kwargs::@NamedTuple{}, nsite::Int64, reverse_step::Bool, sweep::Int64, observer!::ITensorMPS.EmptyObserver, normalize::Bool, outputlevel::Int64, maxdim::Int64, mindim::Int64, cutoff::Float64, noise::Bool})
    @ ITensorMPS ~/.julia/packages/ITensorMPS/TTT5d/src/solvers/sweep_update.jl:25
 [12] macro expansion
    @ ~/.julia/packages/ITensorMPS/TTT5d/src/solvers/alternating_update.jl:70 [inlined]
 [13] macro expansion
    @ ./timing.jl:461 [inlined]
 [14] alternating_update(operator::MPO, init::ITensorMPS.MPS; updater::Function, updater_kwargs::@NamedTuple{}, nsweeps::Int64, checkdone::Returns{Bool}, write_when_maxdim_exceeds::Int64, nsite::Int64, reverse_step::Bool, time_start::Float64, time_step::Float64, order::Int64, observer!::ITensorMPS.EmptyObserver, sweep_observer!::ITensorMPS.EmptyObserver, outputlevel::Int64, normalize::Bool, maxdim::Int64, mindim::Int64, cutoff::Float64, noise::Bool)
    @ ITensorMPS ~/.julia/packages/ITensorMPS/TTT5d/src/solvers/alternating_update.jl:69
 [15] alternating_update
    @ ~/.julia/packages/ITensorMPS/TTT5d/src/solvers/alternating_update.jl:23 [inlined]
 [16] #tdvp#924
    @ ~/.julia/packages/ITensorMPS/TTT5d/src/solvers/tdvp.jl:88 [inlined]
 [17] top-level scope
    @ ~/jjdebug/01_tdvp.jl:22
 [18] include(mod::Module, _path::String)
    @ Base ./Base.jl:306
 [19] exec_options(opts::Base.JLOptions)
    @ Base ./client.jl:317
 [20] _start()
    @ Base ./client.jl:550

Version information

  • Output from versioninfo():
julia> versioninfo()
Julia Version 1.12.4
Commit 01a2eadb047 (2026-01-06 16:56 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × 12th Gen Intel(R) Core(TM) i7-1250U
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, alderlake)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 12 virtual cores)
  • Output from using Pkg; Pkg.status("ITensorMPS"):
julia> using Pkg; Pkg.status("ITensorMPS")
Status `~/.julia/environments/v1.12/Project.toml`
  [0d1a4710] ITensorMPS v0.3.28```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal Julia reproduction, then trace the TDVP entry point in solvers/tdvp.jl through solvers/alternating_update.jl and solvers/sweep_update.jl. Inspect the DiskProjMPO copy path in abstractprojmpo/diskprojmpo.jl and the SerializedElementArrays error. Done means write_when_maxdim_exceeds works during TDVP like DMRG, and outputlevel=2 no longer references an undefined sweeps value.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.