You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/qobj/operators.jl
+29-12Lines changed: 29 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ export tunneling
13
13
export qft
14
14
15
15
@docraw"""
16
-
rand_unitary(dimensions, distribution=:haar)
16
+
rand_unitary(dimensions, distribution=Val(:haar))
17
17
18
18
Returns a random unitary [`QuantumObject`](@ref).
19
19
@@ -27,10 +27,13 @@ The `distribution` specifies which of the method used to obtain the unitary matr
27
27
28
28
# References
29
29
1. [F. Mezzadri, How to generate random matrices from the classical compact groups, arXiv:math-ph/0609050 (2007)](https://arxiv.org/abs/math-ph/0609050)
30
+
31
+
!!! warning "Beware of type-stability!"
32
+
If you want to keep type stability, it is recommended to use `rand_unitary(dimensions, Val(distribution))` instead of `rand_unitary(dimensions, distribution)`. Also, put `dimensions` as `Tuple` or `SVector`. 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.
4×4 SparseMatrixCSC{ComplexF64, Int64} with 4 stored entries:
260
+
1.5+0.0im ⋅ ⋅ ⋅
261
+
⋅ 0.5+0.0im ⋅ ⋅
262
+
⋅ ⋅ -0.5+0.0im ⋅
263
+
⋅ ⋅ ⋅ -1.5+0.0im
253
264
```
265
+
266
+
!!! warning "Beware of type-stability!"
267
+
If you want to keep type stability, it is recommended to use `jmat(j, Val(which))` instead of `jmat(j, which)`. 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.
Note that the site index `j` should satisfy: `0 ≤ j ≤ N - 1`.
429
443
430
-
> [!IMPORTANT]
431
-
> If you want to keep type stability, it is recommended to use `fdestroy(Val(N), j)` instead of `fdestroy(N, j)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details.
444
+
!!! warning "Beware of type-stability!"
445
+
If you want to keep type stability, it is recommended to use `fdestroy(Val(N), j)` instead of `fdestroy(N, j)`. 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.
Note that the site index `j` should satisfy: `0 ≤ j ≤ N - 1`.
446
460
447
-
> [!IMPORTANT]
448
-
> If you want to keep type stability, it is recommended to use `fcreate(Val(N), j)` instead of `fcreate(N, j)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details.
461
+
!!! warning "Beware of type-stability!"
462
+
If you want to keep type stability, it is recommended to use `fcreate(Val(N), j)` instead of `fcreate(N, j)`. 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.
@@ -485,8 +499,8 @@ where ``N`` is the number of basis states in the Hilbert space, and ``m`` is the
485
499
486
500
If `sparse=true`, the operator is returned as a sparse matrix, otherwise a dense matrix is returned.
487
501
488
-
> [!IMPORTANT]
489
-
> If you want to keep type stability, it is recommended to use `tunneling(N, m, Val(sparse))` instead of `tunneling(N, m, sparse)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details.
502
+
!!! warning "Beware of type-stability!"
503
+
If you want to keep type stability, it is recommended to use `tunneling(N, m, Val(sparse))` instead of `tunneling(N, m, sparse)`. 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.
(m <1) &&throw(ArgumentError("The number of excitations (m) cannot be less than 1"))
@@ -522,6 +536,9 @@ The `dimensions` can be either the following types:
522
536
```
523
537
524
538
where ``\omega = \exp(\frac{2 \pi i}{N})``.
539
+
540
+
!!! warning "Beware of type-stability!"
541
+
It is highly recommended to use `qft(dimensions)` with `dimensions` as `Tuple` or `SVector` to keep type stability. See the [related Section](@ref doc:Type-Stability) about type stability for more details.
Copy file name to clipboardExpand all lines: src/qobj/states.jl
+33-12Lines changed: 33 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -15,41 +15,50 @@ Returns a zero [`Ket`](@ref) vector with given argument `dimensions`.
15
15
The `dimensions` can be either the following types:
16
16
- `dimensions::Int`: Number of basis states in the Hilbert space.
17
17
- `dimensions::Union{AbstractVector{Int}, Tuple}`: list of dimensions representing the each number of basis in the subsystems.
18
+
19
+
!!! warning "Beware of type-stability!"
20
+
It is highly recommended to use `zero_ket(dimensions)` with `dimensions` as `Tuple` or `SVector` to keep type stability. See the [related Section](@ref doc:Type-Stability) about type stability for more details.
Generates a fock state ``\ket{\psi}`` of dimension `N`.
27
30
28
31
It is also possible to specify the list of dimensions `dims` if different subsystems are present.
32
+
33
+
!!! warning "Beware of type-stability!"
34
+
If you want to keep type stability, it is recommended to use `fock(N, j, dims=dims, sparse=Val(sparse))` instead of `fock(N, j, dims=dims, sparse=sparse)`. Consider also to use `dims` as a `Tuple` or `SVector` instead of `Vector`. 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.
29
35
"""
30
36
functionfock(
31
37
N::Int,
32
-
pos::Int=0;
38
+
j::Int=0;
33
39
dims::Union{Int,AbstractVector{Int},Tuple}= N,
34
40
sparse::Union{Bool,Val}=Val(false),
35
41
)
36
42
ifgetVal(makeVal(sparse))
37
-
array =sparsevec([pos+1], [1.0+0im], N)
43
+
array =sparsevec([j+1], [1.0+0im], N)
38
44
else
39
45
array =zeros(ComplexF64, N)
40
-
array[pos+1] =1
46
+
array[j+1] =1
41
47
end
42
48
returnQuantumObject(array; type = Ket, dims = dims)
It is also possible to specify the list of dimensions `dims` if different subsystems are present.
57
+
58
+
!!! warning "Beware of type-stability!"
59
+
If you want to keep type stability, it is recommended to use `basis(N, j, dims=dims)` with `dims` as a `Tuple` or `SVector` instead of `Vector`. 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.
@@ -68,6 +77,9 @@ Generate a random normalized [`Ket`](@ref) vector with given argument `dimension
68
77
The `dimensions` can be either the following types:
69
78
- `dimensions::Int`: Number of basis states in the Hilbert space.
70
79
- `dimensions::Union{AbstractVector{Int},Tuple}`: list of dimensions representing the each number of basis in the subsystems.
80
+
81
+
!!! warning "Beware of type-stability!"
82
+
If you want to keep type stability, it is recommended to use `rand_ket(dimensions)` with `dimensions` as `Tuple` or `SVector` to keep type stability. See the [related Section](@ref doc:Type-Stability) about type stability for more details.
If you want to keep type stability, it is recommended to use `fock_dm(N, pos, dims=dims, sparse=Val(sparse))` instead of `fock_dm(N, pos, dims=dims, sparse=sparse)`. Consider also to use `dims` as a `Tuple` or `SVector` instead of `Vector`. 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.
85
100
"""
86
101
functionfock_dm(
87
102
N::Int,
@@ -113,8 +128,8 @@ Density matrix for a thermal state (generating thermal state probabilities) with
113
128
- `n::Real`: Expectation value for number of particles in the thermal state.
114
129
- `sparse::Union{Bool,Val}`: If `true`, return a sparse matrix representation.
115
130
116
-
> [!IMPORTANT]
117
-
> If you want to keep type stability, it is recommended to use `thermal_dm(N, n, Val(sparse))` instead of `thermal_dm(N, n, sparse)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details.
131
+
!!! warning "Beware of type-stability!"
132
+
If you want to keep type stability, it is recommended to use `thermal_dm(N, n, sparse=Val(sparse))` instead of `thermal_dm(N, n, sparse=sparse)`. 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.
@@ -135,6 +150,9 @@ Returns the maximally mixed density matrix with given argument `dimensions`.
135
150
The `dimensions` can be either the following types:
136
151
- `dimensions::Int`: Number of basis states in the Hilbert space.
137
152
- `dimensions::Union{AbstractVector{Int},Tuple}`: list of dimensions representing the each number of basis in the subsystems.
153
+
154
+
!!! warning "Beware of type-stability!"
155
+
If you want to keep type stability, it is recommended to use `maximally_mixed_dm(dimensions)` with `dimensions` as `Tuple` or `SVector` to keep type stability. See the [related Section](@ref doc:Type-Stability) about type stability for more details.
@@ -153,6 +171,9 @@ The `dimensions` can be either the following types:
153
171
154
172
The default keyword argument `rank = prod(dimensions)` (full rank).
155
173
174
+
!!! warning "Beware of type-stability!"
175
+
If you want to keep type stability, it is recommended to use `rand_dm(dimensions; rank=rank)` with `dimensions` as `Tuple` or `SVector` instead of `Vector`. 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.
176
+
156
177
# References
157
178
- [J. Ginibre, Statistical ensembles of complex, quaternion, and real matrices, Journal of Mathematical Physics 6.3 (1965): 440-449](https://doi.org/10.1063/1.1704292)
158
179
- [K. Życzkowski, et al., Generating random density matrices, Journal of Mathematical Physics 52, 062201 (2011)](http://dx.doi.org/10.1063/1.3595693)
@@ -284,8 +305,8 @@ Returns the `n`-qubit [W-state](https://en.wikipedia.org/wiki/W_state):
> If you want to keep type stability, it is recommended to use `w_state(Val(n))` instead of `w_state(n)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details.
308
+
!!! warning "Beware of type-stability!"
309
+
If you want to keep type stability, it is recommended to use `w_state(Val(n))` instead of `w_state(n)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details.
Here, `d` specifies the dimension of each qudit. Default to `d=2` (qubit).
307
328
308
-
> [!IMPORTANT]
309
-
> If you want to keep type stability, it is recommended to use `ghz_state(Val(n); kwargs...)` instead of `ghz_state(n; kwargs...)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details.
329
+
!!! warning "Beware of type-stability!"
330
+
If you want to keep type stability, it is recommended to use `ghz_state(Val(n))` instead of `ghz_state(n)`. See [this link](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-value-type) and the [related Section](@ref doc:Type-Stability) for more details.
0 commit comments