Skip to content

Commit dcf059b

Browse files
Remove synonyms for QuantumObject types
1 parent 2b5e86e commit dcf059b

35 files changed

+369
-419
lines changed

docs/src/getting_started/type_stability.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ and its type is
158158
obj_type = typeof(σx_2)
159159
```
160160

161-
This is exactly what the Julia compiler sees: it is a [`QuantumObject`](@ref), composed by a field of type `SparseMatrixCSC{ComplexF64, Int64}` (i.e., the 8x8 matrix containing the Pauli matrix, tensored with the identity matrices of the other two qubits). Then, we can also see that it is a [`OperatorQuantumObject`](@ref), with `3` subsystems in total. Hence, just looking at the type of the object, the compiler has all the information it needs to generate a specialized version of the functions.
161+
This is exactly what the Julia compiler sees: it is a [`QuantumObject`](@ref), composed by a field of type `SparseMatrixCSC{ComplexF64, Int64}` (i.e., the 8x8 matrix containing the Pauli matrix, tensored with the identity matrices of the other two qubits). Then, we can also see that it is a [`Operator`](@ref), with `3` subsystems in total. Hence, just looking at the type of the object, the compiler has all the information it needs to generate a specialized version of the functions.
162162

163163
Let's see more in the details all the internal fields of the [`QuantumObject`](@ref) type:
164164

@@ -174,7 +174,6 @@ fieldnames(obj_type)
174174
σx_2.type
175175
```
176176

177-
[`Operator`](@ref) is a synonym for [`OperatorQuantumObject`](@ref).
178177

179178
```@example type-stability
180179
σx_2.dims

docs/src/resources/api.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,11 @@ Space
2121
Dimensions
2222
GeneralDimensions
2323
AbstractQuantumObject
24-
BraQuantumObject
2524
Bra
26-
KetQuantumObject
2725
Ket
28-
OperatorQuantumObject
2926
Operator
30-
OperatorBraQuantumObject
3127
OperatorBra
32-
OperatorKetQuantumObject
3328
OperatorKet
34-
SuperOperatorQuantumObject
3529
SuperOperator
3630
QuantumObject
3731
QuantumObjectEvolution

ext/QuantumToolboxMakieExt.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function QuantumToolbox.plot_wigner(
5454
location::Union{GridPosition,Nothing} = nothing,
5555
colorbar::Bool = false,
5656
kwargs...,
57-
) where {OpType<:Union{BraQuantumObject,KetQuantumObject,OperatorQuantumObject}}
57+
) where {OpType<:Union{Bra,Ket,Operator}}
5858
QuantumToolbox.getVal(projection) == :two_dim ||
5959
QuantumToolbox.getVal(projection) == :three_dim ||
6060
throw(ArgumentError("Unsupported projection: $projection"))
@@ -84,7 +84,7 @@ function _plot_wigner(
8484
location::Union{GridPosition,Nothing},
8585
colorbar::Bool;
8686
kwargs...,
87-
) where {OpType<:Union{BraQuantumObject,KetQuantumObject,OperatorQuantumObject}}
87+
) where {OpType<:Union{Bra,Ket,Operator}}
8888
fig, location = _getFigAndLocation(location)
8989

9090
lyt = GridLayout(location)
@@ -117,7 +117,7 @@ function _plot_wigner(
117117
location::Union{GridPosition,Nothing},
118118
colorbar::Bool;
119119
kwargs...,
120-
) where {OpType<:Union{BraQuantumObject,KetQuantumObject,OperatorQuantumObject}}
120+
) where {OpType<:Union{Bra,Ket,Operator}}
121121
fig, location = _getFigAndLocation(location)
122122

123123
lyt = GridLayout(location)
@@ -148,7 +148,7 @@ end
148148
unit_y_range::Bool = true,
149149
location::Union{GridPosition,Nothing} = nothing,
150150
kwargs...
151-
) where {SType<:Union{KetQuantumObject,OperatorQuantumObject}}
151+
) where {SType<:Union{Ket,Operator}}
152152
153153
Plot the [Fock state](https://en.wikipedia.org/wiki/Fock_state) distribution of `ρ`.
154154
@@ -178,7 +178,7 @@ function QuantumToolbox.plot_fock_distribution(
178178
unit_y_range::Bool = true,
179179
location::Union{GridPosition,Nothing} = nothing,
180180
kwargs...,
181-
) where {SType<:Union{BraQuantumObject,KetQuantumObject,OperatorQuantumObject}}
181+
) where {SType<:Union{Bra,Ket,Operator}}
182182
return _plot_fock_distribution(
183183
library,
184184
ρ;
@@ -196,7 +196,7 @@ function _plot_fock_distribution(
196196
unit_y_range::Bool = true,
197197
location::Union{GridPosition,Nothing} = nothing,
198198
kwargs...,
199-
) where {SType<:Union{BraQuantumObject,KetQuantumObject,OperatorQuantumObject}}
199+
) where {SType<:Union{Bra,Ket,Operator}}
200200
ρ = ket2dm(ρ)
201201
D = prod.dims)
202202
isapprox(tr(ρ), 1, atol = 1e-4) || (@warn "The input ρ should be normalized.")

src/correlations.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ function correlation_3op_2t(
2929
tlist::AbstractVector,
3030
τlist::AbstractVector,
3131
c_ops::Union{Nothing,AbstractVector,Tuple},
32-
A::QuantumObject{OperatorQuantumObject},
33-
B::QuantumObject{OperatorQuantumObject},
34-
C::QuantumObject{OperatorQuantumObject};
32+
A::QuantumObject{Operator},
33+
B::QuantumObject{Operator},
34+
C::QuantumObject{Operator};
3535
kwargs...,
3636
) where {
37-
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
38-
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
37+
HOpType<:Union{Operator,SuperOperator},
38+
StateOpType<:Union{Ket,Operator},
3939
}
4040
# check tlist and τlist
4141
_check_correlation_time_list(tlist)
@@ -78,13 +78,13 @@ function correlation_3op_1t(
7878
ψ0::Union{Nothing,QuantumObject{StateOpType}},
7979
τlist::AbstractVector,
8080
c_ops::Union{Nothing,AbstractVector,Tuple},
81-
A::QuantumObject{OperatorQuantumObject},
82-
B::QuantumObject{OperatorQuantumObject},
83-
C::QuantumObject{OperatorQuantumObject};
81+
A::QuantumObject{Operator},
82+
B::QuantumObject{Operator},
83+
C::QuantumObject{Operator};
8484
kwargs...,
8585
) where {
86-
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
87-
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
86+
HOpType<:Union{Operator,SuperOperator},
87+
StateOpType<:Union{Ket,Operator},
8888
}
8989
corr = correlation_3op_2t(H, ψ0, [0], τlist, c_ops, A, B, C; kwargs...)
9090

@@ -114,13 +114,13 @@ function correlation_2op_2t(
114114
tlist::AbstractVector,
115115
τlist::AbstractVector,
116116
c_ops::Union{Nothing,AbstractVector,Tuple},
117-
A::QuantumObject{OperatorQuantumObject},
118-
B::QuantumObject{OperatorQuantumObject};
117+
A::QuantumObject{Operator},
118+
B::QuantumObject{Operator};
119119
reverse::Bool = false,
120120
kwargs...,
121121
) where {
122-
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
123-
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
122+
HOpType<:Union{Operator,SuperOperator},
123+
StateOpType<:Union{Ket,Operator},
124124
}
125125
C = eye(prod(H.dimensions), dims = H.dimensions)
126126
if reverse
@@ -153,13 +153,13 @@ function correlation_2op_1t(
153153
ψ0::Union{Nothing,QuantumObject{StateOpType}},
154154
τlist::AbstractVector,
155155
c_ops::Union{Nothing,AbstractVector,Tuple},
156-
A::QuantumObject{OperatorQuantumObject},
157-
B::QuantumObject{OperatorQuantumObject};
156+
A::QuantumObject{Operator},
157+
B::QuantumObject{Operator};
158158
reverse::Bool = false,
159159
kwargs...,
160160
) where {
161-
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
162-
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
161+
HOpType<:Union{Operator,SuperOperator},
162+
StateOpType<:Union{Ket,Operator},
163163
}
164164
corr = correlation_2op_2t(H, ψ0, [0], τlist, c_ops, A, B; reverse = reverse, kwargs...)
165165

src/deprecated.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ correlation_3op_2t(
3333
ψ0::QuantumObject{StateOpType},
3434
t_l::AbstractVector,
3535
τ_l::AbstractVector,
36-
A::QuantumObject{OperatorQuantumObject},
37-
B::QuantumObject{OperatorQuantumObject},
38-
C::QuantumObject{OperatorQuantumObject},
36+
A::QuantumObject{Operator},
37+
B::QuantumObject{Operator},
38+
C::QuantumObject{Operator},
3939
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
4040
kwargs...,
4141
) where {
42-
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
43-
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
42+
HOpType<:Union{Operator,SuperOperator},
43+
StateOpType<:Union{Ket,Operator},
4444
} = error(
4545
"The parameter order of `correlation_3op_2t` has been changed, please use `?correlation_3op_2t` to check the updated docstring.",
4646
)
@@ -49,14 +49,14 @@ correlation_3op_1t(
4949
H::QuantumObject{HOpType},
5050
ψ0::QuantumObject{StateOpType},
5151
τ_l::AbstractVector,
52-
A::QuantumObject{OperatorQuantumObject},
53-
B::QuantumObject{OperatorQuantumObject},
54-
C::QuantumObject{OperatorQuantumObject},
52+
A::QuantumObject{Operator},
53+
B::QuantumObject{Operator},
54+
C::QuantumObject{Operator},
5555
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
5656
kwargs...,
5757
) where {
58-
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
59-
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
58+
HOpType<:Union{Operator,SuperOperator},
59+
StateOpType<:Union{Ket,Operator},
6060
} = error(
6161
"The parameter order of `correlation_3op_1t` has been changed, please use `?correlation_3op_1t` to check the updated docstring.",
6262
)
@@ -66,14 +66,14 @@ correlation_2op_2t(
6666
ψ0::QuantumObject{StateOpType},
6767
t_l::AbstractVector,
6868
τ_l::AbstractVector,
69-
A::QuantumObject{OperatorQuantumObject},
70-
B::QuantumObject{OperatorQuantumObject},
69+
A::QuantumObject{Operator},
70+
B::QuantumObject{Operator},
7171
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
7272
reverse::Bool = false,
7373
kwargs...,
7474
) where {
75-
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
76-
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
75+
HOpType<:Union{Operator,SuperOperator},
76+
StateOpType<:Union{Ket,Operator},
7777
} = error(
7878
"The parameter order of `correlation_2op_2t` has been changed, please use `?correlation_2op_2t` to check the updated docstring.",
7979
)
@@ -82,14 +82,14 @@ correlation_2op_1t(
8282
H::QuantumObject{HOpType},
8383
ψ0::QuantumObject{StateOpType},
8484
τ_l::AbstractVector,
85-
A::QuantumObject{OperatorQuantumObject},
86-
B::QuantumObject{OperatorQuantumObject},
85+
A::QuantumObject{Operator},
86+
B::QuantumObject{Operator},
8787
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
8888
reverse::Bool = false,
8989
kwargs...,
9090
) where {
91-
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
92-
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
91+
HOpType<:Union{Operator,SuperOperator},
92+
StateOpType<:Union{Ket,Operator},
9393
} = error(
9494
"The parameter order of `correlation_2op_1t` has been changed, please use `?correlation_2op_1t` to check the updated docstring.",
9595
)

src/entropy.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function entropy_vn(
4848
ρ::QuantumObject{ObjType};
4949
base::Int = 0,
5050
tol::Real = 1e-15,
51-
) where {ObjType<:Union{KetQuantumObject,OperatorQuantumObject}}
51+
) where {ObjType<:Union{Ket,Operator}}
5252
T = eltype(ρ)
5353
vals = eigenenergies(ket2dm(ρ))
5454
indexes = findall(x -> abs(x) > tol, vals)
@@ -79,8 +79,8 @@ function entropy_relative(
7979
base::Int = 0,
8080
tol::Real = 1e-15,
8181
) where {
82-
ObjType1<:Union{KetQuantumObject,OperatorQuantumObject},
83-
ObjType2<:Union{KetQuantumObject,OperatorQuantumObject},
82+
ObjType1<:Union{Ket,Operator},
83+
ObjType2<:Union{Ket,Operator},
8484
}
8585
check_dimensions(ρ, σ)
8686

@@ -131,7 +131,7 @@ Calculates the quantum linear entropy ``S_L = 1 - \textrm{Tr} \left[ \hat{\rho}^
131131
132132
Note that `ρ` can be either a [`Ket`](@ref) or an [`Operator`](@ref).
133133
"""
134-
entropy_linear::QuantumObject{ObjType}) where {ObjType<:Union{KetQuantumObject,OperatorQuantumObject}} =
134+
entropy_linear::QuantumObject{ObjType}) where {ObjType<:Union{Ket,Operator}} =
135135
1.0 - purity(ρ) # use 1.0 to make sure it always return value in Float-type
136136

137137
@doc raw"""
@@ -153,7 +153,7 @@ function entropy_mutual(
153153
selA::Union{Int,AbstractVector{Int},Tuple},
154154
selB::Union{Int,AbstractVector{Int},Tuple};
155155
kwargs...,
156-
) where {ObjType<:Union{KetQuantumObject,OperatorQuantumObject},N}
156+
) where {ObjType<:Union{Ket,Operator},N}
157157
# check if selA and selB matches the dimensions of ρAB
158158
sel_A_B = (selA..., selB...)
159159
(length(sel_A_B) != N) && throw(
@@ -185,7 +185,7 @@ entropy_conditional(
185185
ρAB::QuantumObject{ObjType,<:AbstractDimensions{N,N}},
186186
selB::Union{Int,AbstractVector{Int},Tuple};
187187
kwargs...,
188-
) where {ObjType<:Union{KetQuantumObject,OperatorQuantumObject},N} =
188+
) where {ObjType<:Union{Ket,Operator},N} =
189189
entropy_vn(ρAB; kwargs...) - entropy_vn(ptrace(ρAB, selB); kwargs...)
190190

191191
@doc raw"""
@@ -203,7 +203,7 @@ function entanglement(
203203
ρ::QuantumObject{OpType},
204204
sel::Union{Int,AbstractVector{Int},Tuple},
205205
kwargs...,
206-
) where {OpType<:Union{KetQuantumObject,OperatorQuantumObject}}
206+
) where {OpType<:Union{Ket,Operator}}
207207
p = purity(ρ)
208208
isapprox(p, 1; atol = 1e-2) || throw(
209209
ArgumentError(
@@ -229,7 +229,7 @@ Calculate the [concurrence](https://en.wikipedia.org/wiki/Concurrence_(quantum_c
229229
230230
- [Hill-Wootters1997](@citet)
231231
"""
232-
function concurrence::QuantumObject{OpType}) where {OpType<:Union{KetQuantumObject,OperatorQuantumObject}}
232+
function concurrence::QuantumObject{OpType}) where {OpType<:Union{Ket,Operator}}
233233
.dimensions == Dimensions((Space(2), Space(2)))) || throw(
234234
ArgumentError(
235235
"The `concurrence` only works for a two-qubit state, invalid dims = $(_get_dims_string.dimensions)).",

src/metrics.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ Here, the definition is from [Nielsen-Chuang2011](@citet). It is the square root
1616
1717
Note that `ρ` and `σ` must be either [`Ket`](@ref) or [`Operator`](@ref).
1818
"""
19-
function fidelity::QuantumObject{OperatorQuantumObject}, σ::QuantumObject{OperatorQuantumObject})
19+
function fidelity::QuantumObject{Operator}, σ::QuantumObject{Operator})
2020
sqrt_ρ = sqrt(ρ)
2121
eigval = abs.(eigvals(sqrt_ρ * σ * sqrt_ρ))
2222
return sum(sqrt, eigval)
2323
end
24-
fidelity::QuantumObject{OperatorQuantumObject}, ψ::QuantumObject{KetQuantumObject}) = sqrt(abs(expect(ρ, ψ)))
25-
fidelity::QuantumObject{KetQuantumObject}, σ::QuantumObject{OperatorQuantumObject}) = fidelity(σ, ψ)
26-
fidelity::QuantumObject{KetQuantumObject}, ϕ::QuantumObject{KetQuantumObject}) = abs(dot(ψ, ϕ))
24+
fidelity::QuantumObject{Operator}, ψ::QuantumObject{Ket}) = sqrt(abs(expect(ρ, ψ)))
25+
fidelity::QuantumObject{Ket}, σ::QuantumObject{Operator}) = fidelity(σ, ψ)
26+
fidelity::QuantumObject{Ket}, ϕ::QuantumObject{Ket}) = abs(dot(ψ, ϕ))
2727

2828
@doc raw"""
2929
tracedist(ρ::QuantumObject, σ::QuantumObject)
@@ -37,8 +37,8 @@ tracedist(
3737
ρ::QuantumObject{ObjType1},
3838
σ::QuantumObject{ObjType2},
3939
) where {
40-
ObjType1<:Union{KetQuantumObject,OperatorQuantumObject},
41-
ObjType2<:Union{KetQuantumObject,OperatorQuantumObject},
40+
ObjType1<:Union{Ket,Operator},
41+
ObjType2<:Union{Ket,Operator},
4242
} = norm(ket2dm(ρ) - ket2dm(σ), 1) / 2
4343

4444
@doc raw"""
@@ -56,8 +56,8 @@ function hilbert_dist(
5656
ρ::QuantumObject{ObjType1},
5757
σ::QuantumObject{ObjType2},
5858
) where {
59-
ObjType1<:Union{KetQuantumObject,OperatorQuantumObject},
60-
ObjType2<:Union{KetQuantumObject,OperatorQuantumObject},
59+
ObjType1<:Union{Ket,Operator},
60+
ObjType2<:Union{Ket,Operator},
6161
}
6262
check_dimensions(ρ, σ)
6363

@@ -80,8 +80,8 @@ function hellinger_dist(
8080
ρ::QuantumObject{ObjType1},
8181
σ::QuantumObject{ObjType2},
8282
) where {
83-
ObjType1<:Union{KetQuantumObject,OperatorQuantumObject},
84-
ObjType2<:Union{KetQuantumObject,OperatorQuantumObject},
83+
ObjType1<:Union{Ket,Operator},
84+
ObjType2<:Union{Ket,Operator},
8585
}
8686
# Ket (pure state) doesn't need to do square root
8787
sqrt_ρ = isket(ρ) ? ket2dm(ρ) : sqrt(ρ)

0 commit comments

Comments
 (0)