-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add evolve!
for evolution of an MPS
with an MPO
#264
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #264 +/- ##
==========================================
+ Coverage 79.59% 80.47% +0.88%
==========================================
Files 32 34 +2
Lines 2068 2182 +114
==========================================
+ Hits 1646 1756 +110
- Misses 422 426 +4 ☔ View full report in Codecov by Sentry. |
If `threshold` or `maxdim` are not `nothing`, the tensors are truncated after each sweep at the proper value. | ||
""" | ||
function evolve!(ψ::AbstractAnsatz, mpo::AbstractMPO; threshold=nothing, maxdim=nothing, normalize=true) | ||
evolve!(form(ψ), ψ, mpo; threshold, maxdim, normalize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@starsfordummies Tomorrow I will add here the replace!
so this evolve!
function does not change the output indices, after that, we can merge!
@starsfordummies Okay, I added the For me, this PR is ready to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! If you haven't yet, you could add an evolve() function so that you're not forced to do it inplace, other than that looks great to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great! thanks! this was very needed
old_norm = norm(ψ) | ||
if isnothing(bond) # Normalize all λ tensors | ||
for i in 1:(nsites(ψ) - 1) | ||
λ = tensors(ψ; between=(Site(i), Site(i + 1))) | ||
replace!(ψ, λ => λ ./ norm(λ)^(1 / (nsites(ψ) - 1))) | ||
replace!(ψ, λ => λ ./ old_norm^(1 / (nsites(ψ) - 1))) | ||
end | ||
else | ||
λ = tensors(ψ; between=bond) | ||
replace!(ψ, λ => λ ./ norm(λ)) | ||
replace!(ψ, λ => λ ./ old_norm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so in reality, there's no need for this because norm(λ)
will only be computed once as it already is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nop, you need the norm
of the full mps
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already tried that but fails on some truncate
tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh i see the difference now, I thought it was the same norm
call
src/MPS.jl
Outdated
for i in nsites(ψ):-1:2 | ||
canonize_site!(ψ, Site(i); direction=:left, method=:svd) | ||
end | ||
|
||
# left-to-right SVD sweep, get left-canonical tensors and singular values and truncate | ||
for i in 1:(nsites(ψ) - 1) | ||
canonize_site!(ψ, Site(i); direction=:right, method=:svd) | ||
(!isnothing(threshold) || !isnothing(maxdim)) && | ||
truncate!(ψ, [Site(i), Site(i + 1)]; threshold, maxdim, normalize, compute_local_svd=false) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you can replace this with mixed_canonize!
to the left-most site and reuse the method for MixedCanonical
for i in nsites(ψ):-1:2 | |
canonize_site!(ψ, Site(i); direction=:left, method=:svd) | |
end | |
# left-to-right SVD sweep, get left-canonical tensors and singular values and truncate | |
for i in 1:(nsites(ψ) - 1) | |
canonize_site!(ψ, Site(i); direction=:right, method=:svd) | |
(!isnothing(threshold) || !isnothing(maxdim)) && | |
truncate!(ψ, [Site(i), Site(i + 1)]; threshold, maxdim, normalize, compute_local_svd=false) | |
end | |
mixed_canonize!(ψ, site"1") | |
truncate_sweep(ψ; threshold, maxdim, normalize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you can't do this. I specifically created this function because in the Canonical
form you do not contract the lambdas but still truncate them. This is different from the other methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, i want to better understand this but let's merge it and refactor it later (if we need)
if !isnothing(threshold) || !isnothing(maxdim) | ||
truncate_sweep!(Canonical(), ψ; threshold, maxdim, normalize) | ||
else | ||
normalize && canonize!(ψ; normalize) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need to normalize if you don't truncate?
also, for this case (i.e. Canonical
form) you will canonize 2 times if you truncate and normalize (1 in truncate_sweep
for recanonization and another here for normalization)
if !isnothing(threshold) || !isnothing(maxdim) | |
truncate_sweep!(Canonical(), ψ; threshold, maxdim, normalize) | |
else | |
normalize && canonize!(ψ; normalize) | |
end | |
if !isnothing(threshold) || !isnothing(maxdim) | |
truncate_sweep!(Canonical(), ψ; threshold, maxdim, normalize) | |
normalize && canonize!(ψ; normalize) | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this. This is not the case, you don't need to normalize
if you already normalize the bond that you truncate.
And yes, you might want to normalize if you don't truncate if the mpo
is not unitary and evolves the ψ
out of norm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would you want to normalize here a TN that it's not already normalized? but ok, I see that both things could be understandable from a semantics point of view
let's merge, discuss on Monday and refactor it if we need
Okay, @mofeing I removed some unnecessary |
* Add evolve! function for an MPS with an MPO * Add tests for MPS-MPO evolution * Remove unnecessary @show * Add comment * Fix kwarg handling on truncate! function * Fix normalize! for Canonical form and small fixes on evolve! with MPO * Extend evolve!(mps, mpo) tests * Format code * Remove unnecessary kwarg * Refactor code so it is easier to extend for other canonical forms * Fix comment * Enhance tests * Add reset_index kwarg * Update tests * Format code * Remove unnecessary Quantum functions, add docstring for truncate_sweep! * Format code * Remove stale function
Summary
This PR enhances the
evolve!
to handle the evolution of anMPS
with anMPO
in different canonical forms. Additionally, it includes new test cases to verify the correctness of the evolution functions.mps
. This way things are easier to check if works properly.Form
s do not need to change theevolve!
funciton, but just extend it as they need.maxdim
,threshold
? I don't know.@starsfordummies Please take a look and tell me what do you think!
Also we should take a look at issue #238 (which asks to extend
mixed_canonize!
so it dispatches onForm
). So if we already have anmps
that is inMixedCanonical
, there is no need to do the full sweep if we just want to change the ortogonality center.Example