-
Notifications
You must be signed in to change notification settings - Fork 53
Add WindowMPOHamiltonian enabling propagators and dynamical DMRG on WindowMPS #417
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3396ad8
windowhamiltonian poc
maartenvd ea455de
test
maartenvd c8799d2
remove parent
maartenvd 92acded
format
maartenvd a1ed562
::Number
maartenvd bdf1bce
constructor in line with windowhamiltonian
maartenvd 11cb2d5
circshift
maartenvd 2dc3c89
format
maartenvd e75ae1f
attempt at better doc
maartenvd a0b4e37
Fix WindowMPOHamiltonian environments to build finite envs directly
lkdvos 75eda68
Fix WindowMPOHamiltonian linalg, squared-env warnings, and docs
lkdvos 5f018ad
Test WindowMPOHamiltonian addition with distinct summands
lkdvos ad7ba76
Inline _add_finite_window into WindowMPOHamiltonian + and trim comments
lkdvos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # todo - what is the required interface for abstractmpo? | ||
| # support densempo windows? | ||
| """ | ||
| $(TYPEDEF) | ||
|
|
||
| The Hamiltonian counterpart of a [`WindowMPS`](@ref): a finite region embedded between an | ||
| infinite environment to the left and to the right. | ||
| It consists of an infinite Hamiltonian to the left, a finite Hamiltonian in the middle, and | ||
| an infinite Hamiltonian to the right. | ||
|
|
||
| Acts similar to just a finite Hamiltonian, but we "remember" the boundary Hamiltonians. | ||
|
|
||
| ## Fields | ||
|
|
||
| $(TYPEDFIELDS) | ||
|
|
||
| ## Constructors | ||
|
|
||
| WindowMPOHamiltonian(ham::InfiniteMPOHamiltonian, interval::UnitRange) | ||
|
|
||
| Construct a `WindowMPOHamiltonian` by carving a finite `interval` out of an infinite | ||
| Hamiltonian `ham`. | ||
| The finite window consists of the sites in `interval`, while the left and right environments | ||
| are copies of `ham` whose unit cells are circshifted so that they line up with the window | ||
| boundaries. | ||
| """ | ||
| struct WindowMPOHamiltonian{O} <: AbstractMPO{O} | ||
| "Hamiltonian acting on the infinite environment to the left of the window" | ||
| left_ham::InfiniteMPOHamiltonian{O} | ||
| "Hamiltonian acting on the finite window" | ||
| finite_ham::FiniteMPOHamiltonian{O} | ||
| "Hamiltonian acting on the infinite environment to the right of the window" | ||
| right_ham::InfiniteMPOHamiltonian{O} | ||
| end | ||
|
|
||
| function WindowMPOHamiltonian(ham::InfiniteMPOHamiltonian, interval::UnitRange) | ||
| left_edge = (interval.start - 1) % length(ham) | ||
| left_ham = circshift(ham, -left_edge) | ||
| right_edge = (interval.stop + 1) % length(ham) | ||
| right_ham = circshift(ham, -right_edge + 1) | ||
| finite_ham = FiniteMPOHamiltonian([ham[i] for i in interval]) | ||
| return WindowMPOHamiltonian(left_ham, finite_ham, right_ham) | ||
| end | ||
|
|
||
| Base.parent(h::WindowMPOHamiltonian) = h.finite_ham | ||
| Base.copy(h::WindowMPOHamiltonian) = WindowMPOHamiltonian(copy(h.left_ham), copy(h.finite_ham), copy(h.right_ham)) | ||
|
|
||
| function Base.:+(a::WindowMPOHamiltonian, b::WindowMPOHamiltonian) | ||
| # the finite window carries full Jordan virtual spaces at its boundaries, so it has to be | ||
| # block-diagonalized at every site (like an InfiniteMPOHamiltonian) rather than through | ||
| # the regular FiniteMPOHamiltonian addition | ||
| Ha, Hb = a.finite_ham, b.finite_ham | ||
| N = check_length(Ha, Hb) | ||
| finite_ham = similar(parent(Ha)) | ||
| Vtriv = leftunitspace(first(physicalspace(Ha))) | ||
| for i in 1:N | ||
| A = cat(Ha[i].A, Hb[i].A; dims = (1, 4)) | ||
| B = cat(Ha[i].B, Hb[i].B; dims = 1) | ||
| C = cat(Ha[i].C, Hb[i].C; dims = 3) | ||
| D = Ha[i].D + Hb[i].D | ||
|
|
||
| Vleft = ⊞(Vtriv, left_virtualspace(A), Vtriv) | ||
| Vright = ⊞(Vtriv, right_virtualspace(A), Vtriv) | ||
| V = Vleft ⊗ physicalspace(A) ← physicalspace(A) ⊗ Vright | ||
|
|
||
| finite_ham[i] = JordanMPOTensor(V, A, B, C, D) | ||
| end | ||
| return WindowMPOHamiltonian( | ||
| a.left_ham + b.left_ham, FiniteMPOHamiltonian(finite_ham), a.right_ham + b.right_ham | ||
| ) | ||
| end | ||
| function Base.:*(a::WindowMPOHamiltonian, b::WindowMPOHamiltonian) | ||
| return WindowMPOHamiltonian( | ||
| a.left_ham * b.left_ham, a.finite_ham * b.finite_ham, a.right_ham * b.right_ham | ||
| ) | ||
| end | ||
| function VectorInterface.scale(H::WindowMPOHamiltonian, α::Number) | ||
| return WindowMPOHamiltonian( | ||
| scale(H.left_ham, α), scale(H.finite_ham, α), scale(H.right_ham, α) | ||
| ) | ||
| end | ||
|
|
||
| TensorKit.dot( | ||
| bra::WindowMPS, H::WindowMPOHamiltonian, ket::WindowMPS = bra, | ||
| envs = environments(bra, H, ket) | ||
| ) = dot(bra.window, H.finite_ham, ket.window, envs) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| println(" | ||
| --------------------------------- | ||
| | WindowMPOHamiltonian tests | | ||
| --------------------------------- | ||
| ") | ||
|
|
||
| using .TestSetup | ||
| using Test, TestExtras | ||
| using MPSKit | ||
| using TensorKit | ||
| using TensorKit: ℙ | ||
|
|
||
| @testset "WindowMPOHamiltonian" begin | ||
| # a uniform state, represented with a two-site unit cell, so that carving out a window | ||
| # at different offsets exercises the (non-trivial) circshift alignment of the infinite | ||
| # environments while the physics stays translationally invariant. | ||
| H1 = force_planar(transverse_field_ising(; g = 1.5)) | ||
| gs1, = find_groundstate(InfiniteMPS([ℙ^2], [ℙ^12]), H1, VUMPS(; verbosity = 0)) | ||
| gs = repeat(gs1, 2) | ||
| H = repeat(H1, 2) | ||
|
|
||
| L = 6 | ||
|
|
||
| @testset "interval offset (circshift)" begin | ||
| # the window energy must be independent of the offset for a uniform state | ||
| energies = map((1:L, 2:(L + 1), 3:(L + 2))) do interval | ||
| ψ = WindowMPS(gs, interval) | ||
| Hw = WindowMPOHamiltonian(H, interval) | ||
| @test length(Hw) == length(interval) | ||
| return expectation_value(ψ, Hw) | ||
| end | ||
| @test energies[1] ≈ energies[2] atol = 1.0e-8 | ||
| @test energies[1] ≈ energies[3] atol = 1.0e-8 | ||
| end | ||
|
|
||
| @testset "linear algebra" begin | ||
| ψ = WindowMPS(gs, 1:L) | ||
| Hw = WindowMPOHamiltonian(H, 1:L) | ||
| e = expectation_value(ψ, Hw) | ||
|
|
||
| @test expectation_value(ψ, Hw + Hw) ≈ 2 * e atol = 1.0e-8 | ||
| @test expectation_value(ψ, Hw - Hw) ≈ 0 atol = 1.0e-8 | ||
| @test expectation_value(ψ, 3 * Hw) ≈ 3 * e atol = 1.0e-8 | ||
| @test expectation_value(ψ, Hw * 3) ≈ 3 * e atol = 1.0e-8 | ||
| @test expectation_value(ψ, -Hw) ≈ -e atol = 1.0e-8 | ||
| end | ||
|
|
||
| @testset "distinct summands" begin | ||
| # add two genuinely different Hamiltonians: the ZZ Ising string has a single bulk | ||
| # level while the XY hopping needs two, so the boundary/bulk virtual spaces of the | ||
| # two summands differ and have to be block-diagonalized consistently. | ||
| ψ = WindowMPS(gs1, 1:L) | ||
| Ha = WindowMPOHamiltonian(H1, 1:L) | ||
| Hb = WindowMPOHamiltonian(force_planar(XY_model(; g = 0.7)), 1:L) | ||
| @test right_virtualspace(Ha.finite_ham, 3) != right_virtualspace(Hb.finite_ham, 3) | ||
|
|
||
| ea = expectation_value(ψ, Ha) | ||
| eb = expectation_value(ψ, Hb) | ||
| @test expectation_value(ψ, Ha + Hb) ≈ ea + eb atol = 1.0e-8 | ||
| @test expectation_value(ψ, Hb + Ha) ≈ ea + eb atol = 1.0e-8 | ||
| @test expectation_value(ψ, Ha - Hb) ≈ ea - eb atol = 1.0e-8 | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.