You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/qobj/arithmetic_and_attributes.jl
+58-26Lines changed: 58 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -475,8 +475,9 @@ proj(ψ::QuantumObject{<:AbstractArray{T},BraQuantumObject}) where {T} = ψ' *
475
475
@docraw"""
476
476
ptrace(QO::QuantumObject, sel)
477
477
478
-
[Partial trace](https://en.wikipedia.org/wiki/Partial_trace) of a quantum state `QO` leaving only the dimensions
479
-
with the indices present in the `sel` vector.
478
+
[Partial trace](https://en.wikipedia.org/wiki/Partial_trace) of a quantum state `QO` leaving only the dimensions with the indices present in the `sel` vector.
479
+
480
+
Note that this function will always return [`Operator`](@ref). No matter the input [`QuantumObject`](@ref) is a [`Ket`](@ref), [`Bra`](@ref), or [`Operator`](@ref).
480
481
481
482
# Examples
482
483
Two qubits in the state ``\ket{\psi} = \ket{e,g}``:
throw(ArgumentError("The argument $argname must be a Tuple or a StaticVector of non-zero length."))
223
-
_non_static_array_warning(argname, arg::Union{SVector{N,T},MVector{N,T},NTuple{N,T}}) where {N,T} =nothing
224
-
_non_static_array_warning(argname, arg::AbstractVector{T}) where {T} =
225
-
@warn"The argument $argname should be a Tuple or a StaticVector for better performance. Try to use `$argname = $(Tuple(arg))` or `$argname = SVector("*
226
-
join(arg, ", ") *
227
-
")` instead of `$argname = $arg`." maxlog =1
228
-
229
218
function_check_dims(dims::Union{AbstractVector{T},NTuple{N,T}}) where {T<:Integer,N}
throw(ArgumentError("The argument $argname must be a Tuple or a StaticVector of non-zero length."))
63
+
_non_static_array_warning(argname, arg::Union{SVector{N,T},MVector{N,T},NTuple{N,T}}) where {N,T} =nothing
64
+
_non_static_array_warning(argname, arg::AbstractVector{T}) where {T} =
65
+
@warn"The argument $argname should be a Tuple or a StaticVector for better performance. Try to use `$argname = $(Tuple(arg))` or `$argname = SVector("*
@testptrace(ψtotal, sel) ≈tensor([ket2dm(ψlist[i]) for i in sel]...)
627
+
@testptrace(ρtotal, sel) ≈tensor([ρlist[i] for i in sel]...)
628
+
end
629
+
end
630
+
@testptrace(ψtotal, (1, 3, 4)) ≈ptrace(ψtotal, (4, 3, 1)) # check sort of sel
631
+
@testptrace(ρtotal, (1, 3, 4)) ≈ptrace(ρtotal, (3, 1, 4)) # check sort of sel
632
+
@test_logs (
633
+
:warn,
634
+
"The argument sel should be a Tuple or a StaticVector for better performance. Try to use `sel = (1, 2)` or `sel = SVector(1, 2)` instead of `sel = [1, 2]`.",
635
+
) ptrace(ψtotal, [1, 2])
636
+
@test_logs (
637
+
:warn,
638
+
"The argument sel should be a Tuple or a StaticVector for better performance. Try to use `sel = (1, 2)` or `sel = SVector(1, 2)` instead of `sel = [1, 2]`.",
0 commit comments