# [julia] DMRGObserver not working

+1 vote

Hello,

I'm new to ITensors and try to mainly use the DMRG features here. I found the DMRGObserver feature pretty useful and was trying to implement it according to the documentation here . However, I saw an error while trying to create the DMRGObserver.

DMRGObserver(energy_tol = 1e-5, minsweeps = 2)


    ERROR: MethodError: no method matching DMRGObserver(; energy_tol=1.0e-5, minsweeps=2)
Closest candidates are:
DMRGObserver() at C:\Users\Sherry\.julia\packages\ITensors\2Rd6c\src\mps\observer.jl:33 got unsupported keyword arguments "energy_tol", "minsweeps"
DMRGObserver(::Array{String,1}, ::Array{var"#s305",1} where var"#s305"<:Index; energy_tol, minsweeps) at C:\Users\Sherry\.julia\packages\ITensors\2Rd6c\src\mps\observer.jl:38
DMRGObserver(::Any) at C:\Users\Sherry\.julia\packages\ITensors\2Rd6c\src\mps\observer.jl:33 got unsupported keyword arguments "energy_tol", "minsweeps"


Then I simply tried DMRGObserver(), still it gives the error

ERROR: MethodError: no method matching Array{var"#s305",1} where var"#s305"<:Index(::Array{Any,1})
Stacktrace:
[1] convert(::Type{Array{var"#s305",1} where var"#s305"<:Index}, ::Array{Any,1}) at .\array.jl:554
[2] DMRGObserver(::Float64, ::Int64) at C:\Users\Sherry\.julia\packages\ITensors\2Rd6c\src\mps\observer.jl:35 (repeats 2 times)
[3] top-level scope at REPL[8]:1


I'm using the most up-to-date version of ITensors (0.1.34). I don't have a good idea on how to fix it from here on. Please let me know if you have any suggestions.

Thanks,
Sherry

answered by (50.7k points)

Hi Sherry, so that documentation was a little bit hard to understand, because it makes it appear as if those arguments are named arguments. They are (or were - see below) not named arguments but just default arguments. However, that constructor turned out to have another bug, so would not have worked anyway even if called correctly.

I used that situation as an opportunity to improve the interface, and now it should work as you'd expect, i.e.

DMRGObserver(; energy_tol = 1E-4, minsweeps = 2)

say. Note that this is true right now only for the master branch of ITensors.jl and isn't in the latest numbered version yet. But we will tag a new version soon and the change will be included in 0.1.35.

Miles

commented by (210 points)
Hi Miles,

I see. Now I use a similar construction function as the example and it works. Initially, I just wanted to use it to set a stop criterion without measuring any observables. Seems like for now I have to put some observable and sites here in order to use it?

Thanks,
Sherry
commented by (50.7k points)
Yes, that's correct if by "for now" you mean for version 0.1.34 of ITensors. But we are tagging a new version 0.1.35 currently that should be available by tomorrow at the latest, and then you can use the more basic DMRGObserver constructor too.

Miles