diff --git a/src/operators/mpo.jl b/src/operators/mpo.jl index af59c3578..c97ba0463 100644 --- a/src/operators/mpo.jl +++ b/src/operators/mpo.jl @@ -53,7 +53,7 @@ DenseMPO(mpo::MPO) = mpo isa DenseMPO ? copy(mpo) : MPO(map(TensorMap, parent(mp # Utility # ------- Base.parent(mpo::MPO) = mpo.O -Base.copy(mpo::MPO) = MPO(map(copy, mpo)) +Base.copy(mpo::MPO) = MPO(copy.(parent(mpo))) function Base.similar(mpo::MPO{<:MPOTensor}, ::Type{O}, L::Int) where {O<:MPOTensor} return MPO(similar(parent(mpo), O, L)) diff --git a/test/operators.jl b/test/operators.jl index 6be9691f0..010c485c0 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -508,4 +508,18 @@ end @test expectation_value(psi2, O) ≈ dot(psi, psi2) * dot(psi2, psi) end +@testset "MPO copy behaviour" begin + # testset that checks the fix for issue #288 + H = transverse_field_ising() + O = make_time_mpo(H, 0.1, TaylorCluster(2, true, true)) + FO = open_boundary_conditions(O, 4) + FH = open_boundary_conditions(H, 4) + + # check if the copy of the MPO is the same type as the original + @test typeof(copy(O)) == typeof(O) + @test typeof(copy(FO)) == typeof(FO) + @test typeof(copy(H)) == typeof(H) + @test typeof(copy(FH)) == typeof(FH) +end + end