Skip to content

Commit 270d3f6

Browse files
authored
Simplify synonyms (#355)
1 parent f5392ee commit 270d3f6

File tree

10 files changed

+194
-277
lines changed

10 files changed

+194
-277
lines changed

.github/workflows/Code-Quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
fail-fast: false
4040
matrix:
4141
version:
42-
- '1'
42+
- 'lts'
4343
os:
4444
- 'ubuntu-latest'
4545
arch:

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: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,15 @@ LinearAlgebra.:(/)(A::AbstractQuantumObject{DT}, n::T) where {DT,T<:Number} =
112112
get_typename_wrapper(A)(A.data / n, A.type, A.dims)
113113

114114
@doc raw"""
115+
A ⋅ B
115116
dot(A::QuantumObject, B::QuantumObject)
116117
117118
Compute the dot product between two [`QuantumObject`](@ref): ``\langle A | B \rangle``
118119
119120
Note that `A` and `B` should be [`Ket`](@ref) or [`OperatorKet`](@ref)
120121
121-
`A ⋅ B` (where `⋅` can be typed by tab-completing `\cdot` in the REPL) is a synonym for `dot(A, B)`
122+
!!! note
123+
`A ⋅ B` (where `⋅` can be typed by tab-completing `\cdot` in the REPL) is a synonym of `dot(A, B)`.
122124
"""
123125
function LinearAlgebra.dot(
124126
A::QuantumObject{DT1,OpType},
@@ -130,12 +132,16 @@ end
130132

131133
@doc raw"""
132134
dot(i::QuantumObject, A::AbstractQuantumObject j::QuantumObject)
135+
matrix_element(i::QuantumObject, A::AbstractQuantumObject j::QuantumObject)
133136
134137
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``.
135138
136139
Supports the following inputs:
137140
- `A` is in the type of [`Operator`](@ref), with `i` and `j` are both [`Ket`](@ref).
138141
- `A` is in the type of [`SuperOperator`](@ref), with `i` and `j` are both [`OperatorKet`](@ref)
142+
143+
!!! note
144+
`matrix_element(i, A, j)` is a synonym of `dot(i, A, j)`.
139145
"""
140146
function LinearAlgebra.dot(
141147
i::QuantumObject{DT1,KetQuantumObject},
@@ -195,10 +201,12 @@ LinearAlgebra.transpose(
195201
@doc raw"""
196202
A'
197203
adjoint(A::AbstractQuantumObject)
204+
dag(A::AbstractQuantumObject)
198205
199206
Lazy adjoint (conjugate transposition) of the [`AbstractQuantumObject`](@ref)
200207
201-
Note that `A'` is a synonym for `adjoint(A)`
208+
!!! note
209+
`A'` and `dag(A)` are synonyms of `adjoint(A)`.
202210
"""
203211
LinearAlgebra.adjoint(
204212
A::AbstractQuantumObject{DT,OpType},
@@ -310,13 +318,17 @@ end
310318

311319
@doc raw"""
312320
normalize(A::QuantumObject, p::Real)
321+
unit(A::QuantumObject, p::Real)
313322
314323
Return normalized [`QuantumObject`](@ref) so that its `p`-norm equals to unity, i.e. `norm(A, p) == 1`.
315324
316325
Support for the following types of [`QuantumObject`](@ref):
317326
- If `A` is [`Ket`](@ref) or [`Bra`](@ref), default `p = 2`
318327
- If `A` is [`Operator`](@ref), default `p = 1`
319328
329+
!!! note
330+
`unit` is a synonym of `normalize`.
331+
320332
Also, see [`norm`](@ref) about its definition for different types of [`QuantumObject`](@ref).
321333
"""
322334
LinearAlgebra.normalize(
@@ -375,7 +387,8 @@ LinearAlgebra.rmul!(B::QuantumObject{<:AbstractArray}, a::Number) = (rmul!(B.dat
375387
376388
Matrix square root of [`QuantumObject`](@ref)
377389
378-
Note that `√(A)` is a synonym for `sqrt(A)`
390+
!!! note
391+
`√(A)` (where `√` can be typed by tab-completing `\sqrt` in the REPL) is a synonym of `sqrt(A)`.
379392
"""
380393
LinearAlgebra.sqrt(A::QuantumObject{<:AbstractArray{T}}) where {T} =
381394
QuantumObject(sqrt(sparse_to_dense(A.data)), A.type, A.dims)

src/qobj/boolean_functions.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ 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
69+
`isherm` is a synonym of `ishermitian`.
6670
"""
6771
LinearAlgebra.ishermitian(A::AbstractQuantumObject) = ishermitian(A.data)
6872

src/qobj/functions.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,15 @@ 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
158+
`tensor` and `⊗` (where `⊗` can be typed by tab-completing `\otimes` in the REPL) are synonyms of `kron`.
159+
154160
# Examples
155161
156162
```jldoctest

src/qobj/operators.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,16 @@ 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
424425
Note that `type` can only be either [`Operator`](@ref) or [`SuperOperator`](@ref)
426+
427+
!!! note
428+
`qeye` is a synonym of `eye`.
425429
"""
426430
eye(
427431
N::Int;

src/qobj/quantum_object.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,18 @@ 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} =
54+
QuantumObject(A, type, SVector{1,Int}(dims))
55+
56+
@doc raw"""
57+
Qobj(A::AbstractArray; type = nothing, dims = nothing)
58+
QuantumObject(A::AbstractArray; type = nothing, dims = nothing)
5659
60+
Generate [`QuantumObject`](@ref) with a given `A::AbstractArray` and specified `type::QuantumObjectType` and `dims`.
61+
62+
!!! note
63+
`Qobj` is a synonym of `QuantumObject`.
64+
"""
5765
function QuantumObject(
5866
A::AbstractMatrix{T};
5967
type::ObjType = nothing,

src/qobj/quantum_object_base.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,15 @@ 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
132+
`shape` is a synonym of `size`.
128133
"""
129134
Base.size(A::AbstractQuantumObject) = size(A.data)
130135
Base.size(A::AbstractQuantumObject, idx::Int) = size(A.data, idx)

src/qobj/quantum_object_evo.jl

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#=
2+
This file defines the QuantumObjectEvolution (QobjEvo) structure.
3+
=#
4+
15
export QuantumObjectEvolution
26

37
@doc raw"""
@@ -30,7 +34,7 @@ Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=fal
3034
julia> coef1(p, t) = exp(-1im * t)
3135
coef1 (generic function with 1 method)
3236
33-
julia> op = QuantumObjectEvolution(a, coef1)
37+
julia> op = QobjEvo(a, coef1)
3438
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
3539
ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20)
3640
```
@@ -50,7 +54,7 @@ Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=fal
5054
julia> coef2(p, t) = sin(t)
5155
coef2 (generic function with 1 method)
5256
53-
julia> op1 = QuantumObjectEvolution(((a, coef1), (σm, coef2)))
57+
julia> op1 = QobjEvo(((a, coef1), (σm, coef2)))
5458
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
5559
(ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20) + ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20))
5660
```
@@ -75,7 +79,7 @@ coef1 (generic function with 1 method)
7579
julia> coef2(p, t) = sin(p.ω2 * t)
7680
coef2 (generic function with 1 method)
7781
78-
julia> op1 = QuantumObjectEvolution(((a, coef1), (σm, coef2)))
82+
julia> op1 = QobjEvo(((a, coef1), (σm, coef2)))
7983
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
8084
(ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20) + ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20))
8185
@@ -143,9 +147,12 @@ function QuantumObjectEvolution(data::AbstractSciMLOperator, type::QuantumObject
143147
end
144148

145149
@doc raw"""
150+
QobjEvo(data::AbstractSciMLOperator; type::QuantumObjectType = Operator, dims = nothing)
146151
QuantumObjectEvolution(data::AbstractSciMLOperator; type::QuantumObjectType = Operator, dims = nothing)
147152
148153
Generate a [`QuantumObjectEvolution`](@ref) object from a [`SciMLOperator`](https://github.com/SciML/SciMLOperators.jl), in the same way as [`QuantumObject`](@ref) for `AbstractArray` inputs.
154+
155+
Note that `QobjEvo` is a synonym of `QuantumObjectEvolution`
149156
"""
150157
function QuantumObjectEvolution(data::AbstractSciMLOperator; type::QuantumObjectType = Operator, dims = nothing)
151158
_size = _get_size(data)
@@ -161,7 +168,93 @@ function QuantumObjectEvolution(data::AbstractSciMLOperator; type::QuantumObject
161168
return QuantumObjectEvolution(data, type, dims)
162169
end
163170

164-
# Make the QuantumObjectEvolution, with the option to pre-multiply by a scalar
171+
@doc raw"""
172+
QobjEvo(op_func_list::Union{Tuple,AbstractQuantumObject}, α::Union{Nothing,Number}=nothing; type::Union{Nothing, QuantumObjectType}=nothing)
173+
QuantumObjectEvolution(op_func_list::Union{Tuple,AbstractQuantumObject}, α::Union{Nothing,Number}=nothing; type::Union{Nothing, QuantumObjectType}=nothing)
174+
175+
Generate [`QuantumObjectEvolution`](@ref).
176+
177+
# Arguments
178+
- `op_func_list::Union{Tuple,AbstractQuantumObject}`: A tuple of tuples or operators.
179+
- `α::Union{Nothing,Number}=nothing`: A scalar to pre-multiply the operators.
180+
181+
!!! warning "Beware of type-stability!"
182+
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.
183+
184+
Note that 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.
185+
186+
!!! note
187+
`QobjEvo` is a synonym of `QuantumObjectEvolution`.
188+
189+
# Examples
190+
This operator can be initialized in the same way as the QuTiP `QobjEvo` object. For example
191+
```jldoctest qobjevo
192+
julia> a = tensor(destroy(10), qeye(2))
193+
Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=false
194+
20×20 SparseMatrixCSC{ComplexF64, Int64} with 18 stored entries:
195+
⎡⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⎤
196+
⎢⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⎥
197+
⎢⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⎥
198+
⎢⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⎥
199+
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⎦
200+
201+
julia> σm = tensor(qeye(10), sigmam())
202+
Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=false
203+
20×20 SparseMatrixCSC{ComplexF64, Int64} with 10 stored entries:
204+
⎡⠂⡀⠀⠀⠀⠀⠀⠀⠀⠀⎤
205+
⎢⠀⠀⠂⡀⠀⠀⠀⠀⠀⠀⎥
206+
⎢⠀⠀⠀⠀⠂⡀⠀⠀⠀⠀⎥
207+
⎢⠀⠀⠀⠀⠀⠀⠂⡀⠀⠀⎥
208+
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠂⡀⎦
209+
210+
julia> coef1(p, t) = exp(-1im * t)
211+
coef1 (generic function with 1 method)
212+
213+
julia> coef2(p, t) = sin(t)
214+
coef2 (generic function with 1 method)
215+
216+
julia> op1 = QobjEvo(((a, coef1), (σm, coef2)))
217+
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
218+
(ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20) + ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20))
219+
```
220+
221+
We can also concretize the operator at a specific time `t`
222+
```jldoctest qobjevo
223+
julia> op1(0.1)
224+
Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=false
225+
20×20 SparseMatrixCSC{ComplexF64, Int64} with 28 stored entries:
226+
⎡⠂⡑⢄⠀⠀⠀⠀⠀⠀⠀⎤
227+
⎢⠀⠀⠂⡑⢄⠀⠀⠀⠀⠀⎥
228+
⎢⠀⠀⠀⠀⠂⡑⢄⠀⠀⠀⎥
229+
⎢⠀⠀⠀⠀⠀⠀⠂⡑⢄⠀⎥
230+
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠂⡑⎦
231+
```
232+
233+
It also supports parameter-dependent time evolution
234+
```jldoctest qobjevo
235+
julia> coef1(p, t) = exp(-1im * p.ω1 * t)
236+
coef1 (generic function with 1 method)
237+
238+
julia> coef2(p, t) = sin(p.ω2 * t)
239+
coef2 (generic function with 1 method)
240+
241+
julia> op1 = QobjEvo(((a, coef1), (σm, coef2)))
242+
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
243+
(ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20) + ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20))
244+
245+
julia> p = (ω1 = 1.0, ω2 = 0.5)
246+
(ω1 = 1.0, ω2 = 0.5)
247+
248+
julia> op1(p, 0.1)
249+
Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=false
250+
20×20 SparseMatrixCSC{ComplexF64, Int64} with 28 stored entries:
251+
⎡⠂⡑⢄⠀⠀⠀⠀⠀⠀⠀⎤
252+
⎢⠀⠀⠂⡑⢄⠀⠀⠀⠀⠀⎥
253+
⎢⠀⠀⠀⠀⠂⡑⢄⠀⠀⠀⎥
254+
⎢⠀⠀⠀⠀⠀⠀⠂⡑⢄⠀⎥
255+
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠂⡑⎦
256+
```
257+
"""
165258
function QuantumObjectEvolution(
166259
op_func_list::Tuple,
167260
α::Union{Nothing,Number} = nothing;
@@ -187,6 +280,35 @@ QuantumObjectEvolution(
187280
type::Union{Nothing,QuantumObjectType} = nothing,
188281
) = QuantumObjectEvolution((op_func,), α; type = type)
189282

283+
@doc raw"""
284+
QuantumObjectEvolution(op::QuantumObject, f::Function, α::Union{Nothing,Number}=nothing; type::Union{Nothing,QuantumObjectType} = nothing)
285+
QobjEvo(op::QuantumObject, f::Function, α::Union{Nothing,Number}=nothing; type::Union{Nothing,QuantumObjectType} = nothing)
286+
287+
Generate [`QuantumObjectEvolution`](@ref).
288+
289+
# Notes
290+
- 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`.
291+
- `QobjEvo` is a synonym of `QuantumObjectEvolution`.
292+
293+
# Examples
294+
```jldoctest
295+
julia> a = tensor(destroy(10), qeye(2))
296+
Quantum Object: type=Operator dims=[10, 2] size=(20, 20) ishermitian=false
297+
20×20 SparseMatrixCSC{ComplexF64, Int64} with 18 stored entries:
298+
⎡⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⎤
299+
⎢⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⎥
300+
⎢⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⎥
301+
⎢⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⎥
302+
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⎦
303+
304+
julia> coef(p, t) = exp(-1im * t)
305+
coef (generic function with 1 method)
306+
307+
julia> op = QobjEvo(a, coef)
308+
Quantum Object Evo.: type=Operator dims=[10, 2] size=(20, 20) ishermitian=true isconstant=false
309+
ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20)
310+
```
311+
"""
190312
QuantumObjectEvolution(
191313
op::QuantumObject,
192314
f::Function,

0 commit comments

Comments
 (0)