Skip to content

API

Table of contents

Quantum object (Qobj) and type

QuantumToolbox.Space Type
julia
struct Space <: AbstractSpace
    size::Int
end

A structure that describes a single Hilbert space with size = size.

source

QuantumToolbox.Dimensions Type
julia
struct Dimensions{N,T<:Tuple} <: AbstractDimensions{N}
    to::T
end

A structure that describes the Hilbert Space of each subsystems.

source

QuantumToolbox.GeneralDimensions Type
julia
struct GeneralDimensions{N,T1<:Tuple,T2<:Tuple} <: AbstractDimensions{N}
    to::T1
    from::T2
end

A structure that describes the left-hand side (to) and right-hand side (from) Hilbert Space of an Operator.

source

QuantumToolbox.AbstractQuantumObject Type
julia
abstract type AbstractQuantumObject{ObjType,DimType,DataType}

Abstract type for all quantum objects like QuantumObject and QuantumObjectEvolution.

Example

julia
julia> sigmax() isa AbstractQuantumObject
true

source

QuantumToolbox.BraQuantumObject Type
julia
BraQuantumObject <: QuantumObjectType

Constructor representing a bra state ψ|.

source

QuantumToolbox.Bra Constant
julia
const Bra = BraQuantumObject()

A constant representing the type of BraQuantumObject: a bra state ψ|

source

QuantumToolbox.KetQuantumObject Type
julia
KetQuantumObject <: QuantumObjectType

Constructor representing a ket state |ψ.

source

QuantumToolbox.Ket Constant
julia
const Ket = KetQuantumObject()

A constant representing the type of KetQuantumObject: a ket state |ψ

source

QuantumToolbox.OperatorQuantumObject Type
julia
OperatorQuantumObject <: QuantumObjectType

Constructor representing an operator O^.

source

QuantumToolbox.Operator Constant
julia
const Operator = OperatorQuantumObject()

A constant representing the type of OperatorQuantumObject: an operator O^

source

QuantumToolbox.OperatorBraQuantumObject Type
julia
OperatorBraQuantumObject <: QuantumObjectType

Constructor representing a bra state in the SuperOperator formalism ρ|.

source

QuantumToolbox.OperatorBra Constant
julia
const OperatorBra = OperatorBraQuantumObject()

A constant representing the type of OperatorBraQuantumObject: a bra state in the SuperOperator formalism ρ|.

source

QuantumToolbox.OperatorKetQuantumObject Type
julia
OperatorKetQuantumObject <: QuantumObjectType

Constructor representing a ket state in the SuperOperator formalism |ρ.

source

QuantumToolbox.OperatorKet Constant
julia
const OperatorKet = OperatorKetQuantumObject()

A constant representing the type of OperatorKetQuantumObject: a ket state in the SuperOperator formalism |ρ

source

QuantumToolbox.SuperOperatorQuantumObject Type
julia
SuperOperatorQuantumObject <: QuantumObjectType

Constructor representing a super-operator O^ acting on vectorized density operator matrices.

source

QuantumToolbox.SuperOperator Constant
julia
const SuperOperator = SuperOperatorQuantumObject()

A constant representing the type of SuperOperatorQuantumObject: a super-operator O^ acting on vectorized density operator matrices

source

QuantumToolbox.QuantumObject Type
julia
struct QuantumObject{ObjType<:QuantumObjectType,DimType<:AbstractDimensions,DataType<:AbstractArray} <: AbstractQuantumObject{ObjType,DimType,DataType}
    data::DataType
    type::ObjType
    dimensions::DimType
end

Julia structure representing any time-independent quantum objects. For time-dependent cases, see QuantumObjectEvolution.

dims property

For a given H::QuantumObject, H.dims or getproperty(H, :dims) returns its dimensions in the type of integer-vector.

Examples

julia
julia> a = destroy(20)

Quantum Object:   type=Operator   dims=[20]   size=(20, 20)   ishermitian=false
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:
⎡⠈⠢⡀⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠈⠢⡀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠈⠢⡀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠈⠢⡀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢⎦

julia> a isa QuantumObject
true

julia> a.dims
1-element SVector{1, Int64} with indices SOneTo(1):
 20

julia> a.dimensions
Dimensions{1, Tuple{Space}}((Space(20),))

source

QuantumToolbox.QuantumObjectEvolution Type
julia
struct QuantumObjectEvolution{ObjType<:QuantumObjectType,DimType<:AbstractDimensions,DataType<:AbstractSciMLOperator} <: AbstractQuantumObject{ObjType,DimType,DataType}
    data::DataType
    type::ObjType
    dimensions::DimType
end

Julia struct representing any time-dependent quantum object. The data field is a AbstractSciMLOperator object that represents the time-dependent quantum object. It can be seen as

O^(t)=ici(p,t)O^i

where ci(p,t) is a function that depends on the parameters p and time t, and O^i are the operators that form the quantum object.

For time-independent cases, see QuantumObject, and for more information about AbstractSciMLOperator, see the SciML documentation.

dims property

For a given H::QuantumObjectEvolution, H.dims or getproperty(H, :dims) returns its dimensions in the type of integer-vector.

Examples

This operator can be initialized in the same way as the QuTiP QobjEvo object. For example

julia
julia> a = tensor(destroy(10), qeye(2))

Quantum Object:   type=Operator   dims=[10, 2]   size=(20, 20)   ishermitian=false
20×20 SparseMatrixCSC{ComplexF64, Int64} with 18 stored entries:
⎡⠀⠑⢄⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠀⠑⢄⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠑⢄⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠀⠑⢄⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⎦

julia> coef1(p, t) = exp(-1im * t)
coef1 (generic function with 1 method)

julia> op = QobjEvo(a, coef1)

Quantum Object Evo.:   type=Operator   dims=[10, 2]   size=(20, 20)   ishermitian=true   isconstant=false
ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20)

If there are more than 2 operators, we need to put each set of operator and coefficient function into a two-element Tuple, and put all these Tuples together in a larger Tuple:

julia
julia> σm = tensor(qeye(10), sigmam())

Quantum Object:   type=Operator   dims=[10, 2]   size=(20, 20)   ishermitian=false
20×20 SparseMatrixCSC{ComplexF64, Int64} with 10 stored entries:
⎡⠂⡀⠀⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠂⡀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠂⡀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠂⡀⠀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠂⡀⎦

julia> coef2(p, t) = sin(t)
coef2 (generic function with 1 method)

julia> op1 = QobjEvo(((a, coef1), (σm, coef2)))

Quantum Object Evo.:   type=Operator   dims=[10, 2]   size=(20, 20)   ishermitian=true   isconstant=false
(ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20) + ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20))

We can also concretize the operator at a specific time t

julia
julia> op1(0.1)

Quantum Object:   type=Operator   dims=[10, 2]   size=(20, 20)   ishermitian=false
20×20 SparseMatrixCSC{ComplexF64, Int64} with 28 stored entries:
⎡⠂⡑⢄⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠂⡑⢄⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠂⡑⢄⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠂⡑⢄⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠂⡑⎦

It also supports parameter-dependent time evolution

julia
julia> coef1(p, t) = exp(-1im * p.ω1 * t)
coef1 (generic function with 1 method)

julia> coef2(p, t) = sin(p.ω2 * t)
coef2 (generic function with 1 method)

julia> op1 = QobjEvo(((a, coef1), (σm, coef2)))

Quantum Object Evo.:   type=Operator   dims=[10, 2]   size=(20, 20)   ishermitian=true   isconstant=false
(ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20) + ScalarOperator(0.0 + 0.0im) * MatrixOperator(20 × 20))

julia> p = (ω1 = 1.0, ω2 = 0.5)
(ω1 = 1.0, ω2 = 0.5)

julia> op1(p, 0.1)

Quantum Object:   type=Operator   dims=[10, 2]   size=(20, 20)   ishermitian=false
20×20 SparseMatrixCSC{ComplexF64, Int64} with 28 stored entries:
⎡⠂⡑⢄⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠂⡑⢄⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠂⡑⢄⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠂⡑⢄⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠂⡑⎦

source

Base.size Function
julia
size(A::AbstractQuantumObject)
size(A::AbstractQuantumObject, idx::Int)
shape(A::AbstractQuantumObject)
shape(A::AbstractQuantumObject, idx::Int)

Returns a tuple containing each dimensions of the array in the AbstractQuantumObject.

Optionally, you can specify an index (idx) to just get the corresponding dimension of the array.

Note

shape is a synonym of size.

source

Base.eltype Function
julia
eltype(A::AbstractQuantumObject)

Returns the elements type of the matrix or vector corresponding to the AbstractQuantumObject A.

source

Base.length Function
julia
length(A::AbstractQuantumObject)

Returns the length of the matrix or vector corresponding to the AbstractQuantumObject A.

source

SciMLOperators.cache_operator Function
julia
SciMLOperators.cached_operator(L::AbstractQuantumObject, u)

Allocate caches for AbstractQuantumObject L for in-place evaluation with u-like input vectors.

Here, u can be in either the following types:

source

Qobj boolean functions

QuantumToolbox.isbra Function
julia
isbra(A)

Checks if the QuantumObject A is a BraQuantumObject. Default case returns false for any other inputs.

source

QuantumToolbox.isket Function
julia
isket(A)

Checks if the QuantumObject A is a KetQuantumObject. Default case returns false for any other inputs.

source

QuantumToolbox.isoper Function
julia
isoper(A)

Checks if the AbstractQuantumObject A is a OperatorQuantumObject. Default case returns false for any other inputs.

source

QuantumToolbox.isoperbra Function
julia
isoperbra(A)

Checks if the QuantumObject A is a OperatorBraQuantumObject. Default case returns false for any other inputs.

source

QuantumToolbox.isoperket Function
julia
isoperket(A)

Checks if the QuantumObject A is a OperatorKetQuantumObject. Default case returns false for any other inputs.

source

QuantumToolbox.issuper Function
julia
issuper(A)

Checks if the AbstractQuantumObject A is a SuperOperatorQuantumObject. Default case returns false for any other inputs.

source

LinearAlgebra.ishermitian Function
julia
ishermitian(A::AbstractQuantumObject)
isherm(A::AbstractQuantumObject)

Test whether the AbstractQuantumObject is Hermitian.

Note

isherm is a synonym of ishermitian.

source

LinearAlgebra.issymmetric Function
julia
issymmetric(A::AbstractQuantumObject)

Test whether the AbstractQuantumObject is symmetric.

source

LinearAlgebra.isposdef Function
julia
isposdef(A::AbstractQuantumObject)

Test whether the AbstractQuantumObject is positive definite (and Hermitian) by trying to perform a Cholesky factorization of A.

source

QuantumToolbox.isunitary Function
julia
isunitary(U::QuantumObject; kwargs...)

Test whether the QuantumObject U is unitary operator. This function calls Base.isapprox to test whether UU is approximately equal to identity operator.

Note that all the keyword arguments will be passed to Base.isapprox.

source

SciMLOperators.iscached Function
julia
SciMLOperators.iscached(A::AbstractQuantumObject)

Test whether the AbstractQuantumObject A has preallocated caches for inplace evaluations.

source

SciMLOperators.isconstant Function
julia
SciMLOperators.isconstant(A::AbstractQuantumObject)

Test whether the AbstractQuantumObject A is constant in time. For a QuantumObject, this function returns true, while for a QuantumObjectEvolution, this function returns true if the operator is constant in time.

source

Qobj arithmetic and attributes

Base.zero Function
julia
zero(A::AbstractQuantumObject)

Return a similar AbstractQuantumObject with dims and type are same as A, but data is a zero-array.

source

Base.one Function
julia
one(A::AbstractQuantumObject)

Return a similar AbstractQuantumObject with dims and type are same as A, but data is an identity matrix.

Note that A must be Operator or SuperOperator.

source

Base.conj Function
julia
conj(A::AbstractQuantumObject)

Return the element-wise complex conjugation of the AbstractQuantumObject.

source

Base.transpose Function
julia
transpose(A::AbstractQuantumObject)

Lazy matrix transpose of the AbstractQuantumObject.

source

Base.adjoint Function
julia
A'
adjoint(A::AbstractQuantumObject)
dag(A::AbstractQuantumObject)

Lazy adjoint (conjugate transposition) of the AbstractQuantumObject

Note

A' and dag(A) are synonyms of adjoint(A).

source

LinearAlgebra.dot Function
julia
A  B
dot(A::QuantumObject, B::QuantumObject)

Compute the dot product between two QuantumObject: A|B

Note that A and B should be Ket or OperatorKet

Note

A ⋅ B (where can be typed by tab-completing \cdot in the REPL) is a synonym of dot(A, B).

source

julia
dot(i::QuantumObject, A::AbstractQuantumObject j::QuantumObject)
matrix_element(i::QuantumObject, A::AbstractQuantumObject j::QuantumObject)

Compute the generalized dot product dot(i, A*j) between a AbstractQuantumObject and two QuantumObject (i and j), namely i|A^|j.

Supports the following inputs:

Note

matrix_element(i, A, j) is a synonym of dot(i, A, j).

source

Base.sqrt Function
julia
(A)
sqrt(A::QuantumObject)

Matrix square root of QuantumObject

Note

√(A) (where can be typed by tab-completing \sqrt in the REPL) is a synonym of sqrt(A).

source

Base.log Function
julia
log(A::QuantumObject)

Matrix logarithm of QuantumObject

Note that this function only supports for Operator and SuperOperator

source

Base.exp Function
julia
exp(A::QuantumObject)

Matrix exponential of QuantumObject

Note that this function only supports for Operator and SuperOperator

source

Base.sin Function
julia
sin(A::QuantumObject)

Matrix sine of QuantumObject, defined as

sin(A^)=eiA^eiA^2i

Note that this function only supports for Operator and SuperOperator

source

Base.cos Function
julia
cos(A::QuantumObject)

Matrix cosine of QuantumObject, defined as

cos(A^)=eiA^+eiA^2

Note that this function only supports for Operator and SuperOperator

source

LinearAlgebra.tr Function
julia
tr(A::QuantumObject)

Returns the trace of QuantumObject.

Note that this function only supports for Operator and SuperOperator

Examples

julia
julia> a = destroy(20)

Quantum Object:   type=Operator   dims=[20]   size=(20, 20)   ishermitian=false
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:
⎡⠈⠢⡀⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠈⠢⡀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠈⠢⡀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠈⠢⡀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢⎦

julia> tr(a' * a)
190.0 + 0.0im

source

LinearAlgebra.svdvals Function
julia
svdvals(A::QuantumObject)

Return the singular values of a QuantumObject in descending order

source

LinearAlgebra.norm Function
julia
norm(A::QuantumObject, p::Real)

Return the standard vector p-norm or Schatten p-norm of a QuantumObject depending on the type of A:

Examples

julia
julia> ψ = fock(10, 2)

Quantum Object:   type=Ket   dims=[10]   size=(10,)
10-element Vector{ComplexF64}:
 0.0 + 0.0im
 0.0 + 0.0im
 1.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im

julia> norm(ψ)
1.0

source

LinearAlgebra.normalize Function
julia
normalize(A::QuantumObject, p::Real)
unit(A::QuantumObject, p::Real)

Return normalized QuantumObject so that its p-norm equals to unity, i.e. norm(A, p) == 1.

Support for the following types of QuantumObject:

Note

unit is a synonym of normalize.

Also, see norm about its definition for different types of QuantumObject.

source

LinearAlgebra.normalize! Function
julia
normalize!(A::QuantumObject, p::Real)

Normalize QuantumObject in-place so that its p-norm equals to unity, i.e. norm(A, p) == 1.

Support for the following types of QuantumObject:

Also, see norm about its definition for different types of QuantumObject.

source

Base.inv Function
julia
inv(A::AbstractQuantumObject)

Matrix inverse of the AbstractQuantumObject. If A is a QuantumObjectEvolution, the inverse is computed at the last computed time.

source

LinearAlgebra.diag Function
julia
diag(A::QuantumObject, k::Int=0)

Return the k-th diagonal elements of a matrix-type QuantumObject

Note that this function only supports for Operator and SuperOperator

source

QuantumToolbox.proj Function
julia
proj::QuantumObject)

Return the projector for a Ket or Bra type of QuantumObject

source

QuantumToolbox.ptrace Function
julia
ptrace(QO::QuantumObject, sel)

Partial trace of a quantum state QO leaving only the dimensions with the indices present in the sel vector.

Note that this function will always return Operator. No matter the input QuantumObject is a Ket, Bra, or Operator.

Examples

Two qubits in the state |ψ=|e,g:

julia
julia> ψ = kron(fock(2,0), fock(2,1))

Quantum Object:   type=Ket   dims=[2, 2]   size=(4,)
4-element Vector{ComplexF64}:
 0.0 + 0.0im
 1.0 + 0.0im
 0.0 + 0.0im
 0.0 + 0.0im

julia> ptrace(ψ, 2)

Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=true
2×2 Matrix{ComplexF64}:
 0.0+0.0im  0.0+0.0im
 0.0+0.0im  1.0+0.0im

or in an entangled state |ψ=12(|e,e+|g,g):

julia
julia> ψ = 1 /2 * (kron(fock(2,0), fock(2,0)) + kron(fock(2,1), fock(2,1)))

Quantum Object:   type=Ket   dims=[2, 2]   size=(4,)
4-element Vector{ComplexF64}:
 0.7071067811865475 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im
 0.7071067811865475 + 0.0im

julia> ptrace(ψ, 1)

Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=true
2×2 Matrix{ComplexF64}:
 0.5+0.0im  0.0+0.0im
 0.0+0.0im  0.5+0.0im

source

QuantumToolbox.purity Function
julia
purity::QuantumObject)

Calculate the purity of a QuantumObject: Tr(ρ2)

Note that this function only supports for Ket, Bra, and Operator

source

SparseArrays.permute Function
julia
permute(A::QuantumObject, order::Union{AbstractVector{Int},Tuple})

Permute the tensor structure of a QuantumObject A according to the specified order list

Note that this method currently works for Ket, Bra, and Operator types of QuantumObject.

Examples

If order = [2, 1, 3], the Hilbert space structure will be re-arranged: H1H2H3H2H1H3.

julia
julia> ψ1 = fock(2, 0);

julia> ψ2 = fock(3, 1);

julia> ψ3 = fock(4, 2);

julia> ψ_123 = tensor(ψ1, ψ2, ψ3);

julia> permute(ψ_123, (2, 1, 3))  tensor(ψ2, ψ1, ψ3)
true

Beware of type-stability!

It is highly recommended to use permute(A, order) with order as Tuple or SVector to keep type stability. See the related Section about type stability for more details.

source

QuantumToolbox.tidyup Function
julia
tidyup(A::QuantumObject, tol::Real=1e-14)

Given a QuantumObject A, check the real and imaginary parts of each element separately. Remove the real or imaginary value if its absolute value is less than tol.

source

QuantumToolbox.tidyup! Function
julia
tidyup!(A::QuantumObject, tol::Real=1e-14)

Given a QuantumObject A, check the real and imaginary parts of each element separately. Remove the real or imaginary value if its absolute value is less than tol.

Note that this function is an in-place version of tidyup.

source

QuantumToolbox.get_data Function
julia
get_data(A::AbstractQuantumObject)

Returns the data of a AbstractQuantumObject.

source

QuantumToolbox.get_coherence Function
julia
get_coherence::QuantumObject)

Get the coherence value α by measuring the expectation value of the destruction operator a^ on a state |ψ or a density matrix ρ^.

It returns both α and the corresponding state with the coherence removed: |δα=exp(αa^αa^)|ψ for a pure state, and ρα^=exp(αa^αa^)ρ^exp(α¯a^+αa^) for a density matrix. These states correspond to the quantum fluctuations around the coherent state |α or |αα|.

source

QuantumToolbox.partial_transpose Function
julia
partial_transpose::QuantumObject, mask::Vector{Bool})

Return the partial transpose of a density matrix ρ, where mask is an array/vector with length that equals the length of ρ.dims. The elements in mask are boolean (true or false) which indicates whether or not the corresponding subsystem should be transposed.

Arguments

  • ρ::QuantumObject: The density matrix (ρ.type must be OperatorQuantumObject).

  • mask::Vector{Bool}: A boolean vector selects which subsystems should be transposed.

Returns

  • ρ_pt::QuantumObject: The density matrix with the selected subsystems transposed.

source

Qobj eigenvalues and eigenvectors

QuantumToolbox.EigsolveResult Type
julia
struct EigsolveResult

A struct containing the eigenvalues, the eigenvectors, and some information from the solver

Fields (Attributes)

  • values::AbstractVector: the eigenvalues

  • vectors::AbstractMatrix: the transformation matrix (eigenvectors)

  • type::Union{Nothing,QuantumObjectType}: the type of QuantumObject, or nothing means solving eigen equation for general matrix

  • dimensions::Union{Nothing,AbstractDimensions}: the dimensions of QuantumObject, or nothing means solving eigen equation for general matrix

  • iter::Int: the number of iteration during the solving process

  • numops::Int : number of times the linear map was applied in krylov methods

  • converged::Bool: Whether the result is converged

dims property

For a given res::EigsolveResult, res.dims or getproperty(res, :dims) returns its dimensions in the type of integer-vector.

Examples

One can obtain the eigenvalues and the corresponding QuantumObject-type eigenvectors by:

julia
julia> result = eigenstates(sigmax())
EigsolveResult:   type=Operator   dims=[2]
values:
2-element Vector{ComplexF64}:
 -1.0 + 0.0im
  1.0 + 0.0im
vectors:
2×2 Matrix{ComplexF64}:
 -0.707107+0.0im  0.707107+0.0im
  0.707107+0.0im  0.707107+0.0im

julia> λ, ψ, U = result;

julia> λ
2-element Vector{ComplexF64}:
 -1.0 + 0.0im
  1.0 + 0.0im

julia> ψ
2-element Vector{QuantumObject{KetQuantumObject, Dimensions{1, Tuple{Space}}, Vector{ComplexF64}}}:

Quantum Object:   type=Ket   dims=[2]   size=(2,)
2-element Vector{ComplexF64}:
 -0.7071067811865475 + 0.0im
  0.7071067811865475 + 0.0im

Quantum Object:   type=Ket   dims=[2]   size=(2,)
2-element Vector{ComplexF64}:
 0.7071067811865475 + 0.0im
 0.7071067811865475 + 0.0im

julia> U
2×2 Matrix{ComplexF64}:
 -0.707107+0.0im  0.707107+0.0im
  0.707107+0.0im  0.707107+0.0im

source

QuantumToolbox.eigenenergies Function
julia
eigenenergies(A::QuantumObject; sparse::Bool=false, kwargs...)

Calculate the eigenenergies

Arguments

Returns

  • ::Vector{<:Number}: a list of eigenvalues

source

QuantumToolbox.eigenstates Function
julia
eigenstates(A::QuantumObject; sparse::Bool=false, kwargs...)

Calculate the eigenvalues and corresponding eigenvectors

Arguments

Returns

  • ::EigsolveResult: containing the eigenvalues, the eigenvectors, and some information from the solver. see also EigsolveResult

source

LinearAlgebra.eigen Function
julia
LinearAlgebra.eigen(A::QuantumObject; kwargs...)

Calculates the eigenvalues and eigenvectors of the QuantumObject A using the Julia LinearAlgebra package.

julia
julia> a = destroy(5);

julia> H = a + a';

julia> E, ψ, U = eigen(H)
EigsolveResult:   type=Operator   dims=[5]
values:
5-element Vector{ComplexF64}:
       -2.8569700138728 + 0.0im
    -1.3556261799742608 + 0.0im
 1.3322676295501878e-15 + 0.0im
     1.3556261799742677 + 0.0im
     2.8569700138728056 + 0.0im
vectors:
5×5 Matrix{ComplexF64}:
  0.106101+0.0im  -0.471249-0.0im   0.471249-0.0im  0.106101-0.0im
 -0.303127-0.0im   0.638838+0.0im      0.638838+0.0im  0.303127-0.0im
  0.537348+0.0im  -0.279149-0.0im      0.279149-0.0im  0.537348-0.0im
 -0.638838-0.0im  -0.303127-0.0im     -0.303127-0.0im  0.638838+0.0im
  0.447214+0.0im   0.447214+0.0im     -0.447214-0.0im  0.447214-0.0im

julia> expect(H, ψ[1])  E[1]
true

source

LinearAlgebra.eigvals Function
julia
LinearAlgebra.eigvals(A::QuantumObject; kwargs...)

Same as eigen(A::QuantumObject; kwargs...) but for only the eigenvalues.

source

QuantumToolbox.eigsolve Function
julia
eigsolve(A::QuantumObject; 
    v0::Union{Nothing,AbstractVector}=nothing, 
    sigma::Union{Nothing, Real}=nothing,
    eigvals::Int = 1,
    krylovdim::Int = max(20, 2*k+1),
    tol::Real = 1e-8,
    maxiter::Int = 200,
    solver::Union{Nothing, SciMLLinearSolveAlgorithm} = nothing,
    kwargs...)

Solve for the eigenvalues and eigenvectors of a matrix A using the Arnoldi method.

Arguments

  • A::QuantumObject: the QuantumObject to solve eigenvalues and eigenvectors.

  • v0::Union{Nothing,AbstractVector}: the initial vector for the Arnoldi method. Default is a random vector.

  • sigma::Union{Nothing, Real}: the shift for the eigenvalue problem. Default is nothing.

  • eigvals::Int: the number of eigenvalues to compute. Default is 1.

  • krylovdim::Int: the dimension of the Krylov subspace. Default is max(20, 2*k+1).

  • tol::Real: the tolerance for the Arnoldi method. Default is 1e-8.

  • maxiter::Int: the maximum number of iterations for the Arnoldi method. Default is 200.

  • solver::Union{Nothing, SciMLLinearSolveAlgorithm}: the linear solver algorithm. Default is nothing.

  • kwargs: Additional keyword arguments passed to the solver.

Notes

  • For more details about solver and extra kwargs, please refer to LinearSolve.jl

Returns

  • EigsolveResult: A struct containing the eigenvalues, the eigenvectors, and some information about the eigsolver

source

QuantumToolbox.eigsolve_al Function
julia
eigsolve_al(
    H::Union{AbstractQuantumObject{HOpType},Tuple},
    T::Real,
    c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
    alg::OrdinaryDiffEqAlgorithm = Tsit5(),
    params::NamedTuple = NamedTuple(),
    ρ0::AbstractMatrix = rand_dm(prod(H.dimensions)).data,
    eigvals::Int = 1,
    krylovdim::Int = min(10, size(H, 1)),
    maxiter::Int = 200,
    eigstol::Real = 1e-6,
    kwargs...,
)

Solve the eigenvalue problem for a Liouvillian superoperator L using the Arnoldi-Lindblad method.

Arguments

  • H: The Hamiltonian (or directly the Liouvillian) of the system. It can be a QuantumObject, a QuantumObjectEvolution, or a tuple of the form supported by mesolve.

  • T: The time at which to evaluate the time evolution.

  • c_ops: A vector of collapse operators. Default is nothing meaning the system is closed.

  • alg: The differential equation solver algorithm. Default is Tsit5().

  • params: A NamedTuple containing the parameters of the system.

  • ρ0: The initial density matrix. If not specified, a random density matrix is used.

  • eigvals: The number of eigenvalues to compute.

  • krylovdim: The dimension of the Krylov subspace.

  • maxiter: The maximum number of iterations for the eigsolver.

  • eigstol: The tolerance for the eigsolver.

  • kwargs: Additional keyword arguments passed to the differential equation solver.

Notes

Returns

  • EigsolveResult: A struct containing the eigenvalues, the eigenvectors, and some information about the eigsolver

References

  • [1] Minganti, F., & Huybrechts, D. (2022). Arnoldi-Lindblad time evolution: Faster-than-the-clock algorithm for the spectrum of time-independent and Floquet open quantum systems. Quantum, 6, 649.

source

Qobj manipulation

QuantumToolbox.ket2dm Function
julia
ket2dm::QuantumObject)

Transform the ket state |ψ into a pure density matrix ρ^=|ψψ|.

source

QuantumToolbox.expect Function
julia
expect(O::Union{AbstractQuantumObject,Vector{AbstractQuantumObject}}, ψ::Union{QuantumObject,Vector{QuantumObject}})

Expectation value of the Operator O with the state ψ. The state can be a Ket, Bra or Operator.

If ψ is a Ket or Bra, the function calculates ψ|O^|ψ.

If ψ is a density matrix (Operator), the function calculates Tr[O^ψ^]

The function returns a real number if O is of Hermitian type or Symmetric type, and returns a complex number otherwise. You can make an operator O hermitian by using Hermitian(O).

List of observables and states

The observable O and state ψ can be given as a list of QuantumObject, it returns a list of expectation values. If both of them are given as a list, it returns a Matrix of expectation values.

Examples

julia
julia> ψ1 = 1 /2 * (fock(10,2) + fock(10,4));

julia> ψ2 = coherent(10, 0.6 + 0.8im);

julia> a = destroy(10);

julia> expect(a' * a, ψ1) |> round
3.0 + 0.0im

julia> expect(Hermitian(a' * a), ψ1) |> round
3.0

julia> round.(expect([a' * a, a' + a, a], [ψ1, ψ2]), digits = 1)
3×2 Matrix{ComplexF64}:
 3.0+0.0im  1.0+0.0im
 0.0+0.0im  1.2-0.0im
 0.0+0.0im  0.6+0.8im

source

QuantumToolbox.variance Function
julia
variance(O::QuantumObject, ψ::Union{QuantumObject,Vector{QuantumObject}})

Variance of the Operator O: O^2O^2,

where O^ is the expectation value of O with the state ψ (see also expect), and the state ψ can be a Ket, Bra or Operator.

The function returns a real number if O is hermitian, and returns a complex number otherwise.

Note that ψ can also be given as a list of QuantumObject, it returns a list of expectation values.

source

Base.kron Function
julia
kron(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
tensor(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
A  B

Returns the Kronecker product A^B^.

Note

tensor and (where can be typed by tab-completing \otimes in the REPL) are synonyms of kron.

Examples

julia
julia> a = destroy(20)

Quantum Object:   type=Operator   dims=[20]   size=(20, 20)   ishermitian=false
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:
⎡⠈⠢⡀⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠈⠢⡀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠈⠢⡀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠈⠢⡀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢⎦

julia> O = kron(a, a);

julia> size(a), size(O)
((20, 20), (400, 400))

julia> a.dims, O.dims
([20], [20, 20])

source

QuantumToolbox.to_dense Function
julia
to_dense(A::QuantumObject)

Converts a sparse QuantumObject to a dense QuantumObject.

source

QuantumToolbox.to_sparse Function
julia
to_sparse(A::QuantumObject)

Converts a dense QuantumObject to a sparse QuantumObject.

source

QuantumToolbox.vec2mat Function
julia
vec2mat(A::AbstractVector)

Converts a vector to a matrix.

source

julia
vec2mat(A::QuantumObject)
vector_to_operator(A::QuantumObject)

Convert a quantum object from vector (OperatorKetQuantumObject-type) to matrix (OperatorQuantumObject-type)

Note

vector_to_operator is a synonym of vec2mat.

source

QuantumToolbox.mat2vec Function
julia
mat2vec(A::QuantumObject)
operator_to_vector(A::QuantumObject)

Convert a quantum object from matrix (OperatorQuantumObject-type) to vector (OperatorKetQuantumObject-type)

Note

operator_to_vector is a synonym of mat2vec.

source

julia
mat2vec(A::AbstractMatrix)

Converts a matrix to a vector.

source

Generate states and operators

QuantumToolbox.zero_ket Function
julia
zero_ket(dimensions)

Returns a zero Ket vector with given argument dimensions.

The dimensions can be either the following types:

  • dimensions::Int: Number of basis states in the Hilbert space.

  • dimensions::Union{Dimensions,AbstractVector{Int}, Tuple}: list of dimensions representing the each number of basis in the subsystems.

Beware of type-stability!

It is highly recommended to use zero_ket(dimensions) with dimensions as Tuple or SVector to keep type stability. See the related Section about type stability for more details.

source

QuantumToolbox.fock Function
julia
fock(N::Int, j::Int=0; dims::Union{Int,AbstractVector{Int},Tuple}=N, sparse::Union{Bool,Val}=Val(false))

Generates a fock state |ψ of dimension N.

It is also possible to specify the list of dimensions dims if different subsystems are present.

Beware of type-stability!

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 and the related Section about type stability for more details.

source

QuantumToolbox.basis Function
julia
basis(N::Int, j::Int = 0; dims::Union{Int,AbstractVector{Int},Tuple}=N)

Generates a fock state like fock.

It is also possible to specify the list of dimensions dims if different subsystems are present.

Beware of type-stability!

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 and the related Section about type stability for more details.

source

QuantumToolbox.coherent Function
julia
coherent(N::Int, α::Number)

Generates a coherent state |α, which is defined as an eigenvector of the bosonic annihilation operator a^|α=α|α.

This state is constructed via the displacement operator displace and zero-fock state fock: |α=D^(α)|0

source

QuantumToolbox.rand_ket Function
julia
rand_ket(dimensions)

Generate a random normalized Ket vector with given argument dimensions.

The dimensions can be either the following types:

  • dimensions::Int: Number of basis states in the Hilbert space.

  • dimensions::Union{Dimensions,AbstractVector{Int},Tuple}: list of dimensions representing the each number of basis in the subsystems.

Beware of type-stability!

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 about type stability for more details.

source

QuantumToolbox.fock_dm Function
julia
fock_dm(N::Int, j::Int=0; dims::Union{Int,AbstractVector{Int},Tuple}=N, sparse::Union{Bool,Val}=Val(false))

Density matrix representation of a Fock state.

Constructed via outer product of fock.

Beware of type-stability!

If you want to keep type stability, it is recommended to use fock_dm(N, j, dims=dims, sparse=Val(sparse)) instead of fock_dm(N, j, dims=dims, sparse=sparse). Consider also to use dims as a Tuple or SVector instead of Vector. See this link and the related Section about type stability for more details.

source

QuantumToolbox.coherent_dm Function
julia
coherent_dm(N::Int, α::Number)

Density matrix representation of a coherent state.

Constructed via outer product of coherent.

source

QuantumToolbox.thermal_dm Function
julia
thermal_dm(N::Int, n::Real; sparse::Union{Bool,Val}=Val(false))

Density matrix for a thermal state (generating thermal state probabilities) with the following arguments:

  • N::Int: Number of basis states in the Hilbert space

  • n::Real: Expectation value for number of particles in the thermal state.

  • sparse::Union{Bool,Val}: If true, return a sparse matrix representation.

Beware of type-stability!

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 and the related Section about type stability for more details.

source

QuantumToolbox.maximally_mixed_dm Function
julia
maximally_mixed_dm(dimensions)

Returns the maximally mixed density matrix with given argument dimensions.

The dimensions can be either the following types:

  • dimensions::Int: Number of basis states in the Hilbert space.

  • dimensions::Union{Dimensions,AbstractVector{Int},Tuple}: list of dimensions representing the each number of basis in the subsystems.

Beware of type-stability!

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 about type stability for more details.

source

QuantumToolbox.rand_dm Function
julia
rand_dm(dimensions; rank::Int=prod(dimensions))

Generate a random density matrix from Ginibre ensemble with given argument dimensions and rank, ensuring that it is positive semi-definite and trace equals to 1.

The dimensions can be either the following types:

  • dimensions::Int: Number of basis states in the Hilbert space.

  • dimensions::Union{Dimensions,AbstractVector{Int},Tuple}: list of dimensions representing the each number of basis in the subsystems.

The default keyword argument rank = prod(dimensions) (full rank).

Beware of type-stability!

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 and the related Section about type stability for more details.

References

source

QuantumToolbox.spin_state Function
julia
spin_state(j::Real, m::Real)

Generate the spin state: |j,m

The eigenstate of the Spin-j S^z operator with eigenvalue m, where where j is the spin quantum number and can be a non-negative integer or half-integer

See also jmat.

source

QuantumToolbox.spin_coherent Function
julia
spin_coherent(j::Real, θ::Real, ϕ::Real)

Generate the coherent spin state (rotation of the |j,j state), namely

|θ,ϕ=R^(θ,ϕ)|j,j

where the rotation operator is defined as

R^(θ,ϕ)=exp(θ2(S^eiϕS^+eiϕ))

and S^± are plus and minus Spin-j operators, respectively.

Arguments

  • j::Real: The spin quantum number and can be a non-negative integer or half-integer

  • θ::Real: rotation angle from z-axis

  • ϕ::Real: rotation angle from x-axis

See also jmat and spin_state.

Reference

source

QuantumToolbox.bell_state Function
julia
bell_state(x::Union{Int}, z::Union{Int})

Return the Bell state depending on the arguments (x, z):

  • (0, 0): |Φ+=(|00+|11)/2

  • (0, 1): |Φ=(|00|11)/2

  • (1, 0): |Ψ+=(|01+|10)/2

  • (1, 1): |Ψ=(|01|10)/2

Here, x = 1 (z = 1) means applying Pauli-X ( Pauli-Z) unitary transformation on |Φ+.

Example

julia
julia> bell_state(0, 0)

Quantum Object:   type=Ket   dims=[2, 2]   size=(4,)
4-element Vector{ComplexF64}:
 0.7071067811865475 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im
 0.7071067811865475 + 0.0im

julia> bell_state(Val(1), Val(0))

Quantum Object:   type=Ket   dims=[2, 2]   size=(4,)
4-element Vector{ComplexF64}:
                0.0 + 0.0im
 0.7071067811865475 + 0.0im
 0.7071067811865475 + 0.0im
                0.0 + 0.0im

Beware of type-stability!

If you want to keep type stability, it is recommended to use bell_state(Val(x), Val(z)) instead of bell_state(x, z). See this link and the related Section for more details.

source

QuantumToolbox.singlet_state Function
julia
singlet_state()

Return the two particle singlet state: 12(|01|10)

source

QuantumToolbox.triplet_states Function
julia
triplet_states()

Return a list of the two particle triplet states:

  • |11

  • (|01+|10)/2

  • |00

source

QuantumToolbox.w_state Function
julia
w_state(n::Union{Int,Val})

Returns the n-qubit W-state:

1n(|100...0+|010...0++|00...01)

Beware of type-stability!

If you want to keep type stability, it is recommended to use w_state(Val(n)) instead of w_state(n). See this link and the related Section for more details.

source

QuantumToolbox.ghz_state Function
julia
ghz_state(n::Union{Int,Val}; d::Int=2)

Returns the generalized n-qudit Greenberger–Horne–Zeilinger (GHZ) state:

1di=0d1|i|i

Here, d specifies the dimension of each qudit. Default to d=2 (qubit).

Beware of type-stability!

If you want to keep type stability, it is recommended to use ghz_state(Val(n)) instead of ghz_state(n). See this link and the related Section for more details.

source

QuantumToolbox.rand_unitary Function
julia
rand_unitary(dimensions, distribution=Val(:haar))

Returns a random unitary QuantumObject.

The dimensions can be either the following types:

  • dimensions::Int: Number of basis states in the Hilbert space.

  • dimensions::Union{Dimensions,AbstractVector{Int},Tuple}: list of dimensions representing the each number of basis in the subsystems.

The distribution specifies which of the method used to obtain the unitary matrix:

  • :haar: Haar random unitary matrix using the algorithm from reference 1

  • :exp: Uses exp(iH^), where H^ is a randomly generated Hermitian operator.

References

  1. F. Mezzadri, How to generate random matrices from the classical compact groups, arXiv:math-ph/0609050 (2007)

Beware of type-stability!

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 and the related Section about type stability for more details.

source

QuantumToolbox.sigmap Function
julia
sigmap()

Pauli ladder operator σ^+=(σ^x+iσ^y)/2.

See also jmat.

source

QuantumToolbox.sigmam Function
julia
sigmam()

Pauli ladder operator σ^=(σ^xiσ^y)/2.

See also jmat.

source

QuantumToolbox.sigmax Function
julia
sigmax()

Pauli operator σ^x=σ^+σ^+.

See also jmat.

source

QuantumToolbox.sigmay Function
julia
sigmay()

Pauli operator σ^y=i(σ^σ^+).

See also jmat.

source

QuantumToolbox.sigmaz Function
julia
sigmaz()

Pauli operator σ^z=[σ^+,σ^].

See also jmat.

source

QuantumToolbox.jmat Function
julia
jmat(j::Real, which::Union{Symbol,Val})

Generate higher-order Spin-j operators, where j is the spin quantum number and can be a non-negative integer or half-integer

The parameter which specifies which of the following operator to return.

  • :x: S^x

  • :y: S^y

  • :z: S^z

  • :+: S^+

  • :-: S^

Note that if the parameter which is not specified, returns a set of Spin-j operators: (S^x,S^y,S^z)

Examples

julia
julia> jmat(0.5, :x)

Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=true
2×2 SparseMatrixCSC{ComplexF64, Int64} with 2 stored entries:
      0.5+0.0im
 0.5+0.0im

julia> jmat(0.5, Val(:-))

Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=false
2×2 SparseMatrixCSC{ComplexF64, Int64} with 1 stored entry:
    
 1.0+0.0im

julia> jmat(1.5, Val(:z))

Quantum Object:   type=Operator   dims=[4]   size=(4, 4)   ishermitian=true
4×4 SparseMatrixCSC{ComplexF64, Int64} with 4 stored entries:
 1.5+0.0im    
      0.5+0.0im    
      -0.5+0.0im    
      -1.5+0.0im

Beware of type-stability!

If you want to keep type stability, it is recommended to use jmat(j, Val(which)) instead of jmat(j, which). See this link and the related Section about type stability for more details.

source

QuantumToolbox.spin_Jx Function
julia
spin_Jx(j::Real)

S^x operator for Spin-j, where j is the spin quantum number and can be a non-negative integer or half-integer.

See also jmat.

source

QuantumToolbox.spin_Jy Function
julia
spin_Jy(j::Real)

S^y operator for Spin-j, where j is the spin quantum number and can be a non-negative integer or half-integer.

See also jmat.

source

QuantumToolbox.spin_Jz Function
julia
spin_Jz(j::Real)

S^z operator for Spin-j, where j is the spin quantum number and can be a non-negative integer or half-integer.

See also jmat.

source

QuantumToolbox.spin_Jm Function
julia
spin_Jm(j::Real)

S^ operator for Spin-j, where j is the spin quantum number and can be a non-negative integer or half-integer.

See also jmat.

source

QuantumToolbox.spin_Jp Function
julia
spin_Jp(j::Real)

S^+ operator for Spin-j, where j is the spin quantum number and can be a non-negative integer or half-integer.

See also jmat.

source

QuantumToolbox.spin_J_set Function
julia
spin_J_set(j::Real)

A set of Spin-j operators (S^x,S^y,S^z), where j is the spin quantum number and can be a non-negative integer or half-integer.

Note that this functions is same as jmat(j). See also jmat.

source

QuantumToolbox.destroy Function
julia
destroy(N::Int)

Bosonic annihilation operator with Hilbert space cutoff N.

This operator acts on a fock state as a^|n=n|n1.

Examples

julia
julia> a = destroy(20)

Quantum Object:   type=Operator   dims=[20]   size=(20, 20)   ishermitian=false
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:
⎡⠈⠢⡀⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠈⠢⡀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠈⠢⡀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠈⠢⡀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢⎦

julia> fock(20, 3)' * a * fock(20, 4)
2.0 + 0.0im

source

QuantumToolbox.create Function
julia
create(N::Int)

Bosonic creation operator with Hilbert space cutoff N.

This operator acts on a fock state as a^|n=n+1|n+1.

Examples

julia
julia> a_d = create(20)

Quantum Object:   type=Operator   dims=[20]   size=(20, 20)   ishermitian=false
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:
⎡⠢⡀⠀⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠈⠢⡀⠀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠈⠢⡀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠈⠢⡀⠀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠈⠢⡀⎦

julia> fock(20, 4)' * a_d * fock(20, 3)
2.0 + 0.0im

source

QuantumToolbox.displace Function
julia
displace(N::Int, α::Number)

Generate a displacement operator:

D^(α)=exp(αa^αa^),

where a^ is the bosonic annihilation operator, and α is the amount of displacement in optical phase space.

source

QuantumToolbox.squeeze Function
julia
squeeze(N::Int, z::Number)

Generate a single-mode squeeze operator:

S^(z)=exp(12(za^2z(a^)2)),

where a^ is the bosonic annihilation operator.

source

QuantumToolbox.num Function
julia
num(N::Int)

Bosonic number operator with Hilbert space cutoff N.

This operator is defined as N^=a^a^, where a^ is the bosonic annihilation operator.

source

QuantumToolbox.position Function
julia
position(N::Int)

Position operator with Hilbert space cutoff N.

This operator is defined as x^=12(a^+a^), where a^ is the bosonic annihilation operator.

source

QuantumToolbox.momentum Function
julia
momentum(N::Int)

Momentum operator with Hilbert space cutoff N.

This operator is defined as p^=i2(a^a^), where a^ is the bosonic annihilation operator.

source

QuantumToolbox.phase Function
julia
phase(N::Int, ϕ0::Real=0)

Single-mode Pegg-Barnett phase operator with Hilbert space cutoff N and the reference phase ϕ0.

This operator is defined as

ϕ^=m=0N1ϕm|ϕmϕm|,

where

ϕm=ϕ0+2mπN,

and

|ϕm=1Nn=0N1exp(inϕm)|n.

Reference

source

QuantumToolbox.fdestroy Function
julia
fdestroy(N::Union{Int,Val}, j::Int)

Construct a fermionic destruction operator acting on the j-th site, where the fock space has totally N-sites:

Here, we use the Jordan-Wigner transformation, namely

d^j=σ^zj1σ^+1^Nj

The site index j should satisfy: 1 ≤ j ≤ N.

Note that we put σ^+=(0100) here because we consider |0=(10) to be ground (vacant) state, and |1=(01) to be excited (occupied) state.

Beware of type-stability!

If you want to keep type stability, it is recommended to use fdestroy(Val(N), j) instead of fdestroy(N, j). See this link and the related Section about type stability for more details.

source

QuantumToolbox.fcreate Function
julia
fcreate(N::Union{Int,Val}, j::Int)

Construct a fermionic creation operator acting on the j-th site, where the fock space has totally N-sites:

Here, we use the Jordan-Wigner transformation, namely

d^j=σ^zj1σ^1^Nj

The site index j should satisfy: 1 ≤ j ≤ N.

Note that we put σ^=(0010) here because we consider |0=(10) to be ground (vacant) state, and |1=(01) to be excited (occupied) state.

Beware of type-stability!

If you want to keep type stability, it is recommended to use fcreate(Val(N), j) instead of fcreate(N, j). See this link and the related Section about type stability for more details.

source

QuantumToolbox.tunneling Function
julia
tunneling(N::Int, m::Int=1; sparse::Union{Bool,Val{<:Bool}}=Val(false))

Generate a tunneling operator defined as:

n=0Nm|nn+m|+|n+mn|,

where N is the number of basis states in the Hilbert space, and m is the number of excitations in tunneling event.

If sparse=true, the operator is returned as a sparse matrix, otherwise a dense matrix is returned.

Beware of type-stability!

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 and the related Section about type stability for more details.

source

QuantumToolbox.qft Function
julia
qft(dimensions)

Generates a discrete Fourier transform matrix F^N for Quantum Fourier Transform (QFT) with given argument dimensions.

The dimensions can be either the following types:

  • dimensions::Int: Number of basis states in the Hilbert space.

  • dimensions::Union{Dimensions,AbstractVector{Int},Tuple}: list of dimensions representing the each number of basis in the subsystems.

N represents the total dimension, and therefore the matrix is defined as

F^N=1N[111111ωω2ω3ωN11ω2ω4ω6ω2(N1)1ω3ω6ω9ω3(N1)1ωN1ω2(N1)ω3(N1)ω(N1)(N1)],

where ω=exp(2πiN).

Beware of type-stability!

It is highly recommended to use qft(dimensions) with dimensions as Tuple or SVector to keep type stability. See the related Section about type stability for more details.

source

QuantumToolbox.eye Function
julia
eye(N::Int; type=Operator, dims=nothing)
qeye(N::Int; type=Operator, dims=nothing)

Identity operator 1^ with size N.

It is also possible to specify the list of Hilbert dimensions dims if different subsystems are present.

Note that type can only be either Operator or SuperOperator

Note

qeye is a synonym of eye.

source

QuantumToolbox.projection Function
julia
projection(N::Int, i::Int, j::Int)

Generates the projection operator O^=|ij| with Hilbert space dimension N.

source

QuantumToolbox.commutator Function
julia
commutator(A::QuantumObject, B::QuantumObject; anti::Bool=false)

Return the commutator (or anti-commutator) of the two QuantumObject:

  • commutator (anti=false): A^B^B^A^

  • anticommutator (anti=true): A^B^+B^A^

Note that A and B must be Operator

source

QuantumToolbox.spre Function
julia
spre(A::AbstractQuantumObject, Id_cache=I(size(A,1)))

Returns the SuperOperator form of A acting on the left of the density matrix operator: O(A^)[ρ^]=A^ρ^.

Since the density matrix is vectorized in OperatorKet form: |ρ^, this SuperOperator is always a matrix 1^A^, namely

O(A^)[ρ^]=1^A^ |ρ^

(see the section in documentation: Superoperators and Vectorized Operators for more details)

The optional argument Id_cache can be used to pass a precomputed identity matrix. This can be useful when the same function is applied multiple times with a known Hilbert space dimension.

See also spost and sprepost.

source

QuantumToolbox.spost Function
julia
spost(B::AbstractQuantumObject, Id_cache=I(size(B,1)))

Returns the SuperOperator form of B acting on the right of the density matrix operator: O(B^)[ρ^]=ρ^B^.

Since the density matrix is vectorized in OperatorKet form: |ρ^, this SuperOperator is always a matrix B^T1^, namely

O(B^)[ρ^]=B^T1^ |ρ^

(see the section in documentation: Superoperators and Vectorized Operators for more details)

The optional argument Id_cache can be used to pass a precomputed identity matrix. This can be useful when the same function is applied multiple times with a known Hilbert space dimension.

See also spre and sprepost.

source

QuantumToolbox.sprepost Function
julia
sprepost(A::AbstractQuantumObject, B::AbstractQuantumObject)

Returns the SuperOperator form of A and B acting on the left and right of the density matrix operator, respectively: O(A^,B^)[ρ^]=A^ρ^B^.

Since the density matrix is vectorized in OperatorKet form: |ρ^, this SuperOperator is always a matrix B^TA^, namely

O(A^,B^)[ρ^]=B^TA^ |ρ^=spre(A^)spost(B^) |ρ^

(see the section in documentation: Superoperators and Vectorized Operators for more details)

See also spre and spost.

source

QuantumToolbox.lindblad_dissipator Function
julia
lindblad_dissipator(O::AbstractQuantumObject, Id_cache=I(size(O,1))

Returns the Lindblad SuperOperator defined as

D(O^)[ρ^]=12(2O^ρ^O^O^O^ρ^ρ^O^O^)

The optional argument Id_cache can be used to pass a precomputed identity matrix. This can be useful when the same function is applied multiple times with a known Hilbert space dimension.

See also spre, spost, and sprepost.

source

Synonyms of functions for Qobj

QuantumToolbox.Qobj Type
julia
Qobj(A; kwargs...)

Note

Qobj is a synonym for generating QuantumObject. See the docstring of QuantumObject for more details.

source

QuantumToolbox.QobjEvo Type
julia
QobjEvo(args...; kwargs...)

Note

QobjEvo is a synonym for generating QuantumObjectEvolution. See the docstrings of QuantumObjectEvolution for more details.

source

QuantumToolbox.shape Function
julia
size(A::AbstractQuantumObject)
size(A::AbstractQuantumObject, idx::Int)
shape(A::AbstractQuantumObject)
shape(A::AbstractQuantumObject, idx::Int)

Returns a tuple containing each dimensions of the array in the AbstractQuantumObject.

Optionally, you can specify an index (idx) to just get the corresponding dimension of the array.

Note

shape is a synonym of size.

source

QuantumToolbox.isherm Function
julia
ishermitian(A::AbstractQuantumObject)
isherm(A::AbstractQuantumObject)

Test whether the AbstractQuantumObject is Hermitian.

Note

isherm is a synonym of ishermitian.

source

QuantumToolbox.trans Function
julia
transpose(A::AbstractQuantumObject)

Lazy matrix transpose of the AbstractQuantumObject.

source

QuantumToolbox.dag Function
julia
A'
adjoint(A::AbstractQuantumObject)
dag(A::AbstractQuantumObject)

Lazy adjoint (conjugate transposition) of the AbstractQuantumObject

Note

A' and dag(A) are synonyms of adjoint(A).

source

QuantumToolbox.matrix_element Function
julia
matrix_element(i::QuantumObject, A::QuantumObject j::QuantumObject)

Compute the generalized dot product dot(i, A*j) between three QuantumObject: i|A^|j

Note that this function is same as dot(i, A, j)

Supports the following inputs:

source

QuantumToolbox.unit Function
julia
normalize(A::QuantumObject, p::Real)
unit(A::QuantumObject, p::Real)

Return normalized QuantumObject so that its p-norm equals to unity, i.e. norm(A, p) == 1.

Support for the following types of QuantumObject:

Note

unit is a synonym of normalize.

Also, see norm about its definition for different types of QuantumObject.

source

QuantumToolbox.tensor Function
julia
kron(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
tensor(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
A  B

Returns the Kronecker product A^B^.

Note

tensor and (where can be typed by tab-completing \otimes in the REPL) are synonyms of kron.

Examples

julia
julia> a = destroy(20)

Quantum Object:   type=Operator   dims=[20]   size=(20, 20)   ishermitian=false
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:
⎡⠈⠢⡀⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠈⠢⡀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠈⠢⡀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠈⠢⡀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢⎦

julia> O = kron(a, a);

julia> size(a), size(O)
((20, 20), (400, 400))

julia> a.dims, O.dims
([20], [20, 20])

source

QuantumToolbox.:⊗ Function
julia
kron(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
tensor(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
(A::AbstractQuantumObject, B::AbstractQuantumObject, ...)
A  B

Returns the Kronecker product A^B^.

Note

tensor and (where can be typed by tab-completing \otimes in the REPL) are synonyms of kron.

Examples

julia
julia> a = destroy(20)

Quantum Object:   type=Operator   dims=[20]   size=(20, 20)   ishermitian=false
20×20 SparseMatrixCSC{ComplexF64, Int64} with 19 stored entries:
⎡⠈⠢⡀⠀⠀⠀⠀⠀⠀⠀⎤
⎢⠀⠀⠈⠢⡀⠀⠀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠈⠢⡀⠀⠀⠀⎥
⎢⠀⠀⠀⠀⠀⠀⠈⠢⡀⠀⎥
⎣⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢⎦

julia> O = kron(a, a);

julia> size(a), size(O)
((20, 20), (400, 400))

julia> a.dims, O.dims
([20], [20, 20])

source

QuantumToolbox.qeye Function
julia
eye(N::Int; type=Operator, dims=nothing)
qeye(N::Int; type=Operator, dims=nothing)

Identity operator 1^ with size N.

It is also possible to specify the list of Hilbert dimensions dims if different subsystems are present.

Note that type can only be either Operator or SuperOperator

Note

qeye is a synonym of eye.

source

QuantumToolbox.vector_to_operator Function
julia
vec2mat(A::AbstractVector)

Converts a vector to a matrix.

source

julia
vec2mat(A::QuantumObject)
vector_to_operator(A::QuantumObject)

Convert a quantum object from vector (OperatorKetQuantumObject-type) to matrix (OperatorQuantumObject-type)

Note

vector_to_operator is a synonym of vec2mat.

source

QuantumToolbox.operator_to_vector Function
julia
mat2vec(A::QuantumObject)
operator_to_vector(A::QuantumObject)

Convert a quantum object from matrix (OperatorQuantumObject-type) to vector (OperatorKetQuantumObject-type)

Note

operator_to_vector is a synonym of mat2vec.

source

julia
mat2vec(A::AbstractMatrix)

Converts a matrix to a vector.

source

QuantumToolbox.sqrtm Function
julia
sqrtm(A::QuantumObject)

Matrix square root of Operator type of QuantumObject

Note that for other types of QuantumObject use sprt(A) instead.

source

QuantumToolbox.logm Function
julia
logm(A::QuantumObject)

Matrix logarithm of QuantumObject

Note that this function is same as log(A) and only supports for Operator and SuperOperator.

source

QuantumToolbox.expm Function
julia
expm(A::QuantumObject)

Matrix exponential of QuantumObject

Note that this function is same as exp(A) and only supports for Operator and SuperOperator.

source

QuantumToolbox.sinm Function
julia
sinm(A::QuantumObject)

Matrix sine of QuantumObject, defined as

sin(A^)=eiA^eiA^2i

Note that this function is same as sin(A) and only supports for Operator and SuperOperator.

source

QuantumToolbox.cosm Function
julia
cosm(A::QuantumObject)

Matrix cosine of QuantumObject, defined as

cos(A^)=eiA^+eiA^2

Note that this function is same as cos(A) and only supports for Operator and SuperOperator.

source

Time evolution

QuantumToolbox.TimeEvolutionProblem Type
julia
struct TimeEvolutionProblem

A Julia constructor for handling the ODEProblem of the time evolution of quantum systems.

Fields (Attributes)

  • prob::AbstractSciMLProblem: The ODEProblem of the time evolution.

  • times::Abstractvector: The time list of the evolution.

  • dimensions::AbstractDimensions: The dimensions of the Hilbert space.

  • kwargs::KWT: Generic keyword arguments.

dims property

For a given prob::TimeEvolutionProblem, prob.dims or getproperty(prob, :dims) returns its dimensions in the type of integer-vector.

source

QuantumToolbox.TimeEvolutionSol Type
julia
struct TimeEvolutionSol

A structure storing the results and some information from solving time evolution.

Fields (Attributes)

  • times::AbstractVector: The time list of the evolution.

  • states::Vector{QuantumObject}: The list of result states.

  • expect::Union{AbstractMatrix,Nothing}: The expectation values corresponding to each time point in times.

  • retcode: The return code from the solver.

  • alg: The algorithm which is used during the solving process.

  • abstol::Real: The absolute tolerance which is used during the solving process.

  • reltol::Real: The relative tolerance which is used during the solving process.

source

QuantumToolbox.TimeEvolutionMCSol Type
julia
struct TimeEvolutionMCSol

A structure storing the results and some information from solving quantum trajectories of the Monte Carlo wave function time evolution.

Fields (Attributes)

  • ntraj::Int: Number of trajectories

  • times::AbstractVector: The time list of the evolution.

  • states::Vector{Vector{QuantumObject}}: The list of result states in each trajectory.

  • expect::Union{AbstractMatrix,Nothing}: The expectation values (averaging all trajectories) corresponding to each time point in times.

  • average_expect::Union{AbstractMatrix,Nothing}: The expectation values (averaging all trajectories) corresponding to each time point in times.

  • runs_expect::Union{AbstractArray,Nothing}: The expectation values corresponding to each trajectory and each time point in times

  • col_times::Vector{Vector{Real}}: The time records of every quantum jump occurred in each trajectory.

  • col_which::Vector{Vector{Int}}: The indices of which collapse operator was responsible for each quantum jump in col_times.

  • converged::Bool: Whether the solution is converged or not.

  • alg: The algorithm which is used during the solving process.

  • abstol::Real: The absolute tolerance which is used during the solving process.

  • reltol::Real: The relative tolerance which is used during the solving process.

source

QuantumToolbox.TimeEvolutionStochasticSol Type
julia
struct TimeEvolutionStochasticSol

A structure storing the results and some information from solving trajectories of the Stochastic time evolution.

Fields (Attributes)

  • ntraj::Int: Number of trajectories

  • times::AbstractVector: The time list of the evolution.

  • states::Vector{Vector{QuantumObject}}: The list of result states in each trajectory.

  • expect::Union{AbstractMatrix,Nothing}: The expectation values (averaging all trajectories) corresponding to each time point in times.

  • average_expect::Union{AbstractMatrix,Nothing}: The expectation values (averaging all trajectories) corresponding to each time point in times.

  • runs_expect::Union{AbstractArray,Nothing}: The expectation values corresponding to each trajectory and each time point in times

  • converged::Bool: Whether the solution is converged or not.

  • alg: The algorithm which is used during the solving process.

  • abstol::Real: The absolute tolerance which is used during the solving process.

  • reltol::Real: The relative tolerance which is used during the solving process.

source

QuantumToolbox.sesolveProblem Function
julia
sesolveProblem(
    H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
    ψ0::QuantumObject{KetQuantumObject},
    tlist::AbstractVector;
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    progress_bar::Union{Val,Bool} = Val(true),
    inplace::Union{Val,Bool} = Val(true),
    kwargs...,
)

Generate the ODEProblem for the Schrödinger time evolution of a quantum system:

t|ψ(t)=iH^|ψ(t)

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0).

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: Parameters to pass to the solver. This argument is usually expressed as a NamedTuple or AbstractVector of parameters. For more advanced usage, any custom struct can be used.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • inplace: Whether to use the inplace version of the ODEProblem. The default is Val(true). It is recommended to use Val(true) for better performance, but it is sometimes necessary to use Val(false), for example when performing automatic differentiation using Zygote.jl.

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-6 and abstol=1e-8.

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Returns

  • prob: The TimeEvolutionProblem containing the ODEProblem for the Schrödinger time evolution of the system.

source

QuantumToolbox.mesolveProblem Function
julia
mesolveProblem(
    H::Union{AbstractQuantumObject,Tuple},
    ψ0::QuantumObject,
    tlist,
    c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    progress_bar::Union{Val,Bool} = Val(true),
    inplace::Union{Val,Bool} = Val(true),
    kwargs...,
)

Generate the ODEProblem for the master equation time evolution of an open quantum system:

ρ^(t)t=i[H^,ρ^(t)]+nD(C^n)[ρ^(t)]

where

D(C^n)[ρ^(t)]=C^nρ^(t)C^n12C^nC^nρ^(t)12ρ^(t)C^nC^n

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0). It can be either a Ket or a Operator.

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • c_ops: List of collapse operators {C^n}n. It can be either a Vector or a Tuple.

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: Parameters to pass to the solver. This argument is usually expressed as a NamedTuple or AbstractVector of parameters. For more advanced usage, any custom struct can be used.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • inplace: Whether to use the inplace version of the ODEProblem. The default is Val(true). It is recommended to use Val(true) for better performance, but it is sometimes necessary to use Val(false), for example when performing automatic differentiation using Zygote.jl.

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-6 and abstol=1e-8.

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Returns

  • prob::ODEProblem: The ODEProblem for the master equation time evolution.

source

QuantumToolbox.mcsolveProblem Function
julia
mcsolveProblem(
    H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
    ψ0::QuantumObject{KetQuantumObject},
    tlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    rng::AbstractRNG = default_rng(),
    jump_callback::TJC = ContinuousLindbladJumpCallback(),
    kwargs...,
)

Generate the ODEProblem for a single trajectory of the Monte Carlo wave function time evolution of an open quantum system.

Given a system Hamiltonian H^ and a list of collapse (jump) operators {C^n}n, the evolution of the state |ψ(t) is governed by the Schrodinger equation:

t|ψ(t)=iH^eff|ψ(t)

with a non-Hermitian effective Hamiltonian:

H^eff=H^i2nC^nC^n.

To the first-order of the wave function in a small time δt, the strictly negative non-Hermitian portion in H^eff gives rise to a reduction in the norm of the wave function, namely

ψ(t+δt)|ψ(t+δt)=1δp,

where

δp=δtnψ(t)|C^nC^n|ψ(t)

is the corresponding quantum jump probability.

If the environmental measurements register a quantum jump, the wave function undergoes a jump into a state defined by projecting |ψ(t) using the collapse operator C^n corresponding to the measurement, namely

|ψ(t+δt)=C^n|ψ(t)ψ(t)|C^nC^n|ψ(t)

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0).

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • c_ops: List of collapse operators {C^n}n. It can be either a Vector or a Tuple.

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: Parameters to pass to the solver. This argument is usually expressed as a NamedTuple or AbstractVector of parameters. For more advanced usage, any custom struct can be used.

  • rng: Random number generator for reproducibility.

  • jump_callback: The Jump Callback type: Discrete or Continuous. The default is ContinuousLindbladJumpCallback(), which is more precise.

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-6 and abstol=1e-8.

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Returns

  • prob: The TimeEvolutionProblem containing the ODEProblem for the Monte Carlo wave function time evolution.

source

QuantumToolbox.mcsolveEnsembleProblem Function
julia
mcsolveEnsembleProblem(
    H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
    ψ0::QuantumObject{KetQuantumObject},
    tlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    rng::AbstractRNG = default_rng(),
    ntraj::Int = 500,
    ensemblealg::EnsembleAlgorithm = EnsembleThreads(),
    jump_callback::TJC = ContinuousLindbladJumpCallback(),
    progress_bar::Union{Val,Bool} = Val(true),
    prob_func::Union{Function, Nothing} = nothing,
    output_func::Union{Tuple,Nothing} = nothing,
    kwargs...,
)

Generate the EnsembleProblem of ODEProblems for the ensemble of trajectories of the Monte Carlo wave function time evolution of an open quantum system.

Given a system Hamiltonian H^ and a list of collapse (jump) operators {C^n}n, the evolution of the state |ψ(t) is governed by the Schrodinger equation:

t|ψ(t)=iH^eff|ψ(t)

with a non-Hermitian effective Hamiltonian:

H^eff=H^i2nC^nC^n.

To the first-order of the wave function in a small time δt, the strictly negative non-Hermitian portion in H^eff gives rise to a reduction in the norm of the wave function, namely

ψ(t+δt)|ψ(t+δt)=1δp,

where

δp=δtnψ(t)|C^nC^n|ψ(t)

is the corresponding quantum jump probability.

If the environmental measurements register a quantum jump, the wave function undergoes a jump into a state defined by projecting |ψ(t) using the collapse operator C^n corresponding to the measurement, namely

|ψ(t+δt)=C^n|ψ(t)ψ(t)|C^nC^n|ψ(t)

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0).

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • c_ops: List of collapse operators {C^n}n. It can be either a Vector or a Tuple.

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: Parameters to pass to the solver. This argument is usually expressed as a NamedTuple or AbstractVector of parameters. For more advanced usage, any custom struct can be used.

  • rng: Random number generator for reproducibility.

  • ntraj: Number of trajectories to use.

  • ensemblealg: Ensemble algorithm to use. Default to EnsembleThreads().

  • jump_callback: The Jump Callback type: Discrete or Continuous. The default is ContinuousLindbladJumpCallback(), which is more precise.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • prob_func: Function to use for generating the ODEProblem.

  • output_func: a Tuple containing the Function to use for generating the output of a single trajectory, the (optional) ProgressBar object, and the (optional) RemoteChannel object.

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-6 and abstol=1e-8.

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Returns

  • prob: The TimeEvolutionProblem containing the Ensemble ODEProblem for the Monte Carlo wave function time evolution.

source

QuantumToolbox.ssesolveProblem Function
julia
ssesolveProblem(
    H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
    ψ0::QuantumObject{KetQuantumObject},
    tlist::AbstractVector,
    sc_ops::Union{Nothing,AbstractVector,Tuple,AbstractQuantumObject} = nothing;
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    rng::AbstractRNG = default_rng(),
    progress_bar::Union{Val,Bool} = Val(true),
    store_measurement::Union{Val, Bool} = Val(false),
    kwargs...,
)

Generate the SDEProblem for the Stochastic Schrödinger time evolution of a quantum system. This is defined by the following stochastic differential equation:

d|ψ(t)=iK^|ψ(t)dt+nM^n|ψ(t)dWn(t)

where

K^=H^+in(en2S^n12S^nS^nen28),M^n=S^nen2,

and

en=S^n+S^n.

Above, S^n are the stochastic collapse operators and dWn(t) is the real Wiener increment associated to S^n. See (Wiseman and Milburn, 2009) for more details.

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0).

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • sc_ops: List of stochastic collapse operators {S^n}n. It can be either a Vector, a Tuple or a AbstractQuantumObject. It is recommended to use the last case when only one operator is provided.

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: NullParameters of parameters to pass to the solver.

  • rng: Random number generator for reproducibility.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • store_measurement: Whether to store the measurement results. Default is Val(false).

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-2 and abstol=1e-2.

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Performance Tip

When sc_ops contains only a single operator, it is recommended to pass only that operator as the argument. This ensures that the stochastic noise is diagonal, making the simulation faster.

Returns

  • prob: The SDEProblem for the Stochastic Schrödinger time evolution of the system.

source

QuantumToolbox.ssesolveEnsembleProblem Function
julia
ssesolveEnsembleProblem(
    H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
    ψ0::QuantumObject{KetQuantumObject},
    tlist::AbstractVector,
    sc_ops::Union{Nothing,AbstractVector,Tuple,AbstractQuantumObject} = nothing;
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    rng::AbstractRNG = default_rng(),
    ntraj::Int = 500,
    ensemblealg::EnsembleAlgorithm = EnsembleThreads(),
    prob_func::Union{Function, Nothing} = nothing,
    output_func::Union{Tuple,Nothing} = nothing,
    progress_bar::Union{Val,Bool} = Val(true),
    store_measurement::Union{Val,Bool} = Val(false),
    kwargs...,
)

Generate the SDE EnsembleProblem for the Stochastic Schrödinger time evolution of a quantum system. This is defined by the following stochastic differential equation:

d|ψ(t)=iK^|ψ(t)dt+nM^n|ψ(t)dWn(t)

where

K^=H^+in(en2S^n12S^nS^nen28),M^n=S^nen2,

and

en=S^n+S^n.

Above, S^n are the stochastic collapse operators and dWn(t) is the real Wiener increment associated to S^n. See (Wiseman and Milburn, 2009) for more details.

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0).

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • sc_ops: List of stochastic collapse operators {S^n}n. It can be either a Vector, a Tuple or a AbstractQuantumObject. It is recommended to use the last case when only one operator is provided.

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: NullParameters of parameters to pass to the solver.

  • rng: Random number generator for reproducibility.

  • ntraj: Number of trajectories to use. Default is 500.

  • ensemblealg: Ensemble method to use. Default to EnsembleThreads().

  • jump_callback: The Jump Callback type: Discrete or Continuous. The default is ContinuousLindbladJumpCallback(), which is more precise.

  • prob_func: Function to use for generating the SDEProblem.

  • output_func: a Tuple containing the Function to use for generating the output of a single trajectory, the (optional) ProgressBar object, and the (optional) RemoteChannel object.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • store_measurement: Whether to store the measurement results. Default is Val(false).

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-2 and abstol=1e-2.

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Performance Tip

When sc_ops contains only a single operator, it is recommended to pass only that operator as the argument. This ensures that the stochastic noise is diagonal, making the simulation faster.

Returns

  • prob::EnsembleProblem with SDEProblem: The Ensemble SDEProblem for the Stochastic Shrödinger time evolution.

source

QuantumToolbox.smesolveProblem Function
julia
smesolveProblem(
    H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
    ψ0::QuantumObject,
    tlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    sc_ops::Union{Nothing,AbstractVector,Tuple,AbstractQuantumObject} = nothing;
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    rng::AbstractRNG = default_rng(),
    progress_bar::Union{Val,Bool} = Val(true),
    store_measurement::Union{Val, Bool} = Val(false),
    kwargs...,
)

Generate the SDEProblem for the Stochastic Master Equation time evolution of an open quantum system. This is defined by the following stochastic differential equation:

dρ(t)=i[H^,ρ(t)]dt+iD[C^i]ρ(t)dt+nD[S^n]ρ(t)dt+nH[S^n]ρ(t)dWn(t),

where

D[O^]ρ=O^ρO^12{O^O^,ρ},

is the Lindblad superoperator, and

H[O^]ρ=O^ρ+ρO^Tr[O^ρ+ρO^]ρ,

Above, C^i represent the collapse operators related to pure dissipation, while S^n are the stochastic collapse operators. The dWn(t) term is the real Wiener increment associated to S^n. See (Wiseman and Milburn, 2009) for more details.

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0). It can be either a Ket or a Operator.

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • c_ops: List of collapse operators {C^i}i. It can be either a Vector or a Tuple.

  • sc_ops: List of stochastic collapse operators {S^n}n. It can be either a Vector, a Tuple or a AbstractQuantumObject. It is recommended to use the last case when only one operator is provided.

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: NullParameters of parameters to pass to the solver.

  • rng: Random number generator for reproducibility.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • store_measurement: Whether to store the measurement expectation values. Default is Val(false).

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-2 and abstol=1e-2.

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Performance Tip

When sc_ops contains only a single operator, it is recommended to pass only that operator as the argument. This ensures that the stochastic noise is diagonal, making the simulation faster.

Returns

  • prob: The TimeEvolutionProblem containing the SDEProblem for the Stochastic Master Equation time evolution.

source

QuantumToolbox.smesolveEnsembleProblem Function
julia
smesolveEnsembleProblem(
    H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
    ψ0::QuantumObject,
    tlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    sc_ops::Union{Nothing,AbstractVector,Tuple,AbstractQuantumObject} = nothing;
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    rng::AbstractRNG = default_rng(),
    ntraj::Int = 500,
    ensemblealg::EnsembleAlgorithm = EnsembleThreads(),
    prob_func::Union{Function, Nothing} = nothing,
    output_func::Union{Tuple,Nothing} = nothing,
    progress_bar::Union{Val,Bool} = Val(true),
    store_measurement::Union{Val,Bool} = Val(false),
    kwargs...,
)

Generate the SDEProblem for the Stochastic Master Equation time evolution of an open quantum system. This is defined by the following stochastic differential equation:

dρ(t)=i[H^,ρ(t)]dt+iD[C^i]ρ(t)dt+nD[S^n]ρ(t)dt+nH[S^n]ρ(t)dWn(t),

where

D[O^]ρ=O^ρO^12{O^O^,ρ},

is the Lindblad superoperator, and

H[O^]ρ=O^ρ+ρO^Tr[O^ρ+ρO^]ρ,

Above, C^i represent the collapse operators related to pure dissipation, while S^n are the stochastic collapse operators. The dWn(t) term is the real Wiener increment associated to S^n. See (Wiseman and Milburn, 2009) for more details.

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0). It can be either a Ket or a Operator.

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • c_ops: List of collapse operators {C^i}i. It can be either a Vector or a Tuple.

  • sc_ops: List of stochastic collapse operators {S^n}n. It can be either a Vector, a Tuple or a AbstractQuantumObject. It is recommended to use the last case when only one operator is provided.

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: NullParameters of parameters to pass to the solver.

  • rng: Random number generator for reproducibility.

  • ntraj: Number of trajectories to use. Default is 500.

  • ensemblealg: Ensemble method to use. Default to EnsembleThreads().

  • prob_func: Function to use for generating the SDEProblem.

  • output_func: a Tuple containing the Function to use for generating the output of a single trajectory, the (optional) ProgressBar object, and the (optional) RemoteChannel object.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • store_measurement: Whether to store the measurement expectation values. Default is Val(false).

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-2 and abstol=1e-2.

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Performance Tip

When sc_ops contains only a single operator, it is recommended to pass only that operator as the argument. This ensures that the stochastic noise is diagonal, making the simulation faster.

Returns

  • prob: The TimeEvolutionProblem containing the Ensemble SDEProblem for the Stochastic Master Equation time evolution.

source

QuantumToolbox.sesolve Function
julia
sesolve(
    H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
    ψ0::QuantumObject{KetQuantumObject},
    tlist::AbstractVector;
    alg::OrdinaryDiffEqAlgorithm = Tsit5(),
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    progress_bar::Union{Val,Bool} = Val(true),
    inplace::Union{Val,Bool} = Val(true),
    kwargs...,
)

Time evolution of a closed quantum system using the Schrödinger equation:

t|ψ(t)=iH^|ψ(t)

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0).

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • alg: The algorithm for the ODE solver. The default is Tsit5().

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: Parameters to pass to the solver. This argument is usually expressed as a NamedTuple or AbstractVector of parameters. For more advanced usage, any custom struct can be used.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • inplace: Whether to use the inplace version of the ODEProblem. The default is Val(true). It is recommended to use Val(true) for better performance, but it is sometimes necessary to use Val(false), for example when performing automatic differentiation using Zygote.jl.

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-6 and abstol=1e-8.

  • For more details about alg please refer to DifferentialEquations.jl (ODE Solvers)

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Returns

  • sol::TimeEvolutionSol: The solution of the time evolution. See also TimeEvolutionSol

source

QuantumToolbox.mesolve Function
julia
mesolve(
    H::Union{AbstractQuantumObject,Tuple},
    ψ0::QuantumObject,
    tlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
    alg::OrdinaryDiffEqAlgorithm = Tsit5(),
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    progress_bar::Union{Val,Bool} = Val(true),
    inplace::Union{Val,Bool} = Val(true),
    kwargs...,
)

Time evolution of an open quantum system using Lindblad master equation:

ρ^(t)t=i[H^,ρ^(t)]+nD(C^n)[ρ^(t)]

where

D(C^n)[ρ^(t)]=C^nρ^(t)C^n12C^nC^nρ^(t)12ρ^(t)C^nC^n

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0). It can be either a Ket or a Operator.

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • c_ops: List of collapse operators {C^n}n. It can be either a Vector or a Tuple.

  • alg: The algorithm for the ODE solver. The default value is Tsit5().

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: Parameters to pass to the solver. This argument is usually expressed as a NamedTuple or AbstractVector of parameters. For more advanced usage, any custom struct can be used.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • inplace: Whether to use the inplace version of the ODEProblem. The default is Val(true). It is recommended to use Val(true) for better performance, but it is sometimes necessary to use Val(false), for example when performing automatic differentiation using Zygote.jl.

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-6 and abstol=1e-8.

  • For more details about alg please refer to DifferentialEquations.jl (ODE Solvers)

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Returns

  • sol::TimeEvolutionSol: The solution of the time evolution. See also TimeEvolutionSol

source

QuantumToolbox.mcsolve Function
julia
mcsolve(
    H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
    ψ0::QuantumObject{KetQuantumObject},
    tlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
    alg::OrdinaryDiffEqAlgorithm = Tsit5(),
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    rng::AbstractRNG = default_rng(),
    ntraj::Int = 500,
    ensemblealg::EnsembleAlgorithm = EnsembleThreads(),
    jump_callback::TJC = ContinuousLindbladJumpCallback(),
    progress_bar::Union{Val,Bool} = Val(true),
    prob_func::Union{Function, Nothing} = nothing,
    output_func::Union{Tuple,Nothing} = nothing,
    normalize_states::Union{Val,Bool} = Val(true),
    kwargs...,
)

Time evolution of an open quantum system using quantum trajectories.

Given a system Hamiltonian H^ and a list of collapse (jump) operators {C^n}n, the evolution of the state |ψ(t) is governed by the Schrodinger equation:

t|ψ(t)=iH^eff|ψ(t)

with a non-Hermitian effective Hamiltonian:

H^eff=H^i2nC^nC^n.

To the first-order of the wave function in a small time δt, the strictly negative non-Hermitian portion in H^eff gives rise to a reduction in the norm of the wave function, namely

ψ(t+δt)|ψ(t+δt)=1δp,

where

δp=δtnψ(t)|C^nC^n|ψ(t)

is the corresponding quantum jump probability.

If the environmental measurements register a quantum jump, the wave function undergoes a jump into a state defined by projecting |ψ(t) using the collapse operator C^n corresponding to the measurement, namely

|ψ(t+δt)=C^n|ψ(t)ψ(t)|C^nC^n|ψ(t)

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0).

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • c_ops: List of collapse operators {C^n}n. It can be either a Vector or a Tuple.

  • alg: The algorithm to use for the ODE solver. Default to Tsit5().

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: Parameters to pass to the solver. This argument is usually expressed as a NamedTuple or AbstractVector of parameters. For more advanced usage, any custom struct can be used.

  • rng: Random number generator for reproducibility.

  • ntraj: Number of trajectories to use.

  • ensemblealg: Ensemble algorithm to use. Default to EnsembleThreads().

  • jump_callback: The Jump Callback type: Discrete or Continuous. The default is ContinuousLindbladJumpCallback(), which is more precise.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • prob_func: Function to use for generating the ODEProblem.

  • output_func: a Tuple containing the Function to use for generating the output of a single trajectory, the (optional) ProgressBar object, and the (optional) RemoteChannel object.

  • normalize_states: Whether to normalize the states. Default to Val(true).

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • ensemblealg can be one of EnsembleThreads(), EnsembleSerial(), EnsembleDistributed()

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-6 and abstol=1e-8.

  • For more details about alg please refer to DifferentialEquations.jl (ODE Solvers)

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Returns

source

QuantumToolbox.ssesolve Function
julia
ssesolve(
    H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
    ψ0::QuantumObject{KetQuantumObject},
    tlist::AbstractVector,
    sc_ops::Union{Nothing,AbstractVector,Tuple,AbstractQuantumObject} = nothing;
    alg::Union{Nothing,StochasticDiffEqAlgorithm} = nothing,
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    rng::AbstractRNG = default_rng(),
    ntraj::Int = 500,
    ensemblealg::EnsembleAlgorithm = EnsembleThreads(),
    prob_func::Union{Function, Nothing} = nothing,
    output_func::Union{Tuple,Nothing} = nothing,
    progress_bar::Union{Val,Bool} = Val(true),
    store_measurement::Union{Val,Bool} = Val(false),
    kwargs...,
)

Stochastic Schrödinger equation evolution of a quantum system given the system Hamiltonian H^ and a list of stochastic collapse (jump) operators {S^n}n. The stochastic evolution of the state |ψ(t) is defined by:

d|ψ(t)=iK^|ψ(t)dt+nM^n|ψ(t)dWn(t)

where

K^=H^+in(en2S^n12S^nS^nen28),M^n=S^nen2,

and

en=S^n+S^n.

Above, S^n are the stochastic collapse operators and dWn(t) is the real Wiener increment associated to S^n. See (Wiseman and Milburn, 2009) for more details.

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0).

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • sc_ops: List of stochastic collapse operators {S^n}n. It can be either a Vector, a Tuple or a AbstractQuantumObject. It is recommended to use the last case when only one operator is provided.

  • alg: The algorithm to use for the stochastic differential equation. Default is SRIW1() if sc_ops is an AbstractQuantumObject (diagonal noise), and SRA2() otherwise (non-diagonal noise).

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: NullParameters of parameters to pass to the solver.

  • rng: Random number generator for reproducibility.

  • ntraj: Number of trajectories to use. Default is 500.

  • ensemblealg: Ensemble method to use. Default to EnsembleThreads().

  • prob_func: Function to use for generating the SDEProblem.

  • output_func: a Tuple containing the Function to use for generating the output of a single trajectory, the (optional) ProgressBar object, and the (optional) RemoteChannel object.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • store_measurement: Whether to store the measurement results. Default is Val(false).

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-2 and abstol=1e-2.

  • For more details about alg please refer to DifferentialEquations.jl (SDE Solvers)

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Performance Tip

When sc_ops contains only a single operator, it is recommended to pass only that operator as the argument. This ensures that the stochastic noise is diagonal, making the simulation faster.

Returns

source

QuantumToolbox.smesolve Function
julia
smesolve(
    H::Union{AbstractQuantumObject{OperatorQuantumObject},Tuple},
    ψ0::QuantumObject,
    tlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    sc_ops::Union{Nothing,AbstractVector,Tuple,AbstractQuantumObject} = nothing;
    alg::Union{Nothing,StochasticDiffEqAlgorithm} = nothing,
    e_ops::Union{Nothing,AbstractVector,Tuple} = nothing,
    params = NullParameters(),
    rng::AbstractRNG = default_rng(),
    ntraj::Int = 500,
    ensemblealg::EnsembleAlgorithm = EnsembleThreads(),
    prob_func::Union{Function, Nothing} = nothing,
    output_func::Union{Tuple,Nothing} = nothing,
    progress_bar::Union{Val,Bool} = Val(true),
    store_measurement::Union{Val,Bool} = Val(false),
    kwargs...,
)

Stochastic Master Equation time evolution of an open quantum system. This is defined by the following stochastic differential equation:

dρ(t)=i[H^,ρ(t)]dt+iD[C^i]ρ(t)dt+nD[S^n]ρ(t)dt+nH[S^n]ρ(t)dWn(t),

where

D[O^]ρ=O^ρO^12{O^O^,ρ},

is the Lindblad superoperator, and

H[O^]ρ=O^ρ+ρO^Tr[O^ρ+ρO^]ρ,

Above, C^i represent the collapse operators related to pure dissipation, while S^n are the stochastic co operators. The dWn(t) term is the real Wiener increment associated to S^n. See (Wiseman and Milburn, 2009) for more details.

Arguments

  • H: Hamiltonian of the system H^. It can be either a QuantumObject, a QuantumObjectEvolution, or a Tuple of operator-function pairs.

  • ψ0: Initial state of the system |ψ(0). It can be either a Ket or a Operator.

  • tlist: List of times at which to save either the state or the expectation values of the system.

  • c_ops: List of collapse operators {C^i}i. It can be either a Vector or a Tuple.

  • sc_ops: List of stochastic collapse operators {S^n}n. It can be either a Vector, a Tuple or a AbstractQuantumObject. It is recommended to use the last case when only one operator is provided.

  • alg: The algorithm to use for the stochastic differential equation. Default is SRIW1() if sc_ops is an AbstractQuantumObject (diagonal noise), and SRA2() otherwise (non-diagonal noise).

  • e_ops: List of operators for which to calculate expectation values. It can be either a Vector or a Tuple.

  • params: NullParameters of parameters to pass to the solver.

  • rng: Random number generator for reproducibility.

  • ntraj: Number of trajectories to use. Default is 500.

  • ensemblealg: Ensemble method to use. Default to EnsembleThreads().

  • prob_func: Function to use for generating the SDEProblem.

  • output_func: a Tuple containing the Function to use for generating the output of a single trajectory, the (optional) ProgressBar object, and the (optional) RemoteChannel object.

  • progress_bar: Whether to show the progress bar. Using non-Val types might lead to type instabilities.

  • store_measurement: Whether to store the measurement expectation values. Default is Val(false).

  • kwargs: The keyword arguments for the ODEProblem.

Notes

  • The states will be saved depend on the keyword argument saveat in kwargs.

  • If e_ops is empty, the default value of saveat=tlist (saving the states corresponding to tlist), otherwise, saveat=[tlist[end]] (only save the final state). You can also specify e_ops and saveat separately.

  • The default tolerances in kwargs are given as reltol=1e-2 and abstol=1e-2.

  • For more details about kwargs please refer to DifferentialEquations.jl (Keyword Arguments)

Performance Tip

When sc_ops contains only a single operator, it is recommended to pass only that operator as the argument. This ensures that the stochastic noise is diagonal, making the simulation faster.

Returns

source

QuantumToolbox.dfd_mesolve Function
julia
dfd_mesolve(H::Function, ψ0::QuantumObject,
    tlist::AbstractVector, c_ops::Function, maxdims::AbstractVector,
    dfd_params::NamedTuple=NamedTuple();
    alg::OrdinaryDiffEqAlgorithm=Tsit5(),
    e_ops::Function=(dim_list) -> Vector{Vector{T1}}([]),
    params::NamedTuple=NamedTuple(),
    tol_list::Vector{<:Number}=fill(1e-8, length(maxdims)),
    kwargs...)

Time evolution of an open quantum system using master equation, dynamically changing the dimension of the Hilbert subspaces.

Notes

source

QuantumToolbox.liouvillian Function
julia
liouvillian(H::AbstractQuantumObject, c_ops::Union{Nothing,AbstractVector,Tuple}=nothing, Id_cache=I(prod(H.dimensions)))

Construct the Liouvillian SuperOperator for a system Hamiltonian H^ and a set of collapse operators {C^n}n:

L[]=i[H^,]+nD(C^n)[]

where

D(C^n)[]=C^n[]C^n12C^nC^n[]12[]C^nC^n

The optional argument Id_cache can be used to pass a precomputed identity matrix. This can be useful when the same function is applied multiple times with a known Hilbert space dimension.

See also spre, spost, and lindblad_dissipator.

source

QuantumToolbox.liouvillian_generalized Function
julia
liouvillian_generalized(H::QuantumObject, fields::Vector, 
T_list::Vector; N_trunc::Int=size(H,1), tol::Float64=0.0, σ_filter::Union{Nothing, Real}=nothing)

Constructs the generalized Liouvillian for a system coupled to a bath of harmonic oscillators.

See, e.g., Settineri, Alessio, et al. "Dissipation and thermal noise in hybrid quantum systems in the ultrastrong-coupling regime." Physical Review A 98.5 (2018): 053834.

source

Steady State Solvers

QuantumToolbox.steadystate Function
julia
steadystate(
    H::QuantumObject{OpType},
    c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
    solver::SteadyStateSolver = SteadyStateDirectSolver(),
    kwargs...,
)

Solve the stationary state based on different solvers.

Parameters

  • H: The Hamiltonian or the Liouvillian of the system.

  • c_ops: The list of the collapse operators.

  • solver: see documentation Solving for Steady-State Solutions for different solvers.

  • kwargs: The keyword arguments for the solver.

source

QuantumToolbox.steadystate_fourier Function
julia
steadystate_fourier(
    H_0::QuantumObject,
    H_p::QuantumObject,
    H_m::QuantumObject,
    ωd::Number,
    c_ops::Union{Nothing,AbstractVector,Tuple} = nothing;
    n_max::Integer = 2,
    tol::R = 1e-8,
    solver::FSolver = SteadyStateLinearSolver(),
    kwargs...,
)

Calculates the steady state of a periodically driven system. Here H_0 is the Hamiltonian or the Liouvillian of the undriven system. Considering a monochromatic drive at frequency ωd, we divide it into two parts, H_p and H_m, where H_p oscillates as eiωt and H_m oscillates as eiωt. There are two solvers available for this function:

  • SteadyStateLinearSolver: Solves the linear system of equations.

  • SSFloquetEffectiveLiouvillian: Solves the effective Liouvillian.

For both cases, n_max is the number of Fourier components to consider, and tol is the tolerance for the solver.

In the case of SteadyStateLinearSolver, the full linear system is solved at once:

(L0inωd)ρ^n+L1ρ^n1+L1ρ^n+1=0

This is a tridiagonal linear system of the form

Ab=0

where

A=(L0i(nmax)ωdL100L1L0i(nmax+1)ωdL100L1L0i(nmax+2)ωd0000L0inmaxωd)

and

b=(ρ^nmaxρ^nmax+1ρ^0ρ^nmax1ρ^nmax)

This will allow to simultaneously obtain all the ρ^n.

In the case of SSFloquetEffectiveLiouvillian, instead, the effective Liouvillian is calculated using the matrix continued fraction method.

different return

The two solvers returns different objects. The SteadyStateLinearSolver returns a list of QuantumObject, containing the density matrices for each Fourier component (ρ^n, with n from 0 to nmax), while the SSFloquetEffectiveLiouvillian returns only ρ^0.

Note

steadystate_floquet is a synonym of steadystate_fourier.

Arguments

  • H_0::QuantumObject: The Hamiltonian or the Liouvillian of the undriven system.

  • H_p::QuantumObject: The Hamiltonian or the Liouvillian of the part of the drive that oscillates as eiωt.

  • H_m::QuantumObject: The Hamiltonian or the Liouvillian of the part of the drive that oscillates as eiωt.

  • ωd::Number: The frequency of the drive.

  • c_ops::Union{Nothing,AbstractVector} = nothing: The optional collapse operators.

  • n_max::Integer = 2: The number of Fourier components to consider.

  • tol::R = 1e-8: The tolerance for the solver.

  • solver::FSolver = SteadyStateLinearSolver: The solver to use.

  • kwargs...: Additional keyword arguments to be passed to the solver.

source

QuantumToolbox.SteadyStateDirectSolver Type
julia
SteadyStateDirectSolver()

A solver which solves steadystate by finding the inverse of Liouvillian SuperOperator using the standard method given in LinearAlgebra.

source

QuantumToolbox.SteadyStateEigenSolver Type
julia
SteadyStateEigenSolver()

A solver which solves steadystate by finding the zero (or lowest) eigenvalue of Liouvillian SuperOperator using eigsolve.

source

QuantumToolbox.SteadyStateLinearSolver Type
julia
SteadyStateLinearSolver(alg = KrylovJL_GMRES(), Pl = nothing, Pr = nothing)

A solver which solves steadystate by finding the inverse of Liouvillian SuperOperator using the algorithms given in LinearSolve.jl.

Arguments

source

QuantumToolbox.SteadyStateODESolver Type
julia
SteadyStateODESolver(
    alg = Tsit5(),
    ψ0 = nothing,
    tmax = Inf,
    )

An ordinary differential equation (ODE) solver for solving steadystate.

Solve the stationary state based on time evolution (ordinary differential equations; OrdinaryDiffEq.jl) with a given initial state.

The termination condition of the stationary state |ρ is that either the following condition is true:

|ρ^treltol×|ρ^t+|ρ^

or

|ρ^tabstol

Arguments

  • alg::OrdinaryDiffEqAlgorithm=Tsit5(): The algorithm to solve the ODE.

  • ψ0::Union{Nothing,QuantumObject}=nothing: The initial state of the system. If not specified, a random pure state will be generated.

  • tmax::Real=Inf: The final time step for the steady state problem.

For more details about the solvers, please refer to OrdinaryDiffEq.jl.

source

QuantumToolbox.SSFloquetEffectiveLiouvillian Type
julia
SSFloquetEffectiveLiouvillian(steadystate_solver = SteadyStateDirectSolver())

A solver which solves steadystate_fourier by first extracting an effective time-independent Liouvillian and then using the steadystate_solver to extract the steadystate..

Parameters

  • steadystate_solver::SteadyStateSolver=SteadyStateDirectSolver(): The solver to use for the effective Liouvillian.

Note

This solver is only available for steadystate_fourier.

source

Dynamical Shifted Fock method

QuantumToolbox.dsf_mesolve Function
julia
dsf_mesolve(H::Function,
    ψ0::QuantumObject,
    tlist::AbstractVector, c_ops::Function,
    op_list::Vector{TOl},
    α0_l::Vector{<:Number}=zeros(length(op_list)),
    dsf_params::NamedTuple=NamedTuple();
    alg::OrdinaryDiffEqAlgorithm=Tsit5(),
    e_ops::Function=(op_list,p) -> Vector{TOl}([]),
    params::NamedTuple=NamedTuple(),
    δα_list::Vector{<:Number}=fill(0.2, length(op_list)),
    krylov_dim::Int=max(6, min(10, cld(length(ket2dm(ψ0).data), 4))),
    kwargs...)

Time evolution of an open quantum system using master equation and the Dynamical Shifted Fock algorithm.

Notes

source

QuantumToolbox.dsf_mcsolve Function
julia
dsf_mcsolve(H::Function,
    ψ0::QuantumObject,
    tlist::AbstractVector, c_ops::Function,
    op_list::Vector{TOl},
    α0_l::Vector{<:Number}=zeros(length(op_list)),
    dsf_params::NamedTuple=NamedTuple();
    alg::OrdinaryDiffEqAlgorithm=Tsit5(),
    e_ops::Function=(op_list,p) -> Vector{TOl}([]),
    params::NamedTuple=NamedTuple(),
    δα_list::Vector{<:Real}=fill(0.2, length(op_list)),
    ntraj::Int=500,
    ensemblealg::EnsembleAlgorithm=EnsembleThreads(),
    jump_callback::LindbladJumpCallbackType=ContinuousLindbladJumpCallback(),
    krylov_dim::Int=max(6, min(10, cld(length(ket2dm(ψ0).data), 4))),
    progress_bar::Union{Bool,Val} = Val(true)
    kwargs...)

Time evolution of a quantum system using the Monte Carlo wave function method and the Dynamical Shifted Fock algorithm.

Notes

source

Low-rank time evolution

QuantumToolbox.TimeEvolutionLRSol Type
julia
struct TimeEvolutionLRSol

A structure storing the results and some information from solving low-rank master equation time evolution.

Fields (Attributes)

  • times::AbstractVector: The time list of the evolution.

  • states::Vector{QuantumObject}: The list of result states.

  • expect::Matrix: The expectation values corresponding to each time point in times.

  • fexpect::Matrix: The function values at each time point.

  • retcode: The return code from the solver.

  • alg: The algorithm which is used during the solving process.

  • abstol::Real: The absolute tolerance which is used during the solving process.

  • reltol::Real: The relative tolerance which is used during the solving process.

  • z::Vector{QuantumObject}: The `z`` matrix of the low-rank algorithm at each time point.

  • B::Vector{QuantumObject}: The B matrix of the low-rank algorithm at each time point.

source

QuantumToolbox.lr_mesolveProblem Function
julia
lr_mesolveProblem(
    H::QuantumObject{OperatorQuantumObject},
    z::AbstractArray{T,2},
    B::AbstractArray{T,2},
    tlist::AbstractVector,
    c_ops::Union{AbstractVector,Tuple}=();
    e_ops::Union{AbstractVector,Tuple}=(),
    f_ops::Union{AbstractVector,Tuple}=(),
    opt::NamedTuple = lr_mesolve_options_default,
    kwargs...,
)

Formulates the ODEproblem for the low-rank time evolution of the system. The function is called by lr_mesolve. For more information about the low-rank master equation, see (Gravina and Savona, 2024).

Arguments

  • H::QuantumObject: The Hamiltonian of the system.

  • z::AbstractArray: The initial z matrix of the low-rank algorithm.

  • B::AbstractArray: The initial B matrix of the low-rank algorithm.

  • tlist::AbstractVector: The time steps at which the expectation values and function values are calculated.

  • c_ops::Union{AbstractVector,Tuple}: The list of the collapse operators.

  • e_ops::Union{AbstractVector,Tuple}: The list of the operators for which the expectation values are calculated.

  • f_ops::Union{AbstractVector,Tuple}: The list of the functions for which the function values are calculated.

  • opt::NamedTuple: The options of the low-rank master equation.

  • kwargs: Additional keyword arguments.

source

QuantumToolbox.lr_mesolve Function
julia
lr_mesolve(
    H::QuantumObject{OperatorQuantumObject},
    z::AbstractArray{T,2},
    B::AbstractArray{T,2},
    tlist::AbstractVector,
    c_ops::Union{AbstractVector,Tuple}=();
    e_ops::Union{AbstractVector,Tuple}=(),
    f_ops::Union{AbstractVector,Tuple}=(),
    opt::NamedTuple = lr_mesolve_options_default,
    kwargs...,
)

Time evolution of an open quantum system using the low-rank master equation. For more information about the low-rank master equation, see (Gravina and Savona, 2024).

Arguments

  • H::QuantumObject: The Hamiltonian of the system.

  • z::AbstractArray: The initial z matrix of the low-rank algorithm.

  • B::AbstractArray: The initial B matrix of the low-rank algorithm.

  • tlist::AbstractVector: The time steps at which the expectation values and function values are calculated.

  • c_ops::Union{AbstractVector,Tuple}: The list of the collapse operators.

  • e_ops::Union{AbstractVector,Tuple}: The list of the operators for which the expectation values are calculated.

  • f_ops::Union{AbstractVector,Tuple}: The list of the functions for which the function values are calculated.

  • opt::NamedTuple: The options of the low-rank master equation.

  • kwargs: Additional keyword arguments.

source

Correlations and Spectrum

QuantumToolbox.correlation_3op_2t Function
julia
correlation_3op_2t(H::AbstractQuantumObject,
    ψ0::Union{Nothing,QuantumObject},
    tlist::AbstractVector,
    τlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple},
    A::QuantumObject,
    B::QuantumObject,
    C::QuantumObject;
    kwargs...)

Returns the two-times correlation function of three operators A^, B^ and C^: A^(t)B^(t+τ)C^(t) for a given initial state |ψ0.

If the initial state ψ0 is given as nothing, then the steadystate will be used as the initial state. Note that this is only implemented if H is constant (QuantumObject).

source

QuantumToolbox.correlation_3op_1t Function
julia
correlation_3op_1t(H::AbstractQuantumObject,
    ψ0::Union{Nothing,QuantumObject},
    τlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple},
    A::QuantumObject,
    B::QuantumObject,
    C::QuantumObject;
    kwargs...)

Returns the two-time correlation function (with only one time coordinate τ) of three operators A^, B^ and C^: A^(0)B^(τ)C^(0) for a given initial state |ψ0.

If the initial state ψ0 is given as nothing, then the steadystate will be used as the initial state. Note that this is only implemented if H is constant (QuantumObject).

source

QuantumToolbox.correlation_2op_2t Function
julia
correlation_2op_2t(H::AbstractQuantumObject,
    ψ0::Union{Nothing,QuantumObject},
    tlist::AbstractVector,
    τlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple},
    A::QuantumObject,
    B::QuantumObject;
    reverse::Bool=false,
    kwargs...)

Returns the two-times correlation function of two operators A^ and B^ : A^(t+τ)B^(t) for a given initial state |ψ0.

If the initial state ψ0 is given as nothing, then the steadystate will be used as the initial state. Note that this is only implemented if H is constant (QuantumObject).

When reverse=true, the correlation function is calculated as A^(t)B^(t+τ).

source

QuantumToolbox.correlation_2op_1t Function
julia
correlation_2op_1t(H::AbstractQuantumObject,
    ψ0::Union{Nothing,QuantumObject},
    τlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple},
    A::QuantumObject,
    B::QuantumObject;
    reverse::Bool=false,
    kwargs...)

Returns the two-time correlation function (with only one time coordinate τ) of two operators A^ and B^ : A^(τ)B^(0) for a given initial state |ψ0.

If the initial state ψ0 is given as nothing, then the steadystate will be used as the initial state. Note that this is only implemented if H is constant (QuantumObject).

When reverse=true, the correlation function is calculated as A^(0)B^(τ).

source

QuantumToolbox.spectrum_correlation_fft Function
julia
spectrum_correlation_fft(tlist, corr; inverse=false)

Calculate the power spectrum corresponding to a two-time correlation function using fast Fourier transform (FFT).

Parameters

  • tlist::AbstractVector: List of times at which the two-time correlation function is given.

  • corr::AbstractVector: List of two-time correlations corresponding to the given time point in tlist.

  • inverse::Bool: Whether to use the inverse Fourier transform or not. Default to false.

Returns

  • ωlist: the list of angular frequencies ω.

  • Slist: the list of the power spectrum corresponding to the angular frequencies in ωlist.

source

QuantumToolbox.spectrum Function
julia
spectrum(H::QuantumObject,
    ωlist::AbstractVector,
    c_ops::Union{Nothing,AbstractVector,Tuple},
    A::QuantumObject{OperatorQuantumObject},
    B::QuantumObject{OperatorQuantumObject};
    solver::SpectrumSolver=ExponentialSeries(),
    kwargs...)

Calculate the spectrum of the correlation function

S(ω)=limtA^(t+τ)B^(t)eiωτdτ

See also the following list for SpectrumSolver docstrings:

source

QuantumToolbox.ExponentialSeries Type
julia
ExponentialSeries(; tol = 1e-14, calc_steadystate = false)

A solver which solves spectrum by finding the eigen decomposition of the Liouvillian SuperOperator and calculate the exponential series.

source

QuantumToolbox.PseudoInverse Type
julia
PseudoInverse(; alg::SciMLLinearSolveAlgorithm = KrylovJL_GMRES())

A solver which solves spectrum by finding the inverse of Liouvillian SuperOperator using the algorithms given in LinearSolve.jl.

source

Entropy and Metrics

QuantumToolbox.entropy_vn Function
julia
entropy_vn::QuantumObject; base::Int=0, tol::Real=1e-15)

Calculates the Von Neumann entropy S=Tr[ρ^log(ρ^)], where ρ^ is the density matrix of the system.

Notes

  • ρ is the quantum state, can be either a Ket or an Operator.

  • base specifies the base of the logarithm to use, and when using the default value 0, the natural logarithm is used.

  • tol describes the absolute tolerance for detecting the zero-valued eigenvalues of the density matrix ρ^.

Examples

Pure state:

julia
julia> ψ = fock(2,0)

Quantum Object:   type=Ket   dims=[2]   size=(2,)
2-element Vector{ComplexF64}:
 1.0 + 0.0im
 0.0 + 0.0im

julia> entropy_vn(ψ, base=2)
-0.0

Mixed state:

julia
julia> ρ = maximally_mixed_dm(2)

Quantum Object:   type=Operator   dims=[2]   size=(2, 2)   ishermitian=true
2×2 Diagonal{ComplexF64, Vector{ComplexF64}}:
 0.5-0.0im    
      0.5-0.0im

julia> entropy_vn(ρ, base=2)
1.0

source

QuantumToolbox.entropy_relative Function
julia
entropy_relative::QuantumObject, σ::QuantumObject; base::Int=0, tol::Real=1e-15)

Calculates the quantum relative entropy of ρ^ with respect to σ^: D(ρ^||σ^)=Tr[ρ^log(ρ^)]Tr[ρ^log(σ^)].

Notes

  • ρ is a quantum state, can be either a Ket or an Operator.

  • σ is a quantum state, can be either a Ket or an Operator.

  • base specifies the base of the logarithm to use, and when using the default value 0, the natural logarithm is used.

  • tol describes the absolute tolerance for detecting the zero-valued eigenvalues of the density matrix ρ^.

References

source

QuantumToolbox.entropy_linear Function
julia
entropy_linear::QuantumObject)

Calculates the quantum linear entropy SL=1Tr[ρ^2], where ρ^ is the density matrix of the system.

Note that ρ can be either a Ket or an Operator.

source

QuantumToolbox.entropy_mutual Function
julia
entropy_mutual(ρAB::QuantumObject, selA, selB; kwargs...)

Calculates the quantum mutual information I(A:B)=S(ρ^A)+S(ρ^B)S(ρ^AB) between subsystems A and B.

Here, S is the Von Neumann entropy, ρ^AB is the density matrix of the entire system, ρ^A=TrB[ρ^AB], ρ^B=TrA[ρ^AB].

Notes

  • ρAB can be either a Ket or an Operator.

  • selA specifies the indices of the sub-system A in ρAB.dimensions. See also ptrace.

  • selB specifies the indices of the sub-system B in ρAB.dimensions. See also ptrace.

  • kwargs are the keyword arguments for calculating Von Neumann entropy. See also entropy_vn.

source

QuantumToolbox.entropy_conditional Function
julia
entropy_conditional(ρAB::QuantumObject, selB; kwargs...)

Calculates the conditional quantum entropy with respect to sub-system B: S(A|B)=S(ρ^AB)S(ρ^B).

Here, S is the Von Neumann entropy, ρ^AB is the density matrix of the entire system, and ρ^B=TrA[ρ^AB].

Notes

  • ρAB can be either a Ket or an Operator.

  • selB specifies the indices of the sub-system B in ρAB.dimensions. See also ptrace.

  • kwargs are the keyword arguments for calculating Von Neumann entropy. See also entropy_vn.

source

QuantumToolbox.entanglement Function
julia
entanglement::QuantumObject, sel; kwargs...)

Calculates the entanglement entropy by doing the partial trace of ρ, selecting only the dimensions with the indices contained in the sel vector, and then use the Von Neumann entropy entropy_vn.

Notes

  • ρ can be either a Ket or an Operator. But should be a pure state.

  • sel specifies the indices of the remaining sub-system. See also ptrace.

  • kwargs are the keyword arguments for calculating Von Neumann entropy. See also entropy_vn.

source

QuantumToolbox.concurrence Function
julia
concurrence::QuantumObject)

Calculate the concurrence for a two-qubit state.

Notes

source

QuantumToolbox.negativity Function
julia
negativity::QuantumObject, subsys::Int; logarithmic::Bool=false)

Compute the negativity N(ρ^)=ρ^Γ112 where ρ^Γ is the partial transpose of ρ^ with respect to the subsystem, and X^1=TrX^X^ is the trace norm.

Arguments

  • ρ::QuantumObject: The density matrix (ρ.type must be OperatorQuantumObject).

  • subsys::Int: an index that indicates which subsystem to compute the negativity for.

  • logarithmic::Bool: choose whether to calculate logarithmic negativity or not. Default as false

Returns

  • N::Real: The value of negativity.

Examples

julia
julia> Ψ = bell_state(0, 0)

Quantum Object:   type=Ket   dims=[2, 2]   size=(4,)
4-element Vector{ComplexF64}:
 0.7071067811865475 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im
 0.7071067811865475 + 0.0im

julia> ρ = ket2dm(Ψ)

Quantum Object:   type=Operator   dims=[2, 2]   size=(4, 4)   ishermitian=true
4×4 Matrix{ComplexF64}:
 0.5+0.0im  0.0+0.0im  0.0+0.0im  0.5+0.0im
 0.0+0.0im  0.0+0.0im  0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im  0.0+0.0im  0.0+0.0im
 0.5+0.0im  0.0+0.0im  0.0+0.0im  0.5+0.0im

julia> round(negativity(ρ, 2), digits=2)
0.5

source

QuantumToolbox.fidelity Function
julia
fidelity::QuantumObject, σ::QuantumObject)

Calculate the fidelity of two QuantumObject: F(ρ^,σ^)=Trρ^σ^ρ^

Here, the definition is from Nielsen and Chuang (2012). It is the square root of the fidelity defined in Jozsa (1994).

Note that ρ and σ must be either Ket or Operator.

source

QuantumToolbox.tracedist Function
julia
tracedist::QuantumObject, σ::QuantumObject)

Calculates the trace distance between two QuantumObject: T(ρ^,σ^)=12ρ^σ^1

Note that ρ and σ must be either Ket or Operator.

source

QuantumToolbox.hilbert_dist Function
julia
hilbert_dist::QuantumObject, σ::QuantumObject)

Calculates the Hilbert-Schmidt distance between two QuantumObject: DHS(ρ^,σ^)=Tr[A^A^], where A^=ρ^σ^.

Note that ρ and σ must be either Ket or Operator.

References

source

QuantumToolbox.hellinger_dist Function
julia
hellinger_dist::QuantumObject, σ::QuantumObject)

Calculates the Hellinger distance between two QuantumObject: DH(ρ^,σ^)=22Tr(ρ^σ^)

Note that ρ and σ must be either Ket or Operator.

References

source

QuantumToolbox.bures_dist Function
julia
bures_dist::QuantumObject, σ::QuantumObject)

Calculate the Bures distance between two QuantumObject: DB(ρ^,σ^)=2(1F(ρ^,σ^))

Here, the definition of fidelity F is from Nielsen and Chuang (2012). It is the square root of the fidelity defined in Jozsa (1994).

Note that ρ and σ must be either Ket or Operator.

source

QuantumToolbox.bures_angle Function
julia
bures_angle::QuantumObject, σ::QuantumObject)

Calculate the Bures angle between two QuantumObject: DA(ρ^,σ^)=arccos(F(ρ^,σ^))

Here, the definition of fidelity F is from Nielsen and Chuang (2012). It is the square root of the fidelity defined in Jozsa (1994).

Note that ρ and σ must be either Ket or Operator.

source

Spin Lattice

QuantumToolbox.Lattice Type
julia
Lattice

A Julia constructor for a lattice object. The lattice object is used to define the geometry of the lattice. Nx and Ny are the number of sites in the x and y directions, respectively. N is the total number of sites. lin_idx is a LinearIndices object and car_idx is a CartesianIndices object, and they are used to efficiently select sites on the lattice.

source

QuantumToolbox.multisite_operator Function
julia
multisite_operator(dims::Union{AbstractVector, Tuple}, pairs::Pair{<:Integer,<:QuantumObject}...)

A Julia function for generating a multi-site operator hatO=hatOihatOjcdotshatOk. The function takes a vector of dimensions dims and a list of pairs pairs where the first element of the pair is the site index and the second element is the operator acting on that site.

Arguments

  • dims::Union{AbstractVector, Tuple}: A vector of dimensions of the lattice.

  • pairs::Pair{<:Integer,<:QuantumObject}...: A list of pairs where the first element of the pair is the site index and the second element is the operator acting on that site.

Returns

QuantumObject: A QuantumObject representing the multi-site operator.

Example

julia
julia> op = multisite_operator(Val(8), 5=>sigmax(), 7=>sigmaz());

julia> op.dims
8-element SVector{8, Int64} with indices SOneTo(8):
 2
 2
 2
 2
 2
 2
 2
 2

source

QuantumToolbox.DissipativeIsing Function
julia
DissipativeIsing(Jx::Real, Jy::Real, Jz::Real, hx::Real, hy::Real, hz::Real, γ::Real, latt::Lattice; boundary_condition::Union{Symbol, Val} = Val(:periodic_bc), order::Integer = 1)

A Julia constructor for a dissipative Ising model. The function returns the Hamiltonian

H^=Jx2i,jσ^ixσ^jx+Jy2i,jσ^iyσ^jy+Jz2i,jσ^izσ^jz+hxiσ^ix

and the collapse operators

c^i=γσ^i

Arguments

  • Jx::Real: The coupling constant in the x-direction.

  • Jy::Real: The coupling constant in the y-direction.

  • Jz::Real: The coupling constant in the z-direction.

  • hx::Real: The magnetic field in the x-direction.

  • hy::Real: The magnetic field in the y-direction.

  • hz::Real: The magnetic field in the z-direction.

  • γ::Real: The local dissipation rate.

  • latt::Lattice: A Lattice object that defines the geometry of the lattice.

  • boundary_condition::Union{Symbol, Val}: The boundary conditions of the lattice. The possible inputs are periodic_bc and open_bc, for periodic or open boundary conditions, respectively. The default value is Val(:periodic_bc).

  • order::Integer: The order of the nearest-neighbour sites. The default value is 1.

source

Symmetries and Block Diagonalization

QuantumToolbox.block_diagonal_form Function
julia
block_diagonal_form(A::QuantumObject)

Return the block-diagonal form of a QuantumObject. This is very useful in the presence of symmetries.

Arguments

  • A::QuantumObject: The quantum object.

Returns

The BlockDiagonalForm of A.

source

QuantumToolbox.BlockDiagonalForm Type
julia
struct BlockDiagonalForm

A type for storing a block-diagonal form of a matrix.

Fields

  • B::DT: The block-diagonal matrix. It can be a sparse matrix or a QuantumObject.

  • P::DT: The permutation matrix. It can be a sparse matrix or a QuantumObject.

  • blocks::AbstractVector: The blocks of the block-diagonal matrix.

  • block_sizes::AbstractVector: The sizes of the blocks.

source

Miscellaneous

QuantumToolbox.wigner Function
julia
wigner(
    state::QuantumObject{OpType},
    xvec::AbstractVector,
    yvec::AbstractVector;
    g::Real =2,
    method::WignerSolver = WignerClenshaw(),
)

Generates the Wigner quasipropability distribution of state at points xvec + 1im * yvec in phase space. The g parameter is a scaling factor related to the value of in the commutation relation [x,y]=i via =2/g2 giving the default value =1.

The method parameter can be either WignerLaguerre() or WignerClenshaw(). The former uses the Laguerre polynomial expansion of the Wigner function, while the latter uses the Clenshaw algorithm. The Laguerre expansion is faster for sparse matrices, while the Clenshaw algorithm is faster for dense matrices. The WignerLaguerre method has an optional parallel parameter which defaults to true and uses multithreading to speed up the calculation.

Arguments

  • state::QuantumObject: The quantum state for which the Wigner function is calculated. It can be either a KetQuantumObject, BraQuantumObject, or OperatorQuantumObject.

  • xvec::AbstractVector: The x-coordinates of the phase space grid.

  • yvec::AbstractVector: The y-coordinates of the phase space grid.

  • g::Real: The scaling factor related to the value of in the commutation relation [x,y]=i via =2/g2.

  • method::WignerSolver: The method used to calculate the Wigner function. It can be either WignerLaguerre() or WignerClenshaw(), with WignerClenshaw() as default. The WignerLaguerre method has the optional parallel and tol parameters, with default values true and 1e-14, respectively.

Returns

  • W::Matrix: The Wigner function of the state at the points xvec + 1im * yvec in phase space.

Example

julia
julia> ψ = fock(10, 0) + fock(10, 1) |> normalize

Quantum Object:   type=Ket   dims=[10]   size=(10,)
10-element Vector{ComplexF64}:
 0.7071067811865475 + 0.0im
 0.7071067811865475 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im
                0.0 + 0.0im

julia> xvec = range(-5, 5, 200)
-5.0:0.05025125628140704:5.0

julia> wig = wigner(ψ, xvec, xvec);

or taking advantage of the parallel computation of the WignerLaguerre method

julia
julia> ρ = ket2dm(ψ) |> to_sparse;

julia> wig = wigner(ρ, xvec, xvec, method=WignerLaguerre(parallel=true));

source

Linear Maps

QuantumToolbox.AbstractLinearMap Type
julia
AbstractLinearMap{T, TS}

Represents a general linear map with element type T and size TS.

Overview

A linear map is a transformation L that satisfies:

  • Additivity: math L(u + v) = L(u) + L(v)

  • Homogeneity: math L(cu) = cL(u)

It is typically represented as a matrix with dimensions given by size, and this abstract type helps to define this map when the matrix is not explicitly available.

Methods

  • Base.eltype(A): Returns the element type T.

  • Base.size(A): Returns the size A.size.

  • Base.size(A, i): Returns the i-th dimension.

Example

As an example, we now define the linear map used in the eigsolve_al function for Arnoldi-Lindblad eigenvalue solver:

julia
struct ArnoldiLindbladIntegratorMap{T,TS,TI} <: AbstractLinearMap{T,TS}
    elty::Type{T}
    size::TS
    integrator::TI
end

function LinearAlgebra.mul!(y::AbstractVector, A::ArnoldiLindbladIntegratorMap, x::AbstractVector)
    reinit!(A.integrator, x)
    solve!(A.integrator)
    return copyto!(y, A.integrator.u)
end

where integrator is the ODE integrator for the time-evolution. In this way, we can diagonalize this linear map using the eigsolve function.

source

Utility functions

QuantumToolbox.versioninfo Function
julia
QuantumToolbox.versioninfo(io::IO=stdout)

Command line output of information on QuantumToolbox, dependencies, and system information, same as QuantumToolbox.about.

source

QuantumToolbox.about Function
julia
QuantumToolbox.about(io::IO=stdout)

Command line output of information on QuantumToolbox, dependencies, and system information, same as QuantumToolbox.versioninfo.

source

QuantumToolbox.gaussian Function
julia
gaussian(x::Number, μ::Number, σ::Number)

Returns the gaussian function exp[(xμ)22σ2], where μ and σ2 are the mean and the variance respectively.

source

QuantumToolbox.n_thermal Function
julia
n_thermal::Real, ω_th::Real)

Return the number of photons in thermal equilibrium for an harmonic oscillator mode with frequency ω, at the temperature described by ωthkBT/:

n(ω,ωth)=1eω/ωth1,

where is the reduced Planck constant, and kB is the Boltzmann constant.

source

QuantumToolbox.PhysicalConstants Constant
julia
const PhysicalConstants

A NamedTuple which stores some constant values listed in CODATA recommended values of the fundamental physical constants: 2022

The current stored constants are:

  • c : (exact) speed of light in vacuum with unit [ms1]

  • G : Newtonian constant of gravitation with unit [m3kg1s2]

  • h : (exact) Planck constant with unit [Js]

  • ħ : reduced Planck constant with unit [Js]

  • e : (exact) elementary charge with unit [C]

  • μ0 : vacuum magnetic permeability with unit [NA2]

  • ϵ0 : vacuum electric permittivity with unit [Fm1]

  • k : (exact) Boltzmann constant with unit [JK1]

  • NA : (exact) Avogadro constant with unit [mol1]

Examples

julia
julia> PhysicalConstants.ħ
1.0545718176461565e-34

source

QuantumToolbox.convert_unit Function
julia
convert_unit(value::Real, unit1::Symbol, unit2::Symbol)

Convert the energy value from unit1 to unit2. The unit1 and unit2 can be either the following Symbol:

  • :J : Joule

  • :eV : electron volt

  • :meV : milli-electron volt

  • :MHz : Mega-Hertz multiplied by Planck constant h

  • :GHz : Giga-Hertz multiplied by Planck constant h

  • :K : Kelvin multiplied by Boltzmann constant k

  • :mK : milli-Kelvin multiplied by Boltzmann constant k

Note that we use the values stored in PhysicalConstants to do the conversion.

Examples

julia
julia> convert_unit(1, :eV, :J)
1.602176634e-19

julia> convert_unit(1, :GHz, :J)
6.62607015e-25

julia> round(convert_unit(1, :meV, :mK), digits=4)
11604.5181

source

QuantumToolbox.row_major_reshape Function
julia
row_major_reshape(Q::AbstractArray, shapes...)

Reshapes Q in the row-major order, as numpy.

source

QuantumToolbox.meshgrid Function
julia
meshgrid(x::AbstractVector, y::AbstractVector)

Equivalent to numpy meshgrid.

source

Visualization

QuantumToolbox.plot_wigner Function
julia
plot_wigner(
    state::QuantumObject{OpType}; 
    library::Union{Val,Symbol}=Val(:CairoMakie), 
    kwargs...
) where {OpType<:Union{BraQuantumObject,KetQuantumObject,OperatorQuantumObject}

Plot the Wigner quasipropability distribution of state using the wigner function.

The library keyword argument specifies the plotting library to use, defaulting to CairoMakie.

Arguments

  • state::QuantumObject: The quantum state for which to plot the Wigner distribution.

  • library::Union{Val,Symbol}: The plotting library to use. Default is Val(:CairoMakie).

  • kwargs...: Additional keyword arguments to pass to the plotting function. See the documentation for the specific plotting library for more information.

Import library first

The plotting libraries must first be imported before using them with this function.

Beware of type-stability!

If you want to keep type stability, it is recommended to use Val(:CairoMakie) instead of :CairoMakie as the plotting library. See this link and the related Section about type stability for more details.

source

julia
plot_wigner(
    library::Val{:CairoMakie},
    state::QuantumObject{OpType};
    xvec::Union{Nothing,AbstractVector} = nothing,
    yvec::Union{Nothing,AbstractVector} = nothing,
    g::Real =2,
    method::WignerSolver = WignerClenshaw(),
    projection::Union{Val,Symbol} = Val(:two_dim),
    location::Union{GridPosition,Nothing} = nothing,
    colorbar::Bool = false,
    kwargs...
) where {OpType}

Plot the Wigner quasipropability distribution of state using the CairoMakie plotting library.

Arguments

  • library::Val{:CairoMakie}: The plotting library to use.

  • state::QuantumObject: The quantum state for which the Wigner function is calculated. It can be either a Ket, Bra, or Operator.

  • xvec::AbstractVector: The x-coordinates of the phase space grid. Defaults to a linear range from -7.5 to 7.5 with 200 points.

  • yvec::AbstractVector: The y-coordinates of the phase space grid. Defaults to a linear range from -7.5 to 7.5 with 200 points.

  • g::Real: The scaling factor related to the value of in the commutation relation [x,y]=i via =2/g2.

  • method::WignerSolver: The method used to calculate the Wigner function. It can be either WignerLaguerre() or WignerClenshaw(), with WignerClenshaw() as default. The WignerLaguerre method has the optional parallel and tol parameters, with default values true and 1e-14, respectively.

  • projection::Union{Val,Symbol}: Whether to plot the Wigner function in 2D or 3D. It can be either Val(:two_dim) or Val(:three_dim), with Val(:two_dim) as default.

  • location::Union{GridPosition,Nothing}: The location of the plot in the layout. If nothing, the plot is created in a new figure. Default is nothing.

  • colorbar::Bool: Whether to include a colorbar in the plot. Default is false.

  • kwargs...: Additional keyword arguments to pass to the plotting function.

Returns

  • fig: The figure object.

  • ax: The axis object.

  • hm: Either the heatmap or surface object, depending on the projection.

Import library first

CairoMakie must first be imported before using this function.

Beware of type-stability!

If you want to keep type stability, it is recommended to use Val(:two_dim) and Val(:three_dim) instead of :two_dim and :three_dim, respectively. Also, specify the library as Val(:CairoMakie) See this link and the related Section about type stability for more details.

source