TDVP- Measure each k time steps (using Observer.jl)

Dear ITensors (really, ITensorMPS.jl) team,

I wish to perform something similar to the code in example 4 in the ITensorMPS.jl code (ITensorMPS.jl/examples/04_tdvp_observers.jl at main · ITensor/ITensorMPS.jl · GitHub).
However, I wish to compute observables from the state only at each k’th time step (with k some integer). Do you have a recommendation on how to implement this in code?

More explicitly, I am talking about this line:

  state = tdvp(
    H, -1.0im, init; time_step=-0.1im, cutoff=1e-12, (step_observer!)=obs, outputlevel=1
  )
  • Is it possible to wrap the step_observer function in a way that will compute the obs at, say, times [0, 0.5, 1]?
  • An example for a solution- split the tdvp time evolution to separate intervals and compute the observables at the end of each one, i.e.,
    measurements = []
    for measure_time in [0 0.5, 1]
        state = tdvp(
          H, -im*measure_time, init; time_step=-0.1im, cutoff=1e-12, outputlevel=1
        )
      push!(measurements, measure_state(state))
    end
    
    However, this solution does not utilize the convenient Observer.jl package.

Thanks,
Yotam

Here is kind of a hacky way to do it based on specific times

measure_times = [0, 0.5, 1]
function measure_sz(; state, current_time)
  if (round(abs(current_time), sigdigits = 2) ∈ measure_times)
    return expect(state, "Sz"; sites = length(state) ÷ 2)
  end
  return nothing
end

Then later in the printing loop you can write

if obs.sz[n] != nothing
  print(", ⟨Sᶻ⟩ = ", round(obs.sz[n]; digits = 3))
end

Really one should do something more careful than round(abs(current_time), sigdigits = 2) of course, such as

function measure_sz(; state, sweep)
  if (sweep % 5 == 0)
    return expect(state, "Sz"; sites = length(state) ÷ 2)
  end
  return nothing
end

instead

1 Like

Thanks!

The “sweep” parameter is transferred from the tdvp function into observer, if I understand correctly?
If so, this solution works for me :slight_smile:

1 Like

Yeah, tdvp passes the following possible kwargs (from the example):

state::MPS, sweep::Int64, outputlevel::Int64, current_time::ComplexF64

Glad it works!

3 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.