Skip to content

Commit a327d89

Browse files
Fix MPO copy issue of #288 (#289)
* implement copy fix and test * move comment * apply Lukas suggestion
1 parent 5e67713 commit a327d89

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/operators/mpo.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ DenseMPO(mpo::MPO) = mpo isa DenseMPO ? copy(mpo) : MPO(map(TensorMap, parent(mp
5353
# Utility
5454
# -------
5555
Base.parent(mpo::MPO) = mpo.O
56-
Base.copy(mpo::MPO) = MPO(map(copy, mpo))
56+
Base.copy(mpo::MPO) = MPO(copy.(parent(mpo)))
5757

5858
function Base.similar(mpo::MPO{<:MPOTensor}, ::Type{O}, L::Int) where {O<:MPOTensor}
5959
return MPO(similar(parent(mpo), O, L))

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)