Skip to content

Commit 60a57e1

Browse files
Format code
1 parent dcf059b commit 60a57e1

14 files changed

+60
-207
lines changed

src/correlations.jl

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ function correlation_3op_2t(
3333
B::QuantumObject{Operator},
3434
C::QuantumObject{Operator};
3535
kwargs...,
36-
) where {
37-
HOpType<:Union{Operator,SuperOperator},
38-
StateOpType<:Union{Ket,Operator},
39-
}
36+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}}
4037
# check tlist and τlist
4138
_check_correlation_time_list(tlist)
4239
_check_correlation_time_list(τlist)
@@ -82,10 +79,7 @@ function correlation_3op_1t(
8279
B::QuantumObject{Operator},
8380
C::QuantumObject{Operator};
8481
kwargs...,
85-
) where {
86-
HOpType<:Union{Operator,SuperOperator},
87-
StateOpType<:Union{Ket,Operator},
88-
}
82+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}}
8983
corr = correlation_3op_2t(H, ψ0, [0], τlist, c_ops, A, B, C; kwargs...)
9084

9185
return corr[1, :] # 1 means tlist[1] = 0
@@ -118,10 +112,7 @@ function correlation_2op_2t(
118112
B::QuantumObject{Operator};
119113
reverse::Bool = false,
120114
kwargs...,
121-
) where {
122-
HOpType<:Union{Operator,SuperOperator},
123-
StateOpType<:Union{Ket,Operator},
124-
}
115+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}}
125116
C = eye(prod(H.dimensions), dims = H.dimensions)
126117
if reverse
127118
corr = correlation_3op_2t(H, ψ0, tlist, τlist, c_ops, A, B, C; kwargs...)
@@ -157,10 +148,7 @@ function correlation_2op_1t(
157148
B::QuantumObject{Operator};
158149
reverse::Bool = false,
159150
kwargs...,
160-
) where {
161-
HOpType<:Union{Operator,SuperOperator},
162-
StateOpType<:Union{Ket,Operator},
163-
}
151+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}}
164152
corr = correlation_2op_2t(H, ψ0, [0], τlist, c_ops, A, B; reverse = reverse, kwargs...)
165153

166154
return corr[1, :] # 1 means tlist[1] = 0

src/deprecated.jl

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ correlation_3op_2t(
3838
C::QuantumObject{Operator},
3939
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
4040
kwargs...,
41-
) where {
42-
HOpType<:Union{Operator,SuperOperator},
43-
StateOpType<:Union{Ket,Operator},
44-
} = error(
41+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}} = error(
4542
"The parameter order of `correlation_3op_2t` has been changed, please use `?correlation_3op_2t` to check the updated docstring.",
4643
)
4744

@@ -54,10 +51,7 @@ correlation_3op_1t(
5451
C::QuantumObject{Operator},
5552
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
5653
kwargs...,
57-
) where {
58-
HOpType<:Union{Operator,SuperOperator},
59-
StateOpType<:Union{Ket,Operator},
60-
} = error(
54+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}} = error(
6155
"The parameter order of `correlation_3op_1t` has been changed, please use `?correlation_3op_1t` to check the updated docstring.",
6256
)
6357

@@ -71,10 +65,7 @@ correlation_2op_2t(
7165
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
7266
reverse::Bool = false,
7367
kwargs...,
74-
) where {
75-
HOpType<:Union{Operator,SuperOperator},
76-
StateOpType<:Union{Ket,Operator},
77-
} = error(
68+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}} = error(
7869
"The parameter order of `correlation_2op_2t` has been changed, please use `?correlation_2op_2t` to check the updated docstring.",
7970
)
8071

@@ -87,10 +78,7 @@ correlation_2op_1t(
8778
c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
8879
reverse::Bool = false,
8980
kwargs...,
90-
) where {
91-
HOpType<:Union{Operator,SuperOperator},
92-
StateOpType<:Union{Ket,Operator},
93-
} = error(
81+
) where {HOpType<:Union{Operator,SuperOperator},StateOpType<:Union{Ket,Operator}} = error(
9482
"The parameter order of `correlation_2op_1t` has been changed, please use `?correlation_2op_1t` to check the updated docstring.",
9583
)
9684

src/entropy.jl

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ julia> entropy_vn(ρ, base=2)
4444
1.0
4545
```
4646
"""
47-
function entropy_vn(
48-
ρ::QuantumObject{ObjType};
49-
base::Int = 0,
50-
tol::Real = 1e-15,
51-
) where {ObjType<:Union{Ket,Operator}}
47+
function entropy_vn::QuantumObject{ObjType}; base::Int = 0, tol::Real = 1e-15) where {ObjType<:Union{Ket,Operator}}
5248
T = eltype(ρ)
5349
vals = eigenenergies(ket2dm(ρ))
5450
indexes = findall(x -> abs(x) > tol, vals)
@@ -78,10 +74,7 @@ function entropy_relative(
7874
σ::QuantumObject{ObjType2};
7975
base::Int = 0,
8076
tol::Real = 1e-15,
81-
) where {
82-
ObjType1<:Union{Ket,Operator},
83-
ObjType2<:Union{Ket,Operator},
84-
}
77+
) where {ObjType1<:Union{Ket,Operator},ObjType2<:Union{Ket,Operator}}
8578
check_dimensions(ρ, σ)
8679

8780
# the logic of this code follows the detail given in the reference of the docstring
@@ -131,8 +124,7 @@ Calculates the quantum linear entropy ``S_L = 1 - \textrm{Tr} \left[ \hat{\rho}^
131124
132125
Note that `ρ` can be either a [`Ket`](@ref) or an [`Operator`](@ref).
133126
"""
134-
entropy_linear::QuantumObject{ObjType}) where {ObjType<:Union{Ket,Operator}} =
135-
1.0 - purity(ρ) # use 1.0 to make sure it always return value in Float-type
127+
entropy_linear::QuantumObject{ObjType}) where {ObjType<:Union{Ket,Operator}} = 1.0 - purity(ρ) # use 1.0 to make sure it always return value in Float-type
136128

137129
@doc raw"""
138130
entropy_mutual(ρAB::QuantumObject, selA, selB; kwargs...)
@@ -185,8 +177,7 @@ entropy_conditional(
185177
ρAB::QuantumObject{ObjType,<:AbstractDimensions{N,N}},
186178
selB::Union{Int,AbstractVector{Int},Tuple};
187179
kwargs...,
188-
) where {ObjType<:Union{Ket,Operator},N} =
189-
entropy_vn(ρAB; kwargs...) - entropy_vn(ptrace(ρAB, selB); kwargs...)
180+
) where {ObjType<:Union{Ket,Operator},N} = entropy_vn(ρAB; kwargs...) - entropy_vn(ptrace(ρAB, selB); kwargs...)
190181

191182
@doc raw"""
192183
entanglement(ρ::QuantumObject, sel; kwargs...)

src/metrics.jl

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ Note that `ρ` and `σ` must be either [`Ket`](@ref) or [`Operator`](@ref).
3636
tracedist(
3737
ρ::QuantumObject{ObjType1},
3838
σ::QuantumObject{ObjType2},
39-
) where {
40-
ObjType1<:Union{Ket,Operator},
41-
ObjType2<:Union{Ket,Operator},
42-
} = norm(ket2dm(ρ) - ket2dm(σ), 1) / 2
39+
) where {ObjType1<:Union{Ket,Operator},ObjType2<:Union{Ket,Operator}} = norm(ket2dm(ρ) - ket2dm(σ), 1) / 2
4340

4441
@doc raw"""
4542
hilbert_dist(ρ::QuantumObject, σ::QuantumObject)
@@ -55,10 +52,7 @@ Note that `ρ` and `σ` must be either [`Ket`](@ref) or [`Operator`](@ref).
5552
function hilbert_dist(
5653
ρ::QuantumObject{ObjType1},
5754
σ::QuantumObject{ObjType2},
58-
) where {
59-
ObjType1<:Union{Ket,Operator},
60-
ObjType2<:Union{Ket,Operator},
61-
}
55+
) where {ObjType1<:Union{Ket,Operator},ObjType2<:Union{Ket,Operator}}
6256
check_dimensions(ρ, σ)
6357

6458
A = ket2dm(ρ) - ket2dm(σ)
@@ -79,10 +73,7 @@ Note that `ρ` and `σ` must be either [`Ket`](@ref) or [`Operator`](@ref).
7973
function hellinger_dist(
8074
ρ::QuantumObject{ObjType1},
8175
σ::QuantumObject{ObjType2},
82-
) where {
83-
ObjType1<:Union{Ket,Operator},
84-
ObjType2<:Union{Ket,Operator},
85-
}
76+
) where {ObjType1<:Union{Ket,Operator},ObjType2<:Union{Ket,Operator}}
8677
# Ket (pure state) doesn't need to do square root
8778
sqrt_ρ = isket(ρ) ? ket2dm(ρ) : sqrt(ρ)
8879
sqrt_σ = isket(σ) ? ket2dm(σ) : sqrt(σ)

src/qobj/arithmetic_and_attributes.jl

Lines changed: 27 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,7 @@ Note that `A` and `B` should be [`Ket`](@ref) or [`OperatorKet`](@ref)
138138
!!! note
139139
`A ⋅ B` (where `⋅` can be typed by tab-completing `\cdot` in the REPL) is a synonym of `dot(A, B)`.
140140
"""
141-
function LinearAlgebra.dot(
142-
A::QuantumObject{OpType},
143-
B::QuantumObject{OpType},
144-
) where {OpType<:Union{Ket,OperatorKet}}
141+
function LinearAlgebra.dot(A::QuantumObject{OpType}, B::QuantumObject{OpType}) where {OpType<:Union{Ket,OperatorKet}}
145142
check_dimensions(A, B)
146143
return LinearAlgebra.dot(A.data, B.data)
147144
end
@@ -159,11 +156,7 @@ Supports the following inputs:
159156
!!! note
160157
`matrix_element(i, A, j)` is a synonym of `dot(i, A, j)`.
161158
"""
162-
function LinearAlgebra.dot(
163-
i::QuantumObject{Ket},
164-
A::AbstractQuantumObject{Operator},
165-
j::QuantumObject{Ket},
166-
)
159+
function LinearAlgebra.dot(i::QuantumObject{Ket}, A::AbstractQuantumObject{Operator}, j::QuantumObject{Ket})
167160
check_dimensions(i, A, j)
168161
return LinearAlgebra.dot(i.data, A.data, j.data)
169162
end
@@ -205,9 +198,7 @@ Base.conj(A::AbstractQuantumObject) = get_typename_wrapper(A)(conj(A.data), A.ty
205198
206199
Lazy matrix transpose of the [`AbstractQuantumObject`](@ref).
207200
"""
208-
Base.transpose(
209-
A::AbstractQuantumObject{OpType},
210-
) where {OpType<:Union{Operator,SuperOperator}} =
201+
Base.transpose(A::AbstractQuantumObject{OpType}) where {OpType<:Union{Operator,SuperOperator}} =
211202
get_typename_wrapper(A)(transpose(A.data), A.type, transpose(A.dimensions))
212203

213204
@doc raw"""
@@ -224,25 +215,18 @@ Base.adjoint(A::AbstractQuantumObject{OpType}) where {OpType<:Union{Operator,Sup
224215
get_typename_wrapper(A)(adjoint(A.data), A.type, adjoint(A.dimensions))
225216
Base.adjoint(A::QuantumObject{Ket}) = QuantumObject(adjoint(A.data), Bra, adjoint(A.dimensions))
226217
Base.adjoint(A::QuantumObject{Bra}) = QuantumObject(adjoint(A.data), Ket, adjoint(A.dimensions))
227-
Base.adjoint(A::QuantumObject{OperatorKet}) =
228-
QuantumObject(adjoint(A.data), OperatorBra, adjoint(A.dimensions))
229-
Base.adjoint(A::QuantumObject{OperatorBra}) =
230-
QuantumObject(adjoint(A.data), OperatorKet, adjoint(A.dimensions))
218+
Base.adjoint(A::QuantumObject{OperatorKet}) = QuantumObject(adjoint(A.data), OperatorBra, adjoint(A.dimensions))
219+
Base.adjoint(A::QuantumObject{OperatorBra}) = QuantumObject(adjoint(A.data), OperatorKet, adjoint(A.dimensions))
231220

232221
@doc raw"""
233222
inv(A::AbstractQuantumObject)
234223
235224
Matrix inverse of the [`AbstractQuantumObject`](@ref). If `A` is a [`QuantumObjectEvolution`](@ref), the inverse is computed at the last computed time.
236225
"""
237-
LinearAlgebra.inv(
238-
A::AbstractQuantumObject{OpType},
239-
) where {OpType<:Union{Operator,SuperOperator}} =
226+
LinearAlgebra.inv(A::AbstractQuantumObject{OpType}) where {OpType<:Union{Operator,SuperOperator}} =
240227
QuantumObject(sparse(inv(Matrix(A.data))), A.type, A.dimensions)
241228

242-
LinearAlgebra.Hermitian(
243-
A::QuantumObject{OpType},
244-
uplo::Symbol = :U,
245-
) where {OpType<:Union{Operator,SuperOperator}} =
229+
LinearAlgebra.Hermitian(A::QuantumObject{OpType}, uplo::Symbol = :U) where {OpType<:Union{Operator,SuperOperator}} =
246230
QuantumObject(Hermitian(A.data, uplo), A.type, A.dimensions)
247231

248232
@doc raw"""
@@ -269,8 +253,7 @@ julia> tr(a' * a)
269253
190.0 + 0.0im
270254
```
271255
"""
272-
LinearAlgebra.tr(A::QuantumObject{OpType}) where {OpType<:Union{Operator,SuperOperator}} =
273-
tr(A.data)
256+
LinearAlgebra.tr(A::QuantumObject{OpType}) where {OpType<:Union{Operator,SuperOperator}} = tr(A.data)
274257
LinearAlgebra.tr(
275258
A::QuantumObject{OpType,DimsType,<:Union{<:Hermitian{TF},Symmetric{TR}}},
276259
) where {OpType<:Operator,DimsType,TF<:BlasFloat,TR<:Real} = real(tr(A.data))
@@ -312,15 +295,9 @@ julia> norm(ψ)
312295
1.0
313296
```
314297
"""
315-
LinearAlgebra.norm(
316-
A::QuantumObject{OpType},
317-
p::Real = 2,
318-
) where {OpType<:Union{Ket,Bra,OperatorKet,OperatorBra}} =
298+
LinearAlgebra.norm(A::QuantumObject{OpType}, p::Real = 2) where {OpType<:Union{Ket,Bra,OperatorKet,OperatorBra}} =
319299
norm(A.data, p)
320-
function LinearAlgebra.norm(
321-
A::QuantumObject{OpType},
322-
p::Real = 1,
323-
) where {OpType<:Union{Operator,SuperOperator}}
300+
function LinearAlgebra.norm(A::QuantumObject{OpType}, p::Real = 1) where {OpType<:Union{Operator,SuperOperator}}
324301
p == 2.0 && return norm(A.data, 2)
325302
return norm(svdvals(A), p)
326303
end
@@ -340,10 +317,8 @@ Support for the following types of [`QuantumObject`](@ref):
340317
341318
Also, see [`norm`](@ref) about its definition for different types of [`QuantumObject`](@ref).
342319
"""
343-
LinearAlgebra.normalize(
344-
A::QuantumObject{ObjType},
345-
p::Real = 2,
346-
) where {ObjType<:Union{Ket,Bra}} = QuantumObject(A.data / norm(A, p), A.type, A.dimensions)
320+
LinearAlgebra.normalize(A::QuantumObject{ObjType}, p::Real = 2) where {ObjType<:Union{Ket,Bra}} =
321+
QuantumObject(A.data / norm(A, p), A.type, A.dimensions)
347322
LinearAlgebra.normalize(A::QuantumObject{Operator}, p::Real = 1) =
348323
QuantumObject(A.data / norm(A, p), A.type, A.dimensions)
349324

@@ -358,29 +333,17 @@ Support for the following types of [`QuantumObject`](@ref):
358333
359334
Also, see [`norm`](@ref) about its definition for different types of [`QuantumObject`](@ref).
360335
"""
361-
LinearAlgebra.normalize!(
362-
A::QuantumObject{ObjType},
363-
p::Real = 2,
364-
) where {ObjType<:Union{Ket,Bra}} = (rmul!(A.data, 1 / norm(A, p)); A)
336+
LinearAlgebra.normalize!(A::QuantumObject{ObjType}, p::Real = 2) where {ObjType<:Union{Ket,Bra}} =
337+
(rmul!(A.data, 1 / norm(A, p)); A)
365338
LinearAlgebra.normalize!(A::QuantumObject{Operator}, p::Real = 1) = (rmul!(A.data, 1 / norm(A, p)); A)
366339

367-
LinearAlgebra.triu!(
368-
A::QuantumObject{OpType},
369-
k::Integer = 0,
370-
) where {OpType<:Union{Operator,SuperOperator}} = (triu!(A.data, k); A)
371-
LinearAlgebra.tril!(
372-
A::QuantumObject{OpType},
373-
k::Integer = 0,
374-
) where {OpType<:Union{Operator,SuperOperator}} = (tril!(A.data, k); A)
375-
LinearAlgebra.triu(
376-
A::QuantumObject{OpType},
377-
k::Integer = 0,
378-
) where {OpType<:Union{Operator,SuperOperator}} =
340+
LinearAlgebra.triu!(A::QuantumObject{OpType}, k::Integer = 0) where {OpType<:Union{Operator,SuperOperator}} =
341+
(triu!(A.data, k); A)
342+
LinearAlgebra.tril!(A::QuantumObject{OpType}, k::Integer = 0) where {OpType<:Union{Operator,SuperOperator}} =
343+
(tril!(A.data, k); A)
344+
LinearAlgebra.triu(A::QuantumObject{OpType}, k::Integer = 0) where {OpType<:Union{Operator,SuperOperator}} =
379345
QuantumObject(triu(A.data, k), A.type, A.dimensions)
380-
LinearAlgebra.tril(
381-
A::QuantumObject{OpType},
382-
k::Integer = 0,
383-
) where {OpType<:Union{Operator,SuperOperator}} =
346+
LinearAlgebra.tril(A::QuantumObject{OpType}, k::Integer = 0) where {OpType<:Union{Operator,SuperOperator}} =
384347
QuantumObject(tril(A.data, k), A.type, A.dimensions)
385348

386349
LinearAlgebra.lmul!(a::Number, B::QuantumObject) = (lmul!(a, B.data); B)
@@ -416,14 +379,11 @@ Matrix exponential of [`QuantumObject`](@ref)
416379
417380
Note that this function only supports for [`Operator`](@ref) and [`SuperOperator`](@ref)
418381
"""
419-
Base.exp(
420-
A::QuantumObject{ObjType,DimsType,<:AbstractMatrix},
421-
) where {ObjType<:Union{Operator,SuperOperator},DimsType} =
382+
Base.exp(A::QuantumObject{ObjType,DimsType,<:AbstractMatrix}) where {ObjType<:Union{Operator,SuperOperator},DimsType} =
422383
QuantumObject(to_sparse(exp(A.data)), A.type, A.dimensions)
423384
Base.exp(
424385
A::QuantumObject{ObjType,DimsType,<:AbstractSparseMatrix},
425-
) where {ObjType<:Union{Operator,SuperOperator},DimsType} =
426-
QuantumObject(_spexp(A.data), A.type, A.dimensions)
386+
) where {ObjType<:Union{Operator,SuperOperator},DimsType} = QuantumObject(_spexp(A.data), A.type, A.dimensions)
427387

428388
function _spexp(A::SparseMatrixCSC{T,M}; threshold = 1e-14, nonzero_tol = 1e-20) where {T<:Number,M<:Int}
429389
m = checksquare(A) # Throws exception if not square
@@ -477,8 +437,7 @@ Matrix cosine of [`QuantumObject`](@ref), defined as
477437
478438
Note that this function only supports for [`Operator`](@ref) and [`SuperOperator`](@ref)
479439
"""
480-
Base.cos(A::QuantumObject{ObjType}) where {ObjType<:Union{Operator,SuperOperator}} =
481-
(exp(1im * A) + exp(-1im * A)) / 2
440+
Base.cos(A::QuantumObject{ObjType}) where {ObjType<:Union{Operator,SuperOperator}} = (exp(1im * A) + exp(-1im * A)) / 2
482441

483442
@doc raw"""
484443
diag(A::QuantumObject, k::Int=0)
@@ -487,10 +446,8 @@ Return the `k`-th diagonal elements of a matrix-type [`QuantumObject`](@ref)
487446
488447
Note that this function only supports for [`Operator`](@ref) and [`SuperOperator`](@ref)
489448
"""
490-
LinearAlgebra.diag(
491-
A::QuantumObject{ObjType},
492-
k::Int = 0,
493-
) where {ObjType<:Union{Operator,SuperOperator}} = diag(A.data, k)
449+
LinearAlgebra.diag(A::QuantumObject{ObjType}, k::Int = 0) where {ObjType<:Union{Operator,SuperOperator}} =
450+
diag(A.data, k)
494451

495452
@doc raw"""
496453
proj(ψ::QuantumObject)
@@ -773,12 +730,8 @@ function SparseArrays.permute(
773730
return QuantumObject(reshape(permutedims(reshape(A.data, dims...), Tuple(perm)), size(A)), A.type, order_dimensions)
774731
end
775732

776-
_dims_and_perm(
777-
::ObjType,
778-
dims::SVector{N,Int},
779-
order::AbstractVector{Int},
780-
L::Int,
781-
) where {ObjType<:Union{Ket,Bra},N} = reverse(dims), reverse((L + 1) .- order)
733+
_dims_and_perm(::ObjType, dims::SVector{N,Int}, order::AbstractVector{Int}, L::Int) where {ObjType<:Union{Ket,Bra},N} =
734+
reverse(dims), reverse((L + 1) .- order)
782735

783736
# if dims originates from Dimensions
784737
_dims_and_perm(::Operator, dims::SVector{N,Int}, order::AbstractVector{Int}, L::Int) where {N} =

src/qobj/block_diagonal_form.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ Return the block-diagonal form of a [`QuantumObject`](@ref). This is very useful
5050
# Returns
5151
The [`BlockDiagonalForm`](@ref) of `A`.
5252
"""
53-
function block_diagonal_form(
54-
A::QuantumObject{OpType},
55-
) where {OpType<:Union{Operator,SuperOperator}}
53+
function block_diagonal_form(A::QuantumObject{OpType}) where {OpType<:Union{Operator,SuperOperator}}
5654
bdf = block_diagonal_form(A.data)
5755
B = QuantumObject(bdf.B, type = A.type, dims = A.dimensions)
5856
P = QuantumObject(bdf.P, type = A.type, dims = A.dimensions)

0 commit comments

Comments
 (0)