Skip to content
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

Fix truncate! function #254

Merged
merged 12 commits into from
Nov 20, 2024
Merged

Fix truncate! function #254

merged 12 commits into from
Nov 20, 2024

Conversation

jofrevalles
Copy link
Member

@jofrevalles jofrevalles commented Nov 19, 2024

Summary

This PR resolves a bug found in the truncate! function that erroed when maxdim kwarg was larger than the size of the bond that was about to truncate. In a similar way, it also erroed when the threshold was lower than the smaller element in the spectrum that was used to truncate.

Moreover, we fixed the mixed_canonize! function, since previously did not work as the truncate! function expected for MPS with MixedCanonical forms. We also fixed an unnecessary canonization step in the truncate! for Canonical forms.

Example

Without this PR:

julia> using Tenet; using Test; using LinearAlgebra

julia> gate = Quantum(reshape(LinearAlgebra.I(4), 2, 2, 2, 2), [site"2", site"3", site"2'", site"3'"])
Quantum (inputs=2, outputs=2)

julia> ψ = MPS([rand(2, 2), rand(2, 2, 2), rand(2, 2, 2), rand(2, 2)])
MPS (inputs=0, outputs=4)

julia> ψ = deepcopy(ψ)
MPS (inputs=0, outputs=4)

julia> canonize!(ψ)
MPS (inputs=0, outputs=4)

julia> evolved = evolve!(deepcopy(ψ), gate; maxdim=10)
spectrum = [7.129434737170108, 1.2106678577680343, 3.16516617082361e-16, 9.749816418484561e-18]
ERROR: BoundsError: attempt to access 2×2×4 Array{Float64, 3} at index [1:2, 1:2, 1:10]
Stacktrace: ....

julia> evolved = evolve!(deepcopy(ψ), gate; threshold=1e-100)
ERROR: MethodError: no method matching -(::Nothing, ::Int64)
The function `-` exists, but no method is defined for this combination of argument types.

Closest candidates are: ...

Everything now works, and we extended the tests to cover for this changes.

src/Ansatz.jl Show resolved Hide resolved
src/MPS.jl Outdated Show resolved Hide resolved
src/MPS.jl Outdated Show resolved Hide resolved
src/Ansatz.jl Outdated Show resolved Hide resolved
Copy link
Contributor

@starsfordummies starsfordummies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Copy link
Member

@mofeing mofeing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything perfect! Just one suggestion to remove .+ (0,0) because it does nothing.

src/MPS.jl Outdated Show resolved Hide resolved
@jofrevalles jofrevalles merged commit 4b8c356 into master Nov 20, 2024
4 of 5 checks passed
@jofrevalles jofrevalles deleted the fix/truncate! branch November 20, 2024 11:48
jofrevalles added a commit that referenced this pull request Nov 20, 2024
* Fix truncate function and add small test

* Fix mixed_canonize! function

* Add form tests

* Format code

* Fix code

* Fix orthog_center field in MixedCanonical form

* Enhance mixed_canonize! tests

* Add recanonize kwarg for truncate(::Canonical, ...) function

* Small fixes on check_form functions

* Small fixes on tests

* Format code

* Add comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants