Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/operators/mpo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
Base.parent(mpo::MPO) = mpo.O
Base.copy(mpo::MPO) = MPO(map(copy, mpo))

# Explicitly split up Finite and Infinite to ensure proper type after copy
Base.copy(mpo::FiniteMPO) = FiniteMPO(map(copy, mpo))
Base.copy(mpo::InfiniteMPO) = InfiniteMPO(map(copy, mpo))

Check warning on line 60 in src/operators/mpo.jl

View check run for this annotation

Codecov / codecov/patch

src/operators/mpo.jl#L59-L60

Added lines #L59 - L60 were not covered by tests

function Base.similar(mpo::MPO{<:MPOTensor}, ::Type{O}, L::Int) where {O<:MPOTensor}
return MPO(similar(parent(mpo), O, L))
end
Expand Down
14 changes: 14 additions & 0 deletions test/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading