@@ -4,8 +4,8 @@ println("
44----------------------------
55" )
66
7- using . TestSetup
87using Test, TestExtras
8+ using Adapt
99using MPSKit
1010using MPSKit: GeometryStyle, FiniteChainStyle, InfiniteChainStyle, OperatorStyle, HamiltonianStyle
1111using TensorKit
240240 h4 = H4 * H4
241241 @test real (expectation_value (ψ2, H4)) >= 0
242242end
243+
244+ @testset " Adapt" for V in (ℂ^ 2 , U1Space (- 1 => 1 , 0 => 1 , 1 => 1 ))
245+ h = rand (Float32, V^ 2 ← V^ 2 )
246+ h += h'
247+
248+ L = 4
249+ H1 = FiniteMPOHamiltonian (
250+ fill (V, L),
251+ ((i, i + 1 ) => h for i in 1 : (L - 1 )). .. ,
252+ ((i, i + 2 ) => h for i in 1 : (L - 2 )). .. ,
253+ ((i, i + 3 ) => h for i in 1 : (L - 3 )). .. ,
254+ )
255+ mps1 = FiniteMPS (physicalspace (H1), oneunit (V))
256+
257+ for T in (Float64, ComplexF64)
258+ H2 = @testinferred adapt (Vector{T}, H1)
259+ @test H2 isa FiniteMPOHamiltonian
260+ @test scalartype (H2) == T
261+ @test storagetype (H2) == Vector{T}
262+ @test expectation_value (mps1, H1) ≈ expectation_value (mps1, H2)
263+ end
264+
265+ H3 = InfiniteMPOHamiltonian (fill (V, L), (1 , 2 ) => h, (1 , 3 ) => h, (1 , 4 ) => h)
266+ mps2 = InfiniteMPS (physicalspace (H3), [oneunit (V)])
267+ for T in (Float64, ComplexF64)
268+ H4 = @testinferred adapt (Vector{T}, H3)
269+ @test H4 isa InfiniteMPOHamiltonian
270+ @test scalartype (H4) == T
271+ @test storagetype (H4) == Vector{T}
272+ @test expectation_value (mps2, H3) ≈ expectation_value (mps2, H4)
273+ end
274+ end
0 commit comments