Skip to content

Commit c76f522

Browse files
implement copy fix and test
1 parent 5e67713 commit c76f522

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/operators/mpo.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ DenseMPO(mpo::MPO) = mpo isa DenseMPO ? copy(mpo) : MPO(map(TensorMap, parent(mp
5555
Base.parent(mpo::MPO) = mpo.O
5656
Base.copy(mpo::MPO) = MPO(map(copy, mpo))
5757

58+
Base.copy(mpo::FiniteMPO) = FiniteMPO(map(copy, mpo)) # Explicitly split up Finite and Infinite to ensure proper type after copy
59+
Base.copy(mpo::InfiniteMPO) = InfiniteMPO(map(copy, mpo))
60+
5861
function Base.similar(mpo::MPO{<:MPOTensor}, ::Type{O}, L::Int) where {O<:MPOTensor}
5962
return MPO(similar(parent(mpo), O, L))
6063
end

test/operators.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,18 @@ end
508508
@test expectation_value(psi2, O) dot(psi, psi2) * dot(psi2, psi)
509509
end
510510

511+
@testset "MPO copy behaviour" begin
512+
# testset that checks the fix for issue #288
513+
H = transverse_field_ising()
514+
O = make_time_mpo(H, 0.1, TaylorCluster(2, true, true))
515+
FO = open_boundary_conditions(O, 4)
516+
FH = open_boundary_conditions(H, 4)
517+
518+
# check if the copy of the MPO is the same type as the original
519+
@test typeof(copy(O)) == typeof(O)
520+
@test typeof(copy(FO)) == typeof(FO)
521+
@test typeof(copy(H)) == typeof(H)
522+
@test typeof(copy(FH)) == typeof(FH)
523+
end
524+
511525
end

0 commit comments

Comments
 (0)