Skip to content

Commit 3bd3960

Browse files
committed
update docstrings and documentation
1 parent 4ade675 commit 3bd3960

File tree

3 files changed

+109
-31
lines changed

3 files changed

+109
-31
lines changed

docs/src/resources/api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ end
1818

1919
```@docs
2020
Space
21+
EnrSpace
2122
Dimensions
2223
GeneralDimensions
2324
AbstractQuantumObject
@@ -122,6 +123,8 @@ coherent_dm
122123
thermal_dm
123124
maximally_mixed_dm
124125
rand_dm
126+
enr_fock
127+
enr_thermal_dm
125128
spin_state
126129
spin_coherent
127130
bell_state
@@ -152,6 +155,8 @@ QuantumToolbox.momentum
152155
phase
153156
fdestroy
154157
fcreate
158+
enr_destroy
159+
enr_identity
155160
tunneling
156161
qft
157162
eye
@@ -312,6 +317,7 @@ PhysicalConstants
312317
convert_unit
313318
row_major_reshape
314319
meshgrid
320+
enr_state_dictionaries
315321
```
316322

317323
## [Visualization](@id doc-API:Visualization)

docs/src/users_guide/QuantumObject/QuantumObject.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,16 @@ Manually specifying the data for each quantum object is inefficient. Even more s
6666

6767
### States
6868
- [`zero_ket`](@ref): zero ket vector
69-
- [`fock`](@ref) or [`basis`](@ref): fock state ket vector
70-
- [`fock_dm`](@ref): density matrix of a fock state
69+
- [`fock`](@ref) or [`basis`](@ref): Fock state ket vector
70+
- [`fock_dm`](@ref): density matrix of a Fock state
7171
- [`coherent`](@ref): coherent state ket vector
7272
- [`rand_ket`](@ref): random ket vector
7373
- [`coherent_dm`](@ref): density matrix of a coherent state
7474
- [`thermal_dm`](@ref): density matrix of a thermal state
7575
- [`maximally_mixed_dm`](@ref): density matrix of a maximally mixed state
7676
- [`rand_dm`](@ref): random density matrix
77+
- [`enr_fock`](@ref): Fock state in the excitation number restricted (ENR) space
78+
- [`enr_thermal_dm`](@ref): thermal state in the excitation number restricted (ENR) space
7779
- [`spin_state`](@ref): spin state
7880
- [`spin_coherent`](@ref): coherent spin state
7981
- [`bell_state`](@ref): Bell state
@@ -108,6 +110,8 @@ Manually specifying the data for each quantum object is inefficient. Even more s
108110
- [`spin_J_set`](@ref): a set of Spin-`j` operators ``(S_x, S_y, S_z)``
109111
- [`fdestroy`](@ref): fermion destruction operator
110112
- [`fcreate`](@ref): fermion creation operator
113+
- [`enr_destroy`](@ref): destruction operator in the excitation number restricted (ENR) space
114+
- [`enr_identity`](@ref): identity operator in the excitation number restricted (ENR) space
111115
- [`commutator`](@ref): commutator or anti-commutator
112116
- [`tunneling`](@ref): tunneling operator
113117
- [`qft`](@ref): discrete quantum Fourier transform matrix

src/qobj/energy_restricted.jl

Lines changed: 97 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This file defines the energy restricted space structure.
33
=#
44

55
export EnrSpace, enr_state_dictionaries
6-
export enr_identity, enr_fock, enr_destroy, enr_thermal_dm
6+
export enr_fock, enr_thermal_dm, enr_destroy, enr_identity
77

88
@doc raw"""
99
struct EnrSpace{N} <: AbstractSpace
@@ -14,16 +14,25 @@ export enr_identity, enr_fock, enr_destroy, enr_thermal_dm
1414
idx2state::Dict{Int,SVector{N,Int}}
1515
end
1616
17-
A structure that describes an excitation-number restricted (ENR) state space, where `N` is the number of sub-systems.
17+
A structure that describes an excitation number restricted (ENR) state space, where `N` is the number of sub-systems.
1818
1919
# Fields
2020
21-
- `size`: Number of states in the excitation-number restricted state space
21+
- `size`: Number of states in the excitation number restricted state space
2222
- `dims`: A list of the number of states in each sub-system
2323
- `n_excitations`: Maximum number of excitations
2424
- `state2idx`: A dictionary for looking up a state index from a state (`SVector`)
2525
- `idx2state`: A dictionary for looking up state (`SVector`) from a state index
2626
27+
# Functions
28+
29+
With this `EnrSpace`, one can use the following functions to construct states or operators in the excitation number restricted (ENR) space:
30+
31+
- [`enr_fock`](@ref)
32+
- [`enr_thermal_dm`](@ref)
33+
- [`enr_destroy`](@ref)
34+
- [`enr_identity`](@ref)
35+
2736
# Example
2837
2938
To construct an `EnrSpace`, we only need to specify the `dims` and `n_excitations`, namely
@@ -36,6 +45,9 @@ julia> n_excitations = 3;
3645
julia> EnrSpace(dims, n_excitations)
3746
EnrSpace((2, 2, 3), 3)
3847
```
48+
49+
!!! warning "Beware of type-stability!"
50+
It is highly recommended to use `EnrSpace(dims, n_excitations)` with `dims` as `Tuple` or `SVector` from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) to keep type stability. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) about type stability for more details.
3951
"""
4052
struct EnrSpace{N} <: AbstractSpace
4153
size::Int
@@ -111,12 +123,19 @@ function enr_state_dictionaries(dims::Union{AbstractVector{T},NTuple{N,T}}, exci
111123
end
112124
end
113125

114-
function enr_identity(dims::Union{AbstractVector{T},NTuple{N,T}}, excitations::Int) where {T<:Integer,N}
115-
s_enr = EnrSpace(dims, excitations)
116-
return enr_identity(s_enr)
117-
end
118-
enr_identity(s_enr::EnrSpace) = QuantumObject(Diagonal(ones(ComplexF64, s_enr.size)), Operator(), Dimensions(s_enr))
126+
@doc raw"""
127+
enr_fock(dims::Union{AbstractVector,Tuple}, excitations::Int, state::AbstractVector; sparse::Union{Bool,Val}=Val(false))
128+
enr_fock(s_enr::EnrSpace, state::AbstractVector; sparse::Union{Bool,Val}=Val(false))
129+
130+
Generate the Fock state representation ([`Ket`](@ref)) in an excitation number restricted state space ([`EnrSpace`](@ref)).
119131
132+
The arguments `dims` and `excitations` are used to generate [`EnrSpace`](@ref).
133+
134+
The `state` argument is a list of integers that specifies the state (in the number basis representation) for which to generate the Fock state representation.
135+
136+
!!! warning "Beware of type-stability!"
137+
It is highly recommended to use `enr_fock(dims, excitations, state)` with `dims` as `Tuple` or `SVector` from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) to keep type stability. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) about type stability for more details.
138+
"""
120139
function enr_fock(
121140
dims::Union{AbstractVector{T},NTuple{N,T}},
122141
excitations::Int,
@@ -137,6 +156,64 @@ function enr_fock(s_enr::EnrSpace, state::AbstractVector{T}; sparse::Union{Bool,
137156
return QuantumObject(array, Ket(), s_enr)
138157
end
139158

159+
@doc raw"""
160+
enr_thermal_dm(dims::Union{AbstractVector,Tuple}, excitations::Int, n::Union{Real,AbstractVector}; sparse::Union{Bool,Val}=Val(false))
161+
enr_thermal_dm(s_enr::EnrSpace, n::Union{Real,AbstractVector}; sparse::Union{Bool,Val}=Val(false))
162+
163+
Generate the thermal state (density [`Operator`](@ref)) in an excitation number restricted state space ([`EnrSpace`](@ref)).
164+
165+
The arguments `dims` and `excitations` are used to generate [`EnrSpace`](@ref).
166+
167+
The argument `n` is a list that specifies the expectation values for number of particles in each sub-system. If `n` is specified as a real number, it will apply to each sub-system.
168+
169+
!!! warning "Beware of type-stability!"
170+
It is highly recommended to use `enr_thermal_dm(dims, excitations, n)` with `dims` as `Tuple` or `SVector` from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) to keep type stability. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) about type stability for more details.
171+
"""
172+
function enr_thermal_dm(
173+
dims::Union{AbstractVector{T1},NTuple{N,T1}},
174+
excitations::Int,
175+
n::Union{T2,AbstractVector{T2}};
176+
sparse::Union{Bool,Val} = Val(false),
177+
) where {T1<:Integer,T2<:Real,N}
178+
s_enr = EnrSpace(dims, excitations)
179+
return enr_thermal_dm(s_enr, n; sparse = sparse)
180+
end
181+
function enr_thermal_dm(
182+
s_enr::EnrSpace{N},
183+
n::Union{T,AbstractVector{T}};
184+
sparse::Union{Bool,Val} = Val(false),
185+
) where {N,T<:Real}
186+
if n isa Real
187+
nvec = fill(n, N)
188+
else
189+
(length(n) == N) || throw(ArgumentError("The length of the vector `n` should be the same as `dims`."))
190+
nvec = n
191+
end
192+
193+
D = s_enr.size
194+
idx2state = s_enr.idx2state
195+
196+
diags = ComplexF64[prod((nvec ./ (1 .+ nvec)) .^ idx2state[idx]) for idx in 1:D]
197+
diags /= sum(diags)
198+
199+
if getVal(sparse)
200+
return QuantumObject(spdiagm(0 => diags), Operator(), s_enr)
201+
else
202+
return QuantumObject(diagm(0 => diags), Operator(), s_enr)
203+
end
204+
end
205+
206+
@doc raw"""
207+
enr_destroy(dims::Union{AbstractVector,Tuple}, excitations::Int)
208+
enr_destroy(s_enr::EnrSpace)
209+
210+
Generate a `Tuple` of annihilation operators for each sub-system in an excitation number restricted state space ([`EnrSpace`](@ref)). Thus, the return `Tuple` will have the same length as `dims`.
211+
212+
The arguments `dims` and `excitations` are used to generate [`EnrSpace`](@ref).
213+
214+
!!! warning "Beware of type-stability!"
215+
It is highly recommended to use `enr_destroy(dims, excitations)` with `dims` as `Tuple` or `SVector` from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) to keep type stability. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) about type stability for more details.
216+
"""
140217
function enr_destroy(dims::Union{AbstractVector{T},NTuple{N,T}}, excitations::Int) where {T<:Integer,N}
141218
s_enr = EnrSpace(dims, excitations)
142219
return enr_destroy(s_enr)
@@ -164,28 +241,19 @@ function enr_destroy(s_enr::EnrSpace{N}) where {N}
164241
return a_ops
165242
end
166243

167-
function enr_thermal_dm(
168-
dims::Union{AbstractVector{T1},NTuple{N,T1}},
169-
excitations::Int,
170-
n::Union{T2,AbstractVector{T2}},
171-
) where {T1<:Integer,T2<:Real,N}
172-
s_enr = EnrSpace(dims, excitations)
173-
return enr_thermal_dm(s_enr, n)
174-
end
175-
function enr_thermal_dm(s_enr::EnrSpace{N}, n::Union{T,AbstractVector{T}}) where {N,T<:Real}
176-
if n isa Real
177-
nvec = fill(n, N)
178-
else
179-
(length(n) == N) || throw(ArgumentError("The length of the vector `n` should be the same as `dims`."))
180-
nvec = n
181-
end
182-
183-
D = s_enr.size
184-
idx2state = s_enr.idx2state
244+
@doc raw"""
245+
enr_identity(dims::Union{AbstractVector,Tuple}, excitations::Int)
246+
enr_identity(s_enr::EnrSpace)
185247
186-
diags = ComplexF64[prod((nvec ./ (1 .+ nvec)) .^ idx2state[idx]) for idx in 1:D]
248+
Generate the identity operator in an excitation number restricted state space ([`EnrSpace`](@ref)).
187249
188-
diags /= sum(diags)
250+
The arguments `dims` and `excitations` are used to generate [`EnrSpace`](@ref).
189251
190-
return QuantumObject(Diagonal(diags), Operator(), s_enr)
252+
!!! warning "Beware of type-stability!"
253+
It is highly recommended to use `enr_identity(dims, excitations)` with `dims` as `Tuple` or `SVector` from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) to keep type stability. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) about type stability for more details.
254+
"""
255+
function enr_identity(dims::Union{AbstractVector{T},NTuple{N,T}}, excitations::Int) where {T<:Integer,N}
256+
s_enr = EnrSpace(dims, excitations)
257+
return enr_identity(s_enr)
191258
end
259+
enr_identity(s_enr::EnrSpace) = QuantumObject(Diagonal(ones(ComplexF64, s_enr.size)), Operator(), s_enr)

0 commit comments

Comments
 (0)