Skip to content

Commit 725c4b6

Browse files
committed
simplify synonyms
1 parent f5392ee commit 725c4b6

File tree

9 files changed

+172
-274
lines changed

9 files changed

+172
-274
lines changed

docs/src/resources/api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ trans
170170
dag
171171
matrix_element
172172
unit
173+
tensor
174+
175+
qeye
173176
sqrtm
174177
logm
175178
expm
176179
sinm
177180
cosm
178-
tensor
179-
180-
qeye
181181
```
182182

183183
## [Time evolution](@id doc-API:Time-evolution)

src/qobj/arithmetic_and_attributes.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,15 @@ end
130130

131131
@doc raw"""
132132
dot(i::QuantumObject, A::AbstractQuantumObject j::QuantumObject)
133+
matrix_element(i::QuantumObject, A::AbstractQuantumObject j::QuantumObject)
133134
134135
Compute the generalized dot product `dot(i, A*j)` between a [`AbstractQuantumObject`](@ref) and two [`QuantumObject`](@ref) (`i` and `j`), namely ``\langle i | \hat{A} | j \rangle``.
135136
136137
Supports the following inputs:
137138
- `A` is in the type of [`Operator`](@ref), with `i` and `j` are both [`Ket`](@ref).
138139
- `A` is in the type of [`SuperOperator`](@ref), with `i` and `j` are both [`OperatorKet`](@ref)
140+
141+
Note that `matrix_element(i, A, j)` is a synonym of `dot(i, A, j)`.
139142
"""
140143
function LinearAlgebra.dot(
141144
i::QuantumObject{DT1,KetQuantumObject},
@@ -195,10 +198,11 @@ LinearAlgebra.transpose(
195198
@doc raw"""
196199
A'
197200
adjoint(A::AbstractQuantumObject)
201+
dag(A::AbstractQuantumObject)
198202
199203
Lazy adjoint (conjugate transposition) of the [`AbstractQuantumObject`](@ref)
200204
201-
Note that `A'` is a synonym for `adjoint(A)`
205+
Note that `A'` and `dag(A)` are synonyms of `adjoint(A)`.
202206
"""
203207
LinearAlgebra.adjoint(
204208
A::AbstractQuantumObject{DT,OpType},
@@ -310,13 +314,16 @@ end
310314

311315
@doc raw"""
312316
normalize(A::QuantumObject, p::Real)
317+
unit(A::QuantumObject, p::Real)
313318
314319
Return normalized [`QuantumObject`](@ref) so that its `p`-norm equals to unity, i.e. `norm(A, p) == 1`.
315320
316321
Support for the following types of [`QuantumObject`](@ref):
317322
- If `A` is [`Ket`](@ref) or [`Bra`](@ref), default `p = 2`
318323
- If `A` is [`Operator`](@ref), default `p = 1`
319324
325+
Note that `unit` is a synonym of `normalize`.
326+
320327
Also, see [`norm`](@ref) about its definition for different types of [`QuantumObject`](@ref).
321328
"""
322329
LinearAlgebra.normalize(

src/qobj/boolean_functions.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ issuper(A) = false # default case
6161

6262
@doc raw"""
6363
ishermitian(A::AbstractQuantumObject)
64+
isherm(A::AbstractQuantumObject)
6465
6566
Test whether the [`AbstractQuantumObject`](@ref) is Hermitian.
67+
68+
Note that `isherm` is a synonym of `ishermitian`.
6669
"""
6770
LinearAlgebra.ishermitian(A::AbstractQuantumObject) = ishermitian(A.data)
6871

src/qobj/functions.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,14 @@ end
148148

149149
@doc raw"""
150150
kron(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
151+
tensor(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
152+
⊗(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
153+
A ⊗ B
151154
152155
Returns the [Kronecker product](https://en.wikipedia.org/wiki/Kronecker_product) ``\hat{A} \otimes \hat{B} \otimes \cdots``.
153156
157+
Note that `tensor` and `⊗` are synonyms of `kron`.
158+
154159
# Examples
155160
156161
```jldoctest

src/qobj/operators.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,15 @@ sigmaz() = rmul!(jmat(0.5, Val(:z)), 2)
416416

417417
@doc raw"""
418418
eye(N::Int; type=Operator, dims=nothing)
419+
qeye(N::Int; type=Operator, dims=nothing)
419420
420421
Identity operator ``\hat{\mathbb{1}}`` with size `N`.
421422
422423
It is also possible to specify the list of Hilbert dimensions `dims` if different subsystems are present.
423424
424-
Note that `type` can only be either [`Operator`](@ref) or [`SuperOperator`](@ref)
425+
Note that
426+
- `type` can only be either [`Operator`](@ref) or [`SuperOperator`](@ref)
427+
- `qeye` is a synonym of `eye`
425428
"""
426429
eye(
427430
N::Int;

src/qobj/quantum_object.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ struct QuantumObject{MT<:AbstractArray,ObjType<:QuantumObjectType,N} <: Abstract
5050
end
5151
end
5252

53-
function QuantumObject(A::AbstractArray, type::ObjType, dims::Integer) where {ObjType<:QuantumObjectType}
54-
return QuantumObject(A, type, SVector{1,Int}(dims))
55-
end
53+
QuantumObject(A::AbstractArray, type::ObjType, dims::Integer) where {ObjType<:QuantumObjectType} = QuantumObject(A, type, SVector{1,Int}(dims))
54+
55+
@doc raw"""
56+
Qobj(A::AbstractArray; type = nothing, dims = nothing)
57+
QuantumObject(A::AbstractArray; type = nothing, dims = nothing)
5658
59+
Generate [`QuantumObject`](@ref) with a given `A::AbstractArray` and specified `type::QuantumObjectType` and `dims`.
60+
61+
Note that `Qobj` is a synonym of `QuantumObject`.
62+
"""
5763
function QuantumObject(
5864
A::AbstractMatrix{T};
5965
type::ObjType = nothing,

src/qobj/quantum_object_base.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,14 @@ const OperatorKet = OperatorKetQuantumObject()
121121
@doc raw"""
122122
size(A::AbstractQuantumObject)
123123
size(A::AbstractQuantumObject, idx::Int)
124+
shape(A::AbstractQuantumObject)
125+
shape(A::AbstractQuantumObject, idx::Int)
124126
125127
Returns a tuple containing each dimensions of the array in the [`AbstractQuantumObject`](@ref).
126128
127129
Optionally, you can specify an index (`idx`) to just get the corresponding dimension of the array.
130+
131+
Note that `shape` is a synonym of `size`.
128132
"""
129133
Base.size(A::AbstractQuantumObject) = size(A.data)
130134
Base.size(A::AbstractQuantumObject, idx::Int) = size(A.data, idx)

src/qobj/quantum_object_evo.jl

Lines changed: 121 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=fal
3030
julia> coef1(p, t) = exp(-1im * t)
3131
coef1 (generic function with 1 method)
3232
33-
julia> op = QuantumObjectEvolution(a, coef1)
33+
julia> op = QobjEvo(a, coef1)
3434
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
3535
ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20)
3636
```
@@ -50,7 +50,7 @@ Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=fal
5050
julia> coef2(p, t) = sin(t)
5151
coef2 (generic function with 1 method)
5252
53-
julia> op1 = QuantumObjectEvolution(((a, coef1), (σm, coef2)))
53+
julia> op1 = QobjEvo(((a, coef1), (σm, coef2)))
5454
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
5555
(ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20) + ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20))
5656
```
@@ -75,7 +75,7 @@ coef1 (generic function with 1 method)
7575
julia> coef2(p, t) = sin(p.ω2 * t)
7676
coef2 (generic function with 1 method)
7777
78-
julia> op1 = QuantumObjectEvolution(((a, coef1), (σm, coef2)))
78+
julia> op1 = QobjEvo(((a, coef1), (σm, coef2)))
7979
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
8080
(ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20) + ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20))
8181
@@ -143,9 +143,12 @@ function QuantumObjectEvolution(data::AbstractSciMLOperator, type::QuantumObject
143143
end
144144

145145
@doc raw"""
146+
QobjEvo(data::AbstractSciMLOperator; type::QuantumObjectType = Operator, dims = nothing)
146147
QuantumObjectEvolution(data::AbstractSciMLOperator; type::QuantumObjectType = Operator, dims = nothing)
147148
148149
Generate a [`QuantumObjectEvolution`](@ref) object from a [`SciMLOperator`](https://github.com/SciML/SciMLOperators.jl), in the same way as [`QuantumObject`](@ref) for `AbstractArray` inputs.
150+
151+
Note that `QobjEvo` is a synonym of `QuantumObjectEvolution`
149152
"""
150153
function QuantumObjectEvolution(data::AbstractSciMLOperator; type::QuantumObjectType = Operator, dims = nothing)
151154
_size = _get_size(data)
@@ -161,7 +164,92 @@ function QuantumObjectEvolution(data::AbstractSciMLOperator; type::QuantumObject
161164
return QuantumObjectEvolution(data, type, dims)
162165
end
163166

164-
# Make the QuantumObjectEvolution, with the option to pre-multiply by a scalar
167+
@doc raw"""
168+
QobjEvo(op_func_list::Union{Tuple,AbstractQuantumObject}, α::Union{Nothing,Number}=nothing; type::Union{Nothing, QuantumObjectType}=nothing)
169+
QuantumObjectEvolution(op_func_list::Union{Tuple,AbstractQuantumObject}, α::Union{Nothing,Number}=nothing; type::Union{Nothing, QuantumObjectType}=nothing)
170+
171+
Generate [`QuantumObjectEvolution`](@ref).
172+
173+
# Arguments
174+
- `op_func_list::Union{Tuple,AbstractQuantumObject}`: A tuple of tuples or operators.
175+
- `α::Union{Nothing,Number}=nothing`: A scalar to pre-multiply the operators.
176+
177+
!!! warning "Beware of type-stability!"
178+
Please note that, unlike QuTiP, this function doesn't support `op_func_list` as `Vector` type. This is related to the type-stability issue. See the Section [The Importance of Type-Stability](@ref doc:Type-Stability) for more details.
179+
180+
# Notes
181+
- If `α` is provided, all the operators in `op_func_list` will be pre-multiplied by `α`. The `type` parameter is used to specify the type of the [`QuantumObject`](@ref), either `Operator` or `SuperOperator`. The `f` parameter is used to pre-apply a function to the operators before converting them to SciML operators.
182+
- `QobjEvo` is a synonym of `QuantumObjectEvolution`
183+
184+
# Examples
185+
This operator can be initialized in the same way as the QuTiP `QobjEvo` object. For example
186+
```jldoctest qobjevo
187+
julia> a = tensor(destroy(10), qeye(2))
188+
Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=false
189+
20×20 SparseMatrixCSC{ComplexF64, Int64} with 18 stored entries:
190+
⎡⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⎤
191+
⎢⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⎥
192+
⎢⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⎥
193+
⎢⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⎥
194+
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⎦
195+
196+
julia> σm = tensor(qeye(10), sigmam())
197+
Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=false
198+
20×20 SparseMatrixCSC{ComplexF64, Int64} with 10 stored entries:
199+
⎡⠂⡀⠀⠀⠀⠀⠀⠀⠀⠀⎤
200+
⎢⠀⠀⠂⡀⠀⠀⠀⠀⠀⠀⎥
201+
⎢⠀⠀⠀⠀⠂⡀⠀⠀⠀⠀⎥
202+
⎢⠀⠀⠀⠀⠀⠀⠂⡀⠀⠀⎥
203+
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠂⡀⎦
204+
205+
julia> coef1(p, t) = exp(-1im * t)
206+
coef1 (generic function with 1 method)
207+
208+
julia> coef2(p, t) = sin(t)
209+
coef2 (generic function with 1 method)
210+
211+
julia> op1 = QobjEvo(((a, coef1), (σm, coef2)))
212+
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
213+
(ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20) + ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20))
214+
```
215+
216+
We can also concretize the operator at a specific time `t`
217+
```jldoctest qobjevo
218+
julia> op1(0.1)
219+
Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=false
220+
20×20 SparseMatrixCSC{ComplexF64, Int64} with 28 stored entries:
221+
⎡⠂⡑⢄⠀⠀⠀⠀⠀⠀⠀⎤
222+
⎢⠀⠀⠂⡑⢄⠀⠀⠀⠀⠀⎥
223+
⎢⠀⠀⠀⠀⠂⡑⢄⠀⠀⠀⎥
224+
⎢⠀⠀⠀⠀⠀⠀⠂⡑⢄⠀⎥
225+
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠂⡑⎦
226+
```
227+
228+
It also supports parameter-dependent time evolution
229+
```jldoctest qobjevo
230+
julia> coef1(p, t) = exp(-1im * p.ω1 * t)
231+
coef1 (generic function with 1 method)
232+
233+
julia> coef2(p, t) = sin(p.ω2 * t)
234+
coef2 (generic function with 1 method)
235+
236+
julia> op1 = QobjEvo(((a, coef1), (σm, coef2)))
237+
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
238+
(ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20) + ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20))
239+
240+
julia> p = (ω1 = 1.0, ω2 = 0.5)
241+
(ω1 = 1.0, ω2 = 0.5)
242+
243+
julia> op1(p, 0.1)
244+
Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=false
245+
20×20 SparseMatrixCSC{ComplexF64, Int64} with 28 stored entries:
246+
⎡⠂⡑⢄⠀⠀⠀⠀⠀⠀⠀⎤
247+
⎢⠀⠀⠂⡑⢄⠀⠀⠀⠀⠀⎥
248+
⎢⠀⠀⠀⠀⠂⡑⢄⠀⠀⠀⎥
249+
⎢⠀⠀⠀⠀⠀⠀⠂⡑⢄⠀⎥
250+
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠂⡑⎦
251+
```
252+
"""
165253
function QuantumObjectEvolution(
166254
op_func_list::Tuple,
167255
α::Union{Nothing,Number} = nothing;
@@ -187,6 +275,35 @@ QuantumObjectEvolution(
187275
type::Union{Nothing,QuantumObjectType} = nothing,
188276
) = QuantumObjectEvolution((op_func,), α; type = type)
189277

278+
@doc raw"""
279+
QuantumObjectEvolution(op::QuantumObject, f::Function, α::Union{Nothing,Number}=nothing; type::Union{Nothing,QuantumObjectType} = nothing)
280+
QobjEvo(op::QuantumObject, f::Function, α::Union{Nothing,Number}=nothing; type::Union{Nothing,QuantumObjectType} = nothing)
281+
282+
Generate [`QuantumObjectEvolution`](@ref).
283+
284+
# Notes
285+
- The `f` parameter is used to pre-apply a function to the operators before converting them to SciML operators. The `type` parameter is used to specify the type of the [`QuantumObject`](@ref), either `Operator` or `SuperOperator`.
286+
- `QobjEvo` is a synonym of `QuantumObjectEvolution`.
287+
288+
# Examples
289+
```jldoctest
290+
julia> a = tensor(destroy(10), qeye(2))
291+
Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=false
292+
20×20 SparseMatrixCSC{ComplexF64, Int64} with 18 stored entries:
293+
⎡⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⎤
294+
⎢⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⎥
295+
⎢⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⎥
296+
⎢⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⎥
297+
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⎦
298+
299+
julia> coef(p, t) = exp(-1im * t)
300+
coef (generic function with 1 method)
301+
302+
julia> op = QobjEvo(a, coef)
303+
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
304+
ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20)
305+
```
306+
"""
190307
QuantumObjectEvolution(
191308
op::QuantumObject,
192309
f::Function,

0 commit comments

Comments
 (0)