QuantumKitHub / MPSKit.jl

A Julia package dedicated to simulating quantum many-body systems using Matrix Product States (MPS)
MIT License
128 stars 29 forks source link

Plotting error measures during groundstate searches #105

Closed Gertian closed 5 months ago

Gertian commented 9 months ago

When performing groundstate searches requiring many iterations it is desirable to have some notion of convergence speed to estimate runtime on clusters and better help planning.

I used to have an implementation of this using UnicodePlots.jl which can run in any terminal.

I was thinking about re-implementing this and was wondering how such functionality would fit most elegantly within the current framework. I suspect the finalize function can be used for this ? Alternatively it might be implemented as a verbosity setting.

lkdvos commented 9 months ago

I recently changed the logging within the algorithms to allow for something similar, but haven't gotten around to playing with it some more. They now attach some variables to the log messages, that you could access through a custom logger. This would then be able to be handled with something like a unicode plot, or a progress meter, etc. I'd recommend having a look at LoggingExtras for more information. Of course the finaliser should also allow for this, but I felt like the logging approach was better suited

Gertian commented 8 months ago

This sounds like a better approach indeed. I looked into the finalize thing and this was slightly problematic because the function can only take input from the current state of the GS search

maartenvd commented 8 months ago

Even the finalize approach should work. You can keep track of the history by doing something like:

history = []

function finalize(a,b,c,...) push!(history,a) return ... end

Op do 28 dec 2023 om 13:15 schreef Gertian @.***>:

This sounds like a better approach indeed. I looked into the finalize thing and this was slightly problematic because the function can only take input from the current state of the GS search

— Reply to this email directly, view it on GitHub https://github.com/maartenvd/MPSKit.jl/issues/105#issuecomment-1871111543, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJKVCS7GL4IWT6KQN6VXX3YLVPFLAVCNFSM6AAAAABAT3QM5OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZRGEYTCNJUGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Gertian commented 5 months ago

@maartenvd and @lkdvos

As maarten suggested I ended up fixing this using finalize. In particular we now have :

function finalize_saver(x, f, g, numiter) #x = state, f = costfun(x), g  = gradient(f(x)), numiter = iteration
    @info "I'm also updating the $(status_file) file"
    normgrad = sqrt(GrassmannMPS.inner(x,g,g))                
    open("status_file", "a") do file
        write(file, "sinval = $sinval, iter = $numiter, f = $f \t normgrad = $normgrad > $( sinval*extra_accuracy )\n")
    end
    return x,f,g
end

and then I use external software to read and plot the status_file.

If it's up to me this thread can be closed :+1: