Skip to content

windowhamiltonian poc#417

Draft
maartenvd wants to merge 1 commit intomainfrom
mvd/windowham
Draft

windowhamiltonian poc#417
maartenvd wants to merge 1 commit intomainfrom
mvd/windowham

Conversation

@maartenvd
Copy link
Copy Markdown
Collaborator

draft pr for a windowhamiltonian type, resolving some pain points from #411

It wasn't possible in the past to correctly create a windowmps environments. The window uses a finitehamiltonian, but then the boundaries require an infinite hamiltonian. This new windowhamiltonian would keep track of the "bath" hamiltonian, and the finite hamiltonian for the window.

Misses full support for the abstractmpo interface, and I think a propagator+window test would be nice to have.

@github-actions
Copy link
Copy Markdown
Contributor

Your PR requires formatting changes to meet the project's style guidelines.
Please consider running Runic (git runic main) to apply these changes.

Click here to view the suggested changes.
diff --git a/src/operators/windowhamiltonian.jl b/src/operators/windowhamiltonian.jl
index 7eed2c4..d39bfc8 100644
--- a/src/operators/windowhamiltonian.jl
+++ b/src/operators/windowhamiltonian.jl
@@ -8,22 +8,22 @@ Acts simalar as just a finite hamiltonian, but we 'remember' the boundary hamilt
 # todo - what is the required interface for abstractmpo?
 # support densempo windows?
 struct WindowMPOHamiltonian{O} <: AbstractMPO{O}
-    left_ham :: InfiniteMPOHamiltonian{O}
-    finite_ham :: FiniteMPOHamiltonian{O}
-    right_ham :: InfiniteMPOHamiltonian{O}
+    left_ham::InfiniteMPOHamiltonian{O}
+    finite_ham::FiniteMPOHamiltonian{O}
+    right_ham::InfiniteMPOHamiltonian{O}
 end
 
 #utility constructor
 function WindowMPOHamiltonian(ham::InfiniteMPOHamiltonian, interval::UnitRange)
-    
+
     # to make sure the interval corresponds with finite_ham, it is important that the unitcell of the left/right hamiltonians is circshifted correctly
-    left_edge = (interval.start-1) % length(ham)
-    left_ham = InfiniteMPOHamiltonian([ham[i] for i in (left_edge-length(ham)+1):left_edge])
-    right_edge = (interval.stop+1)%length(ham)
-    right_ham = InfiniteMPOHamiltonian([ham[i] for i in right_edge:(right_edge+length(ham)-1)])
+    left_edge = (interval.start - 1) % length(ham)
+    left_ham = InfiniteMPOHamiltonian([ham[i] for i in (left_edge - length(ham) + 1):left_edge])
+    right_edge = (interval.stop + 1) % length(ham)
+    right_ham = InfiniteMPOHamiltonian([ham[i] for i in right_edge:(right_edge + length(ham) - 1)])
 
-    finite_ham = FiniteMPOHamiltonian([ham[i] for i in  interval])
-    WindowMPOHamiltonian(left_ham, finite_ham, right_ham)
+    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
@@ -32,5 +32,5 @@ Base.copy(h::WindowMPOHamiltonian) = WindowMPOHamiltonian(copy(h.left_ham), copy
 
 # some basic linalg
 for fun in (:(Base.:+), :(Base.:-), :(Base.:*))
-    @eval $fun(a::WindowMPOHamiltonian,b::WindowMPOHamiltonian) = WindowMPOHamiltonian($fun(a.left_ham,b.left_ham),$fun(a.finite_ham,b.finite_ham),$fun(a.right_ham,b.right_ham))
+    @eval $fun(a::WindowMPOHamiltonian, b::WindowMPOHamiltonian) = WindowMPOHamiltonian($fun(a.left_ham, b.left_ham), $fun(a.finite_ham, b.finite_ham), $fun(a.right_ham, b.right_ham))
 end
diff --git a/test/states/windowmps.jl b/test/states/windowmps.jl
index 2106dab..ab37bba 100644
--- a/test/states/windowmps.jl
+++ b/test/states/windowmps.jl
@@ -63,7 +63,7 @@ using TensorKit: ℙ
 
     e1 = expectation_value(window, (2, 3) => O)
 
-    w_ham = WindowMPOHamiltonian(ham,1:length(window))
+    w_ham = WindowMPOHamiltonian(ham, 1:length(window))
     window, envs, _ = find_groundstate(window, w_ham, DMRG(; verbosity = 0))
 
     e2 = expectation_value(window, (2, 3) => O)

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.

1 participant