How to calculate onsite observerbles more efficiently?

Hi there,

I find the function measurelocalops!() in the function function measure!(obs::DMRGObserver; kwargs...) in the source code \src\ITensorMPS\observer.jl.

I redefined this function as

function ITensors.measurelocalops!(obs::ObserverDemo, wf::ITensor, i::Int)
    for o in obs.onsite_ITensor_ops
        # Moves to GPU if needed
        # @show o
        oⱼ = ITensors.adapt(ITensors.datatype(wf), ITensors.op(obs.sites, o, i))
        m = ITensors.dot(wf, ITensors.apply(oⱼ, wf))
        imag(m) > 1e-8 && (@warn "encountered finite imaginary part when measuring $o")
        obs.measurements[o][end][i] = real(m)
    end
end

in my own code with the version of ITensors v0.3.35, and it works much more efficiently than inner(psi', MPO(onsite_mpo, obs.sites), psi). However, when I update ITensors to version v0.3.68, this redefined function breaks down, while the source code does not change much.

How can I still use the more efficient way to calculate averages of the onsite operator with the updated version of ITensors?

Thank you so much for your time!

Best wishes.

Can you share a fully runnable minimal example that reproduces the issue you are seeing, along with the full error message (as instructed in Please Read: Make It Easier to Help You)? Additionally, can you update to the the latest version of ITensors.jl (v0.6.13) and try on that version?

Thank you for your response! After running additional tests, I discovered a bug in one of my functions, so the issue isn’t connected to ITensors.