Functions operating on Qobj
QuantumToolbox also provide functions (methods) that operates on QuantumObject.
You can click the function links and see the corresponding docstring for more information.
Linear algebra and attributes
Here is a table that summarizes all the supported linear algebra functions and attribute functions operating on a given QuantumObject Q:
| Description | Function call | Synonyms |
|---|---|---|
| zero-like array | zero(Q) | qzero_like(Q) |
| identity-like matrix | one(Q) | qeye_like(Q) |
| conjugate | conj(Q) | - |
| transpose | transpose(Q) | trans(Q) |
| conjugate transposition | adjoint(Q) | Q', dag(Q) |
| partial transpose | partial_transpose(Q, mask) | - |
| dot product | dot(Q1, Q2) | - |
| generalized dot product | dot(Q1, Q2, Q3) | matrix_element(Q1, Q2, Q3) |
| trace | tr(Q) | - |
| partial trace | ptrace(Q, sel) | - |
| singular values | svdvals(Q) | - |
standard vector p-norm or Schatten p-norm | norm(Q, p) | - |
| normalization | normalize(Q, p) | unit(Q, p) |
| normalization (in-place) | normalize!(Q, p) | - |
| matrix inverse | inv(Q) | - |
| matrix square root | sqrt(Q) | √(Q), sqrtm(Q) |
| matrix logarithm | log(Q) | logm(Q) |
| matrix exponential | exp(Q) | expm(Q) |
| matrix sine | sin(Q) | sinm(Q) |
| matrix cosine | cos(Q) | cosm(Q) |
| diagonal elements | diag(Q) | - |
| projector | proj(Q) | - |
| purity | purity(Q) | - |
| permute | permute(Q, order) | - |
| remove small elements | tidyup(Q, tol) | - |
| remove small elements (in-place) | tidyup!(Q, tol) | - |
| get data | get_data(Q) | - |
| get coherence | get_coherence(Q) | - |
Eigen decomposition
LinearAlgebra.jl eigen solvers
eigvals: return eigenenergies (eigenvalues)eigen: returnEigsolveResult(contains eigenvalues and eigenvectors)
Only work for dense matrices
The eigen decomposition methods provided by LinearAlgebra.jl only works for dense matrices. If you pass-in a sparse matrix, the function automatically convert it to dense matrix.
Extra eigen solvers
eigenenergies: return eigenenergies (eigenvalues)eigenstates: returnEigsolveResult(contains eigenvalues and eigenvectors)eigsolve: using sparse eigen solver and returnEigsolveResult(contains eigenvalues and eigenvectors)eigsolve_al: using the Arnoldi-Lindblad eigen solver and returnEigsolveResult(contains eigenvalues and eigenvectors)
Examples
ψ = normalize(basis(4, 1) + basis(4, 2))
Quantum Object: type=Ket() dims=([4], [1]) size=(4,)
4-element Vector{ComplexF64}:
0.0 + 0.0im
0.7071067811865475 + 0.0im
0.7071067811865475 + 0.0im
0.0 + 0.0imψ'
Quantum Object: type=Bra() dims=([1], [4]) size=(1, 4)
1×4 adjoint(::Vector{ComplexF64}) with eltype ComplexF64:
0.0-0.0im 0.707107-0.0im 0.707107-0.0im 0.0-0.0imρ = coherent_dm(5, 1)
Quantum Object: type=Operator() dims=([5], [5]) size=(5, 5) ishermitian=true
5×5 Matrix{Float64}:
0.367911 0.367744 0.261054 0.146207 0.088267
0.367744 0.367577 0.260936 0.14614 0.0882269
0.261054 0.260936 0.185233 0.103742 0.0626306
0.146207 0.14614 0.103742 0.058102 0.035077
0.088267 0.0882269 0.0626306 0.035077 0.0211765diag(ρ)5-element Vector{Float64}:
0.3679111729923387
0.3675770456232403
0.18523331233838003
0.05810197190350208
0.021176497142538265get_data(ρ)5×5 Matrix{Float64}:
0.367911 0.367744 0.261054 0.146207 0.088267
0.367744 0.367577 0.260936 0.14614 0.0882269
0.261054 0.260936 0.185233 0.103742 0.0626306
0.146207 0.14614 0.103742 0.058102 0.035077
0.088267 0.0882269 0.0626306 0.035077 0.0211765norm(ρ)0.9999999999999996sqrtm(ρ)
Quantum Object: type=Operator() dims=([5], [5]) size=(5, 5) ishermitian=true
5×5 Matrix{Float64}:
0.367911 0.367744 0.261054 0.146207 0.088267
0.367744 0.367577 0.260936 0.14614 0.0882269
0.261054 0.260936 0.185233 0.103742 0.0626306
0.146207 0.14614 0.103742 0.058102 0.035077
0.088267 0.0882269 0.0626306 0.035077 0.0211765tr(ρ)0.9999999999999993eigenenergies(ρ)5-element Vector{Float64}:
-3.188562758433179e-17
-7.70881124130806e-18
2.0684351320241445e-17
1.0235138990670176e-16
0.9999999999999996result = eigenstates(ρ)EigsolveResult: type=Operator() dims=([5], [5])
values:
5-element Vector{Float64}:
-2.8177392874225097e-17
3.416070845000482e-17
7.728341127110703e-17
8.881784197001252e-16
0.9999999999999994
vectors:
5×5 Matrix{Float64}:
0.349081 0.699533 0.113691 -0.0892167 -0.606557
-0.698381 -0.132457 -0.345238 -0.0891762 -0.606281
0.596321 -0.648729 -0.185233 -0.0633045 -0.430387
-0.186568 -0.268811 0.913003 -0.0354544 -0.241044
0.0 0.0 0.0 0.989355 -0.145521λ, ψ = result
λ # eigenvalues5-element Vector{Float64}:
-2.8177392874225097e-17
3.416070845000482e-17
7.728341127110703e-17
8.881784197001252e-16
0.9999999999999994ψ # eigenvectors5-element Vector{QuantumObject{Ket, Dimensions{Space, Space}, Vector{Float64}}}:
Quantum Object: type=Ket() dims=([5], [1]) size=(5,)
5-element Vector{Float64}:
0.34908090726365426
-0.6983812275352181
0.5963209517322131
-0.18656769210014237
0.0
Quantum Object: type=Ket() dims=([5], [1]) size=(5,)
5-element Vector{Float64}:
0.6995328227558701
-0.1324572834510804
-0.6487290623177562
-0.2688112751584079
0.0
Quantum Object: type=Ket() dims=([5], [1]) size=(5,)
5-element Vector{Float64}:
0.11369058957774669
-0.34523801249281383
-0.18523271117272722
0.9130027422100534
0.0
Quantum Object: type=Ket() dims=([5], [1]) size=(5,)
5-element Vector{Float64}:
-0.08921674125585327
-0.0891762198903574
-0.06330447537681073
-0.035454413343867425
0.9893550944213416
Quantum Object: type=Ket() dims=([5], [1]) size=(5,)
5-element Vector{Float64}:
-0.6065568176126116
-0.606281325477901
-0.43038739797812414
-0.24104350624628368
-0.14552146626026788λ, ψ, T = result
T # transformation matrix5×5 Matrix{Float64}:
0.349081 0.699533 0.113691 -0.0892167 -0.606557
-0.698381 -0.132457 -0.345238 -0.0891762 -0.606281
0.596321 -0.648729 -0.185233 -0.0633045 -0.430387
-0.186568 -0.268811 0.913003 -0.0354544 -0.241044
0.0 0.0 0.0 0.989355 -0.145521