@@ -45,6 +45,7 @@ vspaces = (ℙ^10, Rep[U₁]((0 => 20)), Rep[SU₂](1 // 2 => 10, 3 // 2 => 5, 5
4545 mps₁ = FiniteMPS (ψ₁)
4646
4747 @test convert (TensorMap, mpo₁ * mps₁) ≈ O₁ * ψ₁
48+ @test mpo₁ * ψ₁ ≈ O₁ * ψ₁
4849
4950 @test dot (mps₁, mpo₁, mps₁) ≈ dot (ψ₁, O₁, ψ₁)
5051 @test dot (mps₁, mpo₁, mps₁) ≈ dot (mps₁, mpo₁ * mps₁)
6061
6162@testset " Finite MPOHamiltonian" begin
6263 L = 3
63- lattice = fill (ℂ^ 2 , L)
64- O₁ = rand (ComplexF64, ℂ^ 2 , ℂ^ 2 )
65- E = id (storagetype (O₁), domain (O₁))
66- O₂ = rand (ComplexF64, ℂ^ 2 * ℂ^ 2 , ℂ^ 2 * ℂ^ 2 )
67-
68- H1 = FiniteMPOHamiltonian (lattice, i => O₁ for i in 1 : L)
69- H2 = FiniteMPOHamiltonian (lattice, (i, i + 1 ) => O₂ for i in 1 : (L - 1 ))
70- H3 = FiniteMPOHamiltonian (lattice, 1 => O₁, (2 , 3 ) => O₂, (1 , 3 ) => O₂)
71-
72- # check if constructor works by converting back to tensormap
73- H1_tm = convert (TensorMap, H1)
74- operators = vcat (fill (E, L - 1 ), O₁)
75- @test H1_tm ≈ mapreduce (+ , 1 : L) do i
76- return reduce (⊗ , circshift (operators, i))
77- end
78- operators = vcat (fill (E, L - 2 ), O₂)
79- @test convert (TensorMap, H2) ≈ mapreduce (+ , 1 : (L - 1 )) do i
80- return reduce (⊗ , circshift (operators, i))
64+ T = ComplexF64
65+ for V in (ℂ^ 2 , U1Space (0 => 1 , 1 => 1 ))
66+ lattice = fill (V, L)
67+ O₁ = rand (T, V, V)
68+ E = id (storagetype (O₁), domain (O₁))
69+ O₂ = rand (T, V^ 2 ← V^ 2 )
70+
71+ H1 = FiniteMPOHamiltonian (lattice, i => O₁ for i in 1 : L)
72+ H2 = FiniteMPOHamiltonian (lattice, (i, i + 1 ) => O₂ for i in 1 : (L - 1 ))
73+ H3 = FiniteMPOHamiltonian (lattice, 1 => O₁, (2 , 3 ) => O₂, (1 , 3 ) => O₂)
74+
75+ # check if constructor works by converting back to tensormap
76+ H1_tm = convert (TensorMap, H1)
77+ operators = vcat (fill (E, L - 1 ), O₁)
78+ @test H1_tm ≈ mapreduce (+ , 1 : L) do i
79+ return reduce (⊗ , circshift (operators, i))
80+ end
81+ operators = vcat (fill (E, L - 2 ), O₂)
82+ @test convert (TensorMap, H2) ≈ mapreduce (+ , 1 : (L - 1 )) do i
83+ return reduce (⊗ , circshift (operators, i))
84+ end
85+ @test convert (TensorMap, H3) ≈
86+ O₁ ⊗ E ⊗ E + E ⊗ O₂ + permute (O₂ ⊗ E, ((1 , 3 , 2 ), (4 , 6 , 5 )))
87+
88+ # check if adding terms on the same site works
89+ single_terms = Iterators. flatten (Iterators. repeated ((i => O₁ / 2 for i in 1 : L), 2 ))
90+ H4 = FiniteMPOHamiltonian (lattice, single_terms)
91+ @test H4 ≈ H1 atol = 1e-6
92+ double_terms = Iterators. flatten (Iterators. repeated (((i, i + 1 ) => O₂ / 2
93+ for i in 1 : (L - 1 )), 2 ))
94+ H5 = FiniteMPOHamiltonian (lattice, double_terms)
95+ @test H5 ≈ H2 atol = 1e-6
96+
97+ # test linear algebra
98+ @test H1 ≈
99+ FiniteMPOHamiltonian (lattice, 1 => O₁) +
100+ FiniteMPOHamiltonian (lattice, 2 => O₁) +
101+ FiniteMPOHamiltonian (lattice, 3 => O₁)
102+ @test 0.8 * H1 + 0.2 * H1 ≈ H1 atol = 1e-6
103+ @test convert (TensorMap, H1 + H2) ≈ convert (TensorMap, H1) + convert (TensorMap, H2) atol = 1e-6
104+
105+ # test dot and application
106+ state = rand (T, prod (lattice))
107+ mps = FiniteMPS (state)
108+
109+ @test convert (TensorMap, H1 * mps) ≈ H1_tm * state
110+ @test H1 * state ≈ H1_tm * state
111+ @test dot (mps, H2, mps) ≈ dot (mps, H2 * mps)
112+
113+ # test constructor from dictionary with mixed linear and Cartesian lattice indices as keys
114+ grid = square = fill (V, 3 , 3 )
115+
116+ local_operators = Dict ((I,) => O₁ for I in eachindex (grid))
117+ I_vertical = CartesianIndex (1 , 0 )
118+ vertical_operators = Dict ((I, I + I_vertical) => O₂
119+ for I in eachindex (IndexCartesian (), square)
120+ if I[1 ] < size (square, 1 ))
121+ operators = merge (local_operators, vertical_operators)
122+ H4 = FiniteMPOHamiltonian (grid, operators)
123+
124+ @test H4 ≈
125+ FiniteMPOHamiltonian (grid, local_operators) +
126+ FiniteMPOHamiltonian (grid, vertical_operators)
81127 end
82- @test convert (TensorMap, H3) ≈
83- O₁ ⊗ E ⊗ E + E ⊗ O₂ + permute (O₂ ⊗ E, ((1 , 3 , 2 ), (4 , 6 , 5 )))
84-
85- # check if adding terms on the same site works
86- single_terms = Iterators. flatten (Iterators. repeated ((i => O₁ / 2 for i in 1 : L), 2 ))
87- H4 = FiniteMPOHamiltonian (lattice, single_terms)
88- @test H4 ≈ H1 atol = 1e-6
89- double_terms = Iterators. flatten (Iterators. repeated (((i, i + 1 ) => O₂ / 2
90- for i in 1 : (L - 1 )), 2 ))
91- H5 = FiniteMPOHamiltonian (lattice, double_terms)
92- @test H5 ≈ H2 atol = 1e-6
93-
94- # test linear algebra
95- @test H1 ≈
96- FiniteMPOHamiltonian (lattice, 1 => O₁) +
97- FiniteMPOHamiltonian (lattice, 2 => O₁) +
98- FiniteMPOHamiltonian (lattice, 3 => O₁)
99- @test 0.8 * H1 + 0.2 * H1 ≈ H1 atol = 1e-6
100- @test convert (TensorMap, H1 + H2) ≈ convert (TensorMap, H1) + convert (TensorMap, H2) atol = 1e-6
101-
102- # test dot and application
103- state = rand (ComplexF64, prod (lattice))
104- mps = FiniteMPS (state)
105-
106- @test convert (TensorMap, H1 * mps) ≈ H1_tm * state
107- @test dot (mps, H2, mps) ≈ dot (mps, H2 * mps)
108-
109- # test constructor from dictionary with mixed linear and Cartesian lattice indices as keys
110- grid = square = fill (ℂ^ 2 , 3 , 3 )
111-
112- local_operators = Dict ((I,) => O₁ for I in eachindex (grid))
113- I_vertical = CartesianIndex (1 , 0 )
114- vertical_operators = Dict ((I, I + I_vertical) => O₂
115- for I in eachindex (IndexCartesian (), square)
116- if I[1 ] < size (square, 1 ))
117- operators = merge (local_operators, vertical_operators)
118- H4 = FiniteMPOHamiltonian (grid, operators)
119-
120- @test H4 ≈
121- FiniteMPOHamiltonian (grid, local_operators) +
122- FiniteMPOHamiltonian (grid, vertical_operators)
123128end
124129
125130@testset " InfiniteMPOHamiltonian $(sectortype (pspace)) " for (pspace, Dspace) in
0 commit comments