Skip to content

Commit ca872f6

Browse files
authored
Add doctest in all docstrings (#294)
2 parents 0f5a9b1 + c21855b commit ca872f6

14 files changed

+132
-214
lines changed

src/linear_maps.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ It is typically represented as a matrix with dimensions given by `size`, and thi
3030
3131
As an example, we now define the linear map used in the [`eigsolve_al`](@ref) function for Arnoldi-Lindblad eigenvalue solver:
3232
33-
```julia-repl
33+
```julia
3434
struct ArnoldiLindbladIntegratorMap{T,TS,TI} <: AbstractLinearMap{T,TS}
3535
elty::Type{T}
3636
size::TS

src/metrics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ matrix ``\hat{\rho}``.
1919
# Examples
2020
2121
Pure state:
22-
```
22+
```jldoctest
2323
julia> ψ = fock(2,0)
2424
Quantum Object: type=Ket dims=[2] size=(2,)
2525
2-element Vector{ComplexF64}:
@@ -37,7 +37,7 @@ julia> entropy_vn(ρ, base=2)
3737
```
3838
3939
Mixed state:
40-
```
40+
```jldoctest
4141
julia> ρ = maximally_mixed_dm(2)
4242
Quantum Object: type=Operator dims=[2] size=(2, 2) ishermitian=true
4343
2×2 Diagonal{ComplexF64, Vector{ComplexF64}}:

src/negativity.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ and ``\Vert \hat{X} \Vert_1=\textrm{Tr}\sqrt{\hat{X}^\dagger \hat{X}}`` is the t
1717
1818
# Examples
1919
20-
```
20+
```jldoctest
2121
julia> Ψ = bell_state(0, 0)
2222
Quantum Object: type=Ket dims=[2, 2] size=(4,)
2323
4-element Vector{ComplexF64}:
@@ -34,8 +34,8 @@ Quantum Object: type=Operator dims=[2, 2] size=(4, 4) ishermitian=true
3434
0.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im
3535
0.5+0.0im 0.0+0.0im 0.0+0.0im 0.5+0.0im
3636
37-
julia> negativity(ρ, 2)
38-
0.4999999999999998
37+
julia> round(negativity(ρ, 2), digits=2)
38+
0.5
3939
```
4040
"""
4141
function negativity::QuantumObject, subsys::Int; logarithmic::Bool = false)

src/qobj/arithmetic_and_attributes.jl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ Note that this function only supports for [`Operator`](@ref) and [`SuperOperator
217217
218218
# Examples
219219
220-
```
220+
```jldoctest
221221
julia> a = destroy(20)
222222
Quantum Object: type=Operator dims=[20] size=(20, 20) ishermitian=false
223223
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:
224-
⠈⠢⡀⠀⠀⠀⠀⠀⠀⠀
225-
⠀⠀⠈⠢⡀⠀⠀⠀⠀⠀
226-
⠀⠀⠀⠀⠈⠢⡀⠀⠀⠀
227-
⠀⠀⠀⠀⠀⠀⠈⠢⡀⠀
228-
⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢
224+
⠈⠢⡀⠀⠀⠀⠀⠀⠀⠀
225+
⠀⠀⠈⠢⡀⠀⠀⠀⠀⠀
226+
⠀⠀⠀⠀⠈⠢⡀⠀⠀⠀
227+
⠀⠀⠀⠀⠀⠀⠈⠢⡀⠀
228+
⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢
229229
230230
julia> tr(a' * a)
231231
190.0 + 0.0im
@@ -257,7 +257,7 @@ Return the standard vector `p`-norm or [Schatten](https://en.wikipedia.org/wiki/
257257
258258
# Examples
259259
260-
```
260+
```jldoctest
261261
julia> ψ = fock(10, 2)
262262
Quantum Object: type=Ket dims=[10] size=(10,)
263263
10-element Vector{ComplexF64}:
@@ -474,8 +474,9 @@ proj(ψ::QuantumObject{<:AbstractArray{T},BraQuantumObject}) where {T} = ψ' *
474474
Note that this function will always return [`Operator`](@ref). No matter the input [`QuantumObject`](@ref) is a [`Ket`](@ref), [`Bra`](@ref), or [`Operator`](@ref).
475475
476476
# Examples
477+
477478
Two qubits in the state ``\ket{\psi} = \ket{e,g}``:
478-
```
479+
```jldoctest
479480
julia> ψ = kron(fock(2,0), fock(2,1))
480481
Quantum Object: type=Ket dims=[2, 2] size=(4,)
481482
4-element Vector{ComplexF64}:
@@ -492,7 +493,7 @@ Quantum Object: type=Operator dims=[2] size=(2, 2) ishermitian=true
492493
```
493494
494495
or in an entangled state ``\ket{\psi} = \frac{1}{\sqrt{2}} \left( \ket{e,e} + \ket{g,g} \right)``:
495-
```
496+
```jldoctest
496497
julia> ψ = 1 / √2 * (kron(fock(2,0), fock(2,0)) + kron(fock(2,1), fock(2,1)))
497498
Quantum Object: type=Ket dims=[2, 2] size=(4,)
498499
4-element Vector{ComplexF64}:
@@ -693,12 +694,16 @@ Note that this method currently works for [`Ket`](@ref), [`Bra`](@ref), and [`Op
693694
694695
If `order = [2, 1, 3]`, the Hilbert space structure will be re-arranged: ``\mathcal{H}_1 \otimes \mathcal{H}_2 \otimes \mathcal{H}_3 \rightarrow \mathcal{H}_2 \otimes \mathcal{H}_1 \otimes \mathcal{H}_3``.
695696
696-
```
697-
julia> ψ1 = fock(2, 0)
698-
julia> ψ2 = fock(3, 1)
699-
julia> ψ3 = fock(4, 2)
700-
julia> ψ_123 = tensor(ψ1, ψ2, ψ3)
701-
julia> permute(ψ_123, [2, 1, 3]) ≈ tensor(ψ2, ψ1, ψ3)
697+
```jldoctest
698+
julia> ψ1 = fock(2, 0);
699+
700+
julia> ψ2 = fock(3, 1);
701+
702+
julia> ψ3 = fock(4, 2);
703+
704+
julia> ψ_123 = tensor(ψ1, ψ2, ψ3);
705+
706+
julia> permute(ψ_123, (2, 1, 3)) ≈ tensor(ψ2, ψ1, ψ3)
702707
true
703708
```
704709

src/qobj/eigsolve.jl

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,37 @@ A struct containing the eigenvalues, the eigenvectors, and some information from
3030
3131
# Examples
3232
One can obtain the eigenvalues and the corresponding [`QuantumObject`](@ref)-type eigenvectors by:
33-
```
34-
julia> result = eigenstates(sigmax());
33+
```jldoctest
34+
julia> result = eigenstates(sigmax())
35+
EigsolveResult: type=Operator dims=[2]
36+
values:
37+
2-element Vector{ComplexF64}:
38+
-1.0 + 0.0im
39+
1.0 + 0.0im
40+
vectors:
41+
2×2 Matrix{ComplexF64}:
42+
-0.707107+0.0im 0.707107+0.0im
43+
0.707107+0.0im 0.707107+0.0im
3544
36-
julia> λ, ψ, T = result;
45+
julia> λ, ψ, U = result;
3746
3847
julia> λ
3948
2-element Vector{ComplexF64}:
4049
-1.0 + 0.0im
4150
1.0 + 0.0im
4251
4352
julia> ψ
44-
2-element Vector{QuantumObject{Vector{ComplexF64}, KetQuantumObject}}:
45-
QuantumObject{Vector{ComplexF64}, KetQuantumObject}(ComplexF64[-0.7071067811865475 + 0.0im, 0.7071067811865475 + 0.0im], KetQuantumObject(), [2])
46-
QuantumObject{Vector{ComplexF64}, KetQuantumObject}(ComplexF64[0.7071067811865475 + 0.0im, 0.7071067811865475 + 0.0im], KetQuantumObject(), [2])
53+
2-element Vector{QuantumObject{Vector{ComplexF64}, KetQuantumObject, 1}}:
54+
Quantum Object: type=Ket dims=[2] size=(2,)
55+
2-element Vector{ComplexF64}:
56+
-0.7071067811865475 + 0.0im
57+
0.7071067811865475 + 0.0im
58+
Quantum Object: type=Ket dims=[2] size=(2,)
59+
2-element Vector{ComplexF64}:
60+
0.7071067811865475 + 0.0im
61+
0.7071067811865475 + 0.0im
4762
48-
julia> T
63+
julia> U
4964
2×2 Matrix{ComplexF64}:
5065
-0.707107+0.0im 0.707107+0.0im
5166
0.707107+0.0im 0.707107+0.0im
@@ -411,27 +426,20 @@ end
411426
Calculates the eigenvalues and eigenvectors of the [`QuantumObject`](@ref) `A` using
412427
the Julia [LinearAlgebra](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/) package.
413428
414-
```
429+
```jldoctest
415430
julia> a = destroy(5);
416431
417-
julia> H = a + a'
418-
Quantum Object: type=Operator dims=[5] size=(5, 5) ishermitian=true
419-
5×5 SparseMatrixCSC{ComplexF64, Int64} with 8 stored entries:
420-
⋅ 1.0+0.0im ⋅ ⋅ ⋅
421-
1.0+0.0im ⋅ 1.41421+0.0im ⋅ ⋅
422-
⋅ 1.41421+0.0im ⋅ 1.73205+0.0im ⋅
423-
⋅ ⋅ 1.73205+0.0im ⋅ 2.0+0.0im
424-
⋅ ⋅ ⋅ 2.0+0.0im ⋅
432+
julia> H = a + a';
425433
426434
julia> E, ψ, U = eigen(H)
427435
EigsolveResult: type=Operator dims=[5]
428436
values:
429-
5-element Vector{Float64}:
430-
-2.8569700138728
431-
-1.3556261799742608
432-
1.3322676295501878e-15
433-
1.3556261799742677
434-
2.8569700138728056
437+
5-element Vector{ComplexF64}:
438+
-2.8569700138728 + 0.0im
439+
-1.3556261799742608 + 0.0im
440+
1.3322676295501878e-15 + 0.0im
441+
1.3556261799742677 + 0.0im
442+
2.8569700138728056 + 0.0im
435443
vectors:
436444
5×5 Matrix{ComplexF64}:
437445
0.106101+0.0im -0.471249-0.0im … 0.471249-0.0im 0.106101-0.0im

src/qobj/functions.jl

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Note that `ψ` can also be given as a list of [`QuantumObject`](@ref), it return
3131
3232
# Examples
3333
34-
```
34+
```jldoctest
3535
julia> ψ = 1 / √2 * (fock(10,2) + fock(10,4));
3636
3737
julia> a = destroy(10);
@@ -153,40 +153,23 @@ Returns the [Kronecker product](https://en.wikipedia.org/wiki/Kronecker_product)
153153
154154
# Examples
155155
156-
```
156+
```jldoctest
157157
julia> a = destroy(20)
158158
Quantum Object: type=Operator dims=[20] size=(20, 20) ishermitian=false
159159
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:
160-
⠈⠢⡀⠀⠀⠀⠀⠀⠀⠀
161-
⠀⠀⠈⠢⡀⠀⠀⠀⠀⠀
162-
⠀⠀⠀⠀⠈⠢⡀⠀⠀⠀
163-
⠀⠀⠀⠀⠀⠀⠈⠢⡀⠀
164-
⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢
165-
166-
julia> kron(a, a)
167-
Quantum Object: type=Operator dims=[20, 20] size=(400, 400) ishermitian=false
168-
400×400 SparseMatrixCSC{ComplexF64, Int64} with 361 stored entries:
169-
⠀⠀⠘⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
170-
⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
171-
⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
172-
⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
173-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
174-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
175-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
176-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
177-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
178-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
179-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
180-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
181-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
182-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
183-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
184-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
185-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀
186-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀
187-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀
188-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀
189-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠦
160+
⎡⠈⠢⡀⠀⠀⠀⠀⠀⠀⠀⎤
161+
⎢⠀⠀⠈⠢⡀⠀⠀⠀⠀⠀⎥
162+
⎢⠀⠀⠀⠀⠈⠢⡀⠀⠀⠀⎥
163+
⎢⠀⠀⠀⠀⠀⠀⠈⠢⡀⠀⎥
164+
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢⎦
165+
166+
julia> O = kron(a, a);
167+
168+
julia> size(a), size(O)
169+
((20, 20), (400, 400))
170+
171+
julia> a.dims, O.dims
172+
([20], [20, 20])
190173
```
191174
"""
192175
function LinearAlgebra.kron(

src/qobj/operators.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ This operator acts on a fock state as ``\hat{a} \ket{n} = \sqrt{n} \ket{n-1}``.
8888
8989
# Examples
9090
91-
```
91+
```jldoctest
9292
julia> a = destroy(20)
9393
Quantum Object: type=Operator dims=[20] size=(20, 20) ishermitian=false
9494
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:
@@ -113,7 +113,7 @@ This operator acts on a fock state as ``\hat{a}^\dagger \ket{n} = \sqrt{n+1} \ke
113113
114114
# Examples
115115
116-
```
116+
```jldoctest
117117
julia> a_d = create(20)
118118
Quantum Object: type=Operator dims=[20] size=(20, 20) ishermitian=false
119119
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:
@@ -242,14 +242,14 @@ The parameter `which` specifies which of the following operator to return.
242242
Note that if the parameter `which` is not specified, returns a set of Spin-`j` operators: ``(\hat{S}_x, \hat{S}_y, \hat{S}_z)``
243243
244244
# Examples
245-
```
245+
```jldoctest
246246
julia> jmat(0.5, :x)
247247
Quantum Object: type=Operator dims=[2] size=(2, 2) ishermitian=true
248248
2×2 SparseMatrixCSC{ComplexF64, Int64} with 2 stored entries:
249249
⋅ 0.5+0.0im
250250
0.5+0.0im ⋅
251251
252-
julia> jmat(0.5, :-)
252+
julia> jmat(0.5, Val(:-))
253253
Quantum Object: type=Operator dims=[2] size=(2, 2) ishermitian=false
254254
2×2 SparseMatrixCSC{ComplexF64, Int64} with 1 stored entry:
255255
⋅ ⋅

src/qobj/quantum_object.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Julia struct representing any quantum objects.
1919
2020
# Examples
2121
22-
```
22+
```jldoctest
2323
julia> a = destroy(20)
2424
Quantum Object: type=Operator dims=[20] size=(20, 20) ishermitian=false
2525
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:

src/qobj/quantum_object_base.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export Bra, Ket, Operator, OperatorBra, OperatorKet, SuperOperator
1919
Abstract type for all quantum objects like [`QuantumObject`](@ref) and [`QuantumObjectEvolution`](@ref).
2020
2121
# Example
22-
```
22+
```jldoctest
2323
julia> sigmax() isa AbstractQuantumObject
2424
true
2525
```

0 commit comments

Comments
 (0)