Skip to content

Commit 2db608a

Browse files
committed
fix some tests
1 parent c5f54b3 commit 2db608a

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

test/operators/mpo.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,4 @@ end
120120
@test storagetype(mpo4) == Vector{T}
121121
@test dot(mpo3, mpo4) norm(mpo3)^2 atol = 1.0e-4
122122
end
123-
124123
end

test/operators/mpohamiltonian.jl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ println("
44
----------------------------
55
")
66

7-
using .TestSetup
87
using Test, TestExtras
8+
using Adapt
99
using MPSKit
1010
using MPSKit: GeometryStyle, FiniteChainStyle, InfiniteChainStyle, OperatorStyle, HamiltonianStyle
1111
using TensorKit
@@ -240,3 +240,35 @@ end
240240
h4 = H4 * H4
241241
@test real(expectation_value(ψ2, H4)) >= 0
242242
end
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

Comments
 (0)