Observer System for DMRG

hi
I am applying DMRG to a problem with a 1d non-hamiltonian
I ran into problems when I wanted to define a Custom Observer,Since the energy returned is complex, I tried changing the variable type and found it didn’t solve the problem

mutable struct DemoObserver <: AbstractObserver
  energy_tol::Float64
  last_energy::ComplexF64
  DemoObserver(energy_tol=0.0) = new(energy_tol,1000.0)
end

function ITensors.checkdone!(o::DemoObserver;kwargs...)
 sw = kwargs[:sweep]
 energy = kwargs[:energy]
 if abs(real(energy)-real(o.last_energy))/abs(real(energy)) < o.energy_tol
   println("Stopping DMRG after sweep $sw")
   return true
 end
 # Otherwise, update last_energy and keep going
 o.last_energy = energy
 return false
end

image

How and what should I change so that the work it?
Thanks.

Your code worked for me, I believe that error is simply a Julia limitation. You cannot redefine a struct in the same REPL sadly, so some ideas:

  • you can close and reopen Julia when you want to change your DemoObserver
  • If you want to keep using the same REPL you can just give the observer a new name each time (see the solution here)
2 Likes

It worked when I close and reopen Julia. Thank you!

2 Likes