Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/operators/mpo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# Utility
# -------
Base.parent(mpo::MPO) = mpo.O
Base.copy(mpo::MPO) = MPO(map(copy, mpo))
Base.copy(mpo::MPO) = MPO(copy.(parent(mpo)))

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

View check run for this annotation

Codecov / codecov/patch

src/operators/mpo.jl#L56

Added line #L56 was not covered by tests

function Base.similar(mpo::MPO{<:MPOTensor}, ::Type{O}, L::Int) where {O<:MPOTensor}
return MPO(similar(parent(mpo), O, L))
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