Skip to content

Commit eb11b37

Browse files
committed
throw errors for non-supporting EnrSpace functions
1 parent 3bd3960 commit eb11b37

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/negativity.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,19 @@ Return the partial transpose of a density matrix ``\rho``, where `mask` is an ar
7171
- `ρ_pt::QuantumObject`: The density matrix with the selected subsystems transposed.
7272
"""
7373
function partial_transpose::QuantumObject{Operator}, mask::Vector{Bool})
74-
if length(mask) != length.dimensions)
75-
throw(ArgumentError("The length of \`mask\` should be equal to the length of \`ρ.dims\`."))
76-
end
77-
return _partial_transpose(ρ, mask)
78-
end
74+
any(s -> s isa EnrSpace, QO.dimensions.to) && throw(ArgumentError("partial_transpose does not support EnrSpace"))
75+
76+
(length(mask) != length.dimensions)) && throw(ArgumentError("The length of \`mask\` should be equal to the length of \`ρ.dims\`."))
7977

80-
# for dense matrices
81-
function _partial_transpose::QuantumObject{Operator}, mask::Vector{Bool})
8278
isa.dimensions, GeneralDimensions) &&
8379
(get_dimensions_to(ρ) != get_dimensions_from(ρ)) &&
8480
throw(ArgumentError("Invalid partial transpose for dims = $(_get_dims_string.dimensions))"))
8581

82+
return _partial_transpose(ρ, mask)
83+
end
84+
85+
# for dense matrices
86+
function _partial_transpose::QuantumObject{Operator}, mask::Vector{Bool})
8687
mask2 = [1 + Int(i) for i in mask]
8788
# mask2 has elements with values equal to 1 or 2
8889
# 1 - the subsystem don't need to be transposed
@@ -107,10 +108,6 @@ function _partial_transpose(
107108
ρ::QuantumObject{Operator,DimsType,<:AbstractSparseArray},
108109
mask::Vector{Bool},
109110
) where {DimsType<:AbstractDimensions}
110-
isa.dimensions, GeneralDimensions) &&
111-
(get_dimensions_to(ρ) != get_dimensions_from(ρ)) &&
112-
throw(ArgumentError("Invalid partial transpose for dims = $(_get_dims_string.dimensions))"))
113-
114111
M, N = size(ρ)
115112
dimsTuple = Tuple(dimensions_to_dims(get_dimensions_to(ρ)))
116113
colptr = ρ.data.colptr

src/qobj/arithmetic_and_attributes.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ Quantum Object: type=Operator() dims=[2] size=(2, 2) ishermitian=true
505505
```
506506
"""
507507
function ptrace(QO::QuantumObject{Ket}, sel::Union{AbstractVector{Int},Tuple})
508+
any(s -> s isa EnrSpace, QO.dimensions.to) && throw(ArgumentError("ptrace does not support EnrSpace"))
509+
508510
_non_static_array_warning("sel", sel)
509511

510512
if length(sel) == 0 # return full trace for empty sel
@@ -527,6 +529,8 @@ end
527529
ptrace(QO::QuantumObject{Bra}, sel::Union{AbstractVector{Int},Tuple}) = ptrace(QO', sel)
528530

529531
function ptrace(QO::QuantumObject{Operator}, sel::Union{AbstractVector{Int},Tuple})
532+
any(s -> s isa EnrSpace, QO.dimensions.to) && throw(ArgumentError("ptrace does not support EnrSpace"))
533+
530534
# TODO: support for special cases when some of the subsystems have same `to` and `from` space
531535
isa(QO.dimensions, GeneralDimensions) &&
532536
(get_dimensions_to(QO) != get_dimensions_from(QO)) &&
@@ -714,6 +718,8 @@ function SparseArrays.permute(
714718
A::QuantumObject{ObjType},
715719
order::Union{AbstractVector{Int},Tuple},
716720
) where {ObjType<:Union{Ket,Bra,Operator}}
721+
any(s -> s isa EnrSpace, A.dimensions.to) && throw(ArgumentError("permute does not support EnrSpace"))
722+
717723
(length(order) != length(A.dimensions)) &&
718724
throw(ArgumentError("The order list must have the same length as the number of subsystems (A.dims)"))
719725

0 commit comments

Comments
 (0)