Documentation

Basics

PauliStrings.OperatorTS1DMethod
OperatorTS1D(o::Operator; full=true)

Initialize a 1D translation invariant operator from an Operator $O=\sum_i o_i O_i$ where $O_i=T_i(O_0)$ and $T_i$ is the i-sites translation operator.
Set full=true if passing $O$, an Operator that is supported on the whole chain (i.e converting from a translation symmetric Operator)
Set full=false if passing $O_0$,a local term o such that the full operator is $O=\sum_i o_i T_i(O_0)$

source
Base.lengthMethod
Base.length(o::Operator)
Base.length(o::OperatorTS1D)

Number of pauli strings in an operator

Example

julia> A = Operator(4)
julia> A += "X111"
julia> A += "XYZ1"
julia> A += 2, "Y", 4
julia> length(A)
3
source
Base.:+Method
Base.:+(o::Operator, args::Tuple{Number, Vararg{Any}})
Base.:+(o::Operator, args::Tuple{Vararg{Any}})
Base.:+(o::Operator, term::Tuple{Number, String})
Base.:+(o::Operator, term::String)

Main functions to contruct spin operators. Identical signatures are available for -.

Examples

k-local terms can be added by adding a tuple to the operator. The first element of the tuple is an optional coeficient. The other element are couples (symbol,site) where symbol can be "X", "Y", "Z", "Sx", "Sy", "Sz", "S+", "S-" and site is an integer specifying the site on wich the symbol is acting.

A = Operator(4)
A += 2, "X",1,"X",2
A += 3, "Y",1,"X",2
A += "X",3,"X",4
A += 4,"Z",3
A += 5.2,"X",1,"Y",2,"Z",3
julia> A
(4.0 + 0.0im) 11Z1
(3.0 - 0.0im) YX11
(1.0 + 0.0im) 11XX
(2.0 + 0.0im) XX11
(5.2 - 0.0im) XYZ1

Full strings can also be added:

A = Operator(4)
A += 2, "1XXY"
A += 2im, "11Z1"
julia> A
(0.0 + 2.0im) 11Z1
(2.0 - 0.0im) 1XXY
source
Base.:+Method
+(x, y...)

Addition operator. x+y+z+... calls this function with all arguments, i.e. +(x, y, z, ...).

Examples

julia> 1 + 20 + 4
25

julia> +(1, 20, 4)
25
source
Base.:+Method
+(x, y...)

Addition operator. x+y+z+... calls this function with all arguments, i.e. +(x, y, z, ...).

Examples

julia> 1 + 20 + 4
25

julia> +(1, 20, 4)
25
source
Base.:+(o::Operator, args::Tuple{Number, Vararg{Any}})
Base.:+(o::Operator, args::Tuple{Vararg{Any}})
Base.:+(o::Operator, term::Tuple{Number, String})
Base.:+(o::Operator, term::String)

Main functions to contruct spin operators. Identical signatures are available for -.

Examples

k-local terms can be added by adding a tuple to the operator. The first element of the tuple is an optional coeficient. The other element are couples (symbol,site) where symbol can be "X", "Y", "Z", "Sx", "Sy", "Sz", "S+", "S-" and site is an integer specifying the site on wich the symbol is acting.

A = Operator(4)
A += 2, "X",1,"X",2
A += 3, "Y",1,"X",2
A += "X",3,"X",4
A += 4,"Z",3
A += 5.2,"X",1,"Y",2,"Z",3
julia> A
(4.0 + 0.0im) 11Z1
(3.0 - 0.0im) YX11
(1.0 + 0.0im) 11XX
(2.0 + 0.0im) XX11
(5.2 - 0.0im) XYZ1

Full strings can also be added:

A = Operator(4)
A += 2, "1XXY"
A += 2im, "11Z1"
julia> A
(0.0 + 2.0im) 11Z1
(2.0 - 0.0im) 1XXY
source
Base.:+Method
+(x, y...)

Addition operator. x+y+z+... calls this function with all arguments, i.e. +(x, y, z, ...).

Examples

julia> 1 + 20 + 4
25

julia> +(1, 20, 4)
25
source

Operations

PauliStrings.addMethod
add(o1::Operator, o2::Operator)
Base.:+(o1::Operator, o2::Operator)
Base.:+(o::Operator, a::Number)
Base.:+(a::Number, o::Operator)

Add two operators together or add a number to an operator

Example

A = Operator(4)
A += "XYZ1"
A += 1, "Y", 4
B = Operator(4)
B += 2, "Y", 2, "Y", 4
B += 1, "Z", 3
julia> A
(1.0 - 0.0im) 111Y
(1.0 - 0.0im) XYZ1

julia> B
(1.0 + 0.0im) 11Z1
(2.0 - 0.0im) 1Y1Y

julia> A+B
(1.0 + 0.0im) 11Z1
(2.0 - 0.0im) 1Y1Y
(1.0 - 0.0im) 111Y
(1.0 - 0.0im) XYZ1

julia> A+5
(1.0 - 0.0im) 111Y
(1.0 - 0.0im) XYZ1
(5.0 + 0.0im) 1111
source
Base.:+Method
+(x, y...)

Addition operator. x+y+z+... calls this function with all arguments, i.e. +(x, y, z, ...).

Examples

julia> 1 + 20 + 4
25

julia> +(1, 20, 4)
25
source
Base.:+Method
+(x, y...)

Addition operator. x+y+z+... calls this function with all arguments, i.e. +(x, y, z, ...).

Examples

julia> 1 + 20 + 4
25

julia> +(1, 20, 4)
25
source
Base.:+Method
+(x, y...)

Addition operator. x+y+z+... calls this function with all arguments, i.e. +(x, y, z, ...).

Examples

julia> 1 + 20 + 4
25

julia> +(1, 20, 4)
25
source
Base.:*Method
Base.:*(o1::Operator, o2::Operator)
Base.:*(o::Operator, a::Number)
Base.:*(a::Number, o::Operator)

Multiply two operators together or an operator with a number

Example

A = Operator(4)
A += "XYZ1"
A += 1, "Y", 4
B = Operator(4)
B += 2, "Y", 2, "Y", 4
B += 1, "Z", 3
julia> A
(1.0 - 0.0im) 111Y
(1.0 - 0.0im) XYZ1


julia> B
(1.0 + 0.0im) 11Z1
(2.0 - 0.0im) 1Y1Y

julia> A*B
(2.0 - 0.0im) X1ZY
(1.0 - 0.0im) 11ZY
(2.0 - 0.0im) 1Y11
(1.0 - 0.0im) XY11

julia> A*5
(5.0 - 0.0im) 111Y
(5.0 - 0.0im) XYZ1
source
Base.:*Method
*(x, y...)

Multiplication operator. x*y*z*... calls this function with all arguments, i.e. *(x, y, z, ...).

Examples

julia> 2 * 7 * 8
112

julia> *(2, 7, 8)
112
source
Base.:*Method
*(x, y...)

Multiplication operator. x*y*z*... calls this function with all arguments, i.e. *(x, y, z, ...).

Examples

julia> 2 * 7 * 8
112

julia> *(2, 7, 8)
112
source
Base.:-Method
Base.:-(o::Operator)
Base.:-(o1::Operator, o2::Operator)
Base.:-(o::Operator, a::Real)
Base.:-(a::Real, o::Operator)

Subtraction between operators and numbers

source
Base.:-Method
-(x, y)

Subtraction operator.

Examples

julia> 2 - 3
-1

julia> -(2, 4.5)
-2.5
source
Base.:-Method
-(x, y)

Subtraction operator.

Examples

julia> 2 - 3
-1

julia> -(2, 4.5)
-2.5
source
Base.:-Method
-(x, y)

Subtraction operator.

Examples

julia> 2 - 3
-1

julia> -(2, 4.5)
-2.5
source
PauliStrings.comMethod
com(o1::Operator, o2::Operator; epsilon::Real=0, maxlength::Int=1000)
com(o1::OperatorTS1D, o2::OperatorTS1D; anti=false)

Commutator of two operators. Set anti=true to compute the anti-commutator.

Example

julia> A = Operator(4)
julia> A += "X111"
julia> B = Operator(4)
julia> B += "Z111"
julia> B += "XYZ1"
julia> com(A,B)
(0.0 - 2.0im) Y111
source
PauliStrings.diagMethod
diag(o::Operator)
diag(o::OperatorTS1D)

Diagonal of an operator. Keep the strings that only contain 1's or Z's. Return another operator.

Example

julia> A = Operator(4)
julia> A += 2,"1111"
julia> A += 3,"XYZ1"
julia> A += 3,"Z11Z"
julia> diag(A)
(2.0 + 0.0im) 1111
(3.0 + 0.0im) Z11Z
source
PauliStrings.traceMethod
trace(o::Operator)
trace(o::OperatorTS1D)

Trace of an operator

Example

julia> A = Operator(4)
julia> A += 2,"1111"
julia> A += 3,"XYZ1"
julia> trace(A)
32.0 + 0.0im
source
PauliStrings.opnormMethod
opnorm(o::Operator)
opnorm(o::OperatorTS1D)

Frobenius norm

Example

julia> A = Operator(4)
julia> A += 2,"X",2
julia> A += 1,"Z",1,"Z",3
julia> opnorm(A)
8.94427190999916
source
PauliStrings.daggerMethod
dagger(o::Operator)
dagger(o::OperatorTS1D)

Conjugate transpose

Example

A = Operator(3)
A += 1im,"X",2
A += 1,"Z",1,"Z",3
julia> A

(1.0 + 0.0im) Z1Z
(0.0 + 1.0im) 1X1


julia> dagger(A)
(1.0 - 0.0im) Z1Z
(0.0 - 1.0im) 1X1
source
PauliStrings.ptraceMethod
ptrace(o::Operator, keep::Vector{Int})

Partial trace.

keep is list of qubits indices to keep starting at 1 note that this still returns an operator of size N and doesnt permute the qubits this only gets rid of Pauli strings that have no support on keep and add their coeficient*2^N to the identity string

Example

A = Operator(5)
A += "XY1XZ"
A += "XY11Z"
julia> ptrace(A, [3,4])
(1.0 - 0.0im) XY1XZ
(8.0 - 0.0im) 11111

julia> ptrace(A, [1,5])
(1.0 - 0.0im) XY1XZ
(1.0 - 0.0im) XY11Z
source

Power and moments

Base.:^Method
Base.:^(o::Operator, k::Int)

kth power of o. Same as oppow.

source
PauliStrings.trace_productMethod
trace_product(o1::Operator, o2::Operator; scale=0)
trace_product(o1::OperatorTS1D, o2::OperatorTS1D; scale=0)

Efficiently compute trace(o1*o2). This is much faster than doing trace(o1*o2). If scale is not 0, then the result is normalized such that trace(identity)=scale.

source
PauliStrings.trace_productMethod
trace_product(A::Operator, k::Int, B::Operator, l::Int; scale=0)
trace_product(A::OperatorTS1D, k::Int, B::OperatorTS1D, l::Int; scale=0)

Efficiently compute trace(A^k*B^l). This is much faster than doing trace(A^k*B^l).

If scale is not 0, then the result is normalized such that trace(identity)=scale.

source
PauliStrings.trace_productMethod
trace_product(A::Operator, k::Int; scale=0)

Efficiently compute trace(A^k). This is much faster than doing trace(A^k).

If scale is not 0, then the result is normalized such that trace(identity)=scale.

source
PauliStrings.momentsMethod
moments(H::Operator, kmax::Int; start=1, scale=0)
moments(H::OperatorTS1D, kmax::Int; start=1, scale=0)

Compute the first kmax moments of H. start is the first moment to start from.

If scale is not 0, then the result is normalized such that trace(identity)=scale.

source

Random operators

Truncation and noise

Base.truncateMethod
truncate(o::Operator, N::Int; keepnorm::Bool = false)

Remove all terms of length > N. Keep all terms of length <= N. i.e remove all M-local terms with M>N

Example

A = Operator(4)
A += "X",1,"X",2
A += "Z",1,"Z",2,"Z",4
julia> A
(1.0 + 0.0im) ZZ1Z
(1.0 + 0.0im) XX11

julia> ps.truncate(A,2)
(1.0 + 0.0im) XX11
source
PauliStrings.trimMethod
trim(o::Operator, N::Int; keepnorm::Bool = false, keep::Operator=Operator(N))

Keep the first N terms with largest coeficients.

keepnorm is set to true to keep the norm of o.

keep is an operator that specify a set of strings that cannot be removed

Example

A = Operator(4)
A += 1,"XXXX"
A += 2,"XX11"
A += 3,"XX1X"
A += 4,"ZZXX"
B = Operator(4)
B += 1,"XX11"
B += 1,"XX1X"
julia> trim(A,2)
(4.0 + 0.0im) ZZXX
(3.0 + 0.0im) XX1X

julia> trim(A,2;keep=B)
(4.0 + 0.0im) ZZXX
(3.0 + 0.0im) XX1X
(2.0 + 0.0im) XX11
source
PauliStrings.pruneMethod
 prune(o::Operator, alpha::Real; keepnorm::Bool = false)

Keep terms with probability 1-exp(-alpha*abs(c)) where c is the weight of the term

source
PauliStrings.cutoffMethod
cutoff(o::Operator, epsilon::Real; keepnorm::Bool = false)

Remove all terms with weight < epsilon

Example

A = Operator(4)
A += 1,"XXXX"
A += 2,"XX11"
A += 3,"XX1X"
A += 4,"ZZXX"
julia> cutoff(A, 2.5)
(3.0 + 0.0im) XX1X
(4.0 + 0.0im) ZZXX
source
PauliStrings.k_local_partMethod
k_local_part(o::Operator, k::Int)

Return the k-local part of o. I.e all the strings of lenght k.

Example

A = Operator(4)
A += "X",1,"X",2
A += "Z",1,"Z",2,"Z",4
A += "1X11"
julia> A
(1.0 + 0.0im) ZZ1Z
(1.0 + 0.0im) 1X11
(1.0 + 0.0im) XX11

julia> k_local_part(A,2)
(1.0 + 0.0im) XX11
source

Algorithms

PauliStrings.lanczosMethod
lanczos(H::Operator, O::Operator, steps::Int, nterms::Int; keepnorm=true, maxlength=1000)
lanczos(H::OperatorTS1D, O::OperatorTS1D, steps::Int, nterms::Int; keepnorm=true, maxlength=1000)

Computer the first steps lanczos coeficients for Hamiltonian H and initial operator O

At every step, the operator is trimed with trim and only nterms are kept.

Using maxlength speeds up the commutator by only keeping terms of length <= maxlength

source
PauliStrings.lanczosMethod
lanczos(H::Operator, O::Operator, steps::Int, nterms::Int; keepnorm=true, maxlength=1000)
lanczos(H::OperatorTS1D, O::OperatorTS1D, steps::Int, nterms::Int; keepnorm=true, maxlength=1000)

Computer the first steps lanczos coeficients for Hamiltonian H and initial operator O

At every step, the operator is trimed with trim and only nterms are kept.

Using maxlength speeds up the commutator by only keeping terms of length <= maxlength

source
PauliStrings.rk4Method
rk4(H::Operator, O::Operator, dt::Real; hbar::Real=1, heisenberg=false, M=2^20, keep::Operator=Operator(N))

Single step of Runge–Kutta-4 with time independant Hamiltonian. Returns O(t+dt). Set heisenberg=true for evolving an observable in the heisenberg picture. If heisenberg=false then it is assumed that O is a density matrix.

source
PauliStrings.rk4Method
rk4(H::Function, O::Operator, dt::Real, t::Real; hbar::Real=1, heisenberg=false)

Single step of Runge–Kutta-4 with time dependant Hamiltonian. H is a function that takes a number (time) and returns an operator.

source

Construction

PauliStrings.all_k_localMethod
all_k_local(N::Int, k::Int)

Return the sum of all the k-local strings supported on N spins, with coeficients 1. These are k-local only strings, not including strings shorter than k.

julia> all_k_local(2, 1)
(1.0 + 0.0im) X1
(1.0 + 0.0im) 1X
(1.0 + 0.0im) Z1
(1.0 - 0.0im) Y1
(1.0 + 0.0im) 1Z
(1.0 - 0.0im) 1Y
source
PauliStrings.all_xMethod
all_x(N::Int)

Return the sum of all the strings supported on N spins with only x and with coeficients 1

julia> all_x(2)
(1.0 + 0.0im) 11
(1.0 + 0.0im) X1
(1.0 + 0.0im) 1X
(1.0 + 0.0im) XX
source
PauliStrings.all_yMethod
all_y(N::Int)

Return the sum of all the strings supported on N spins with only y and with coeficients 1

julia> all_y(2)
(1.0 + 0.0im) 11
(1.0 - 0.0im) Y1
(1.0 - 0.0im) 1Y
(1.0 - 0.0im) YY
source
PauliStrings.all_zMethod
all_z(N::Int)

Return the sum of all the strings supported on N spins with only z and with coeficients 1

julia> all_z(2)
(1.0 + 0.0im) 11
(1.0 + 0.0im) Z1
(1.0 + 0.0im) 1Z
(1.0 + 0.0im) ZZ
source
PauliStrings.set_coefsMethod
set_coefs(o::Operator, coefs::Vector{T}) where T <: Number

Sets the coeficient of o to coefs. Inplace.

A = Operator(4)
A += 2, "1XXY"
A += 3, "11Z1"
julia> A
(3.0 + 0.0im) 11Z1
(2.0 - 0.0im) 1XXY
julia> set_coefs(A, [5,6])
julia> A
(5.0 + 0.0im) 11Z1
(6.0 - 0.0im) 1XXY
source

Tools

PauliStrings.compressMethod
compress(o::Operator)
compress(o::OperatorTS1D)

Accumulate repeated terms and remove terms with a coeficient smaller than 1e-20

source
PauliStrings.op_to_stringsMethod
op_to_strings(o::Operator)

takes an operator, return (coefs, strings) where coefs is a list of numbers and strings is a list of pauli string coefs[i] multiply strings[i]

source
PauliStrings.shift_leftMethod
shift_left(O::Operator)

Shift evey string left so they start on site 1. This usefull for using translation symmetry in 1D systems

Example

A = Operator(4)
A += "XYZ1"
A += "11ZZ"
A += "1XZY"
A += "ZZ11"
julia> shift_left(A)
(1.0 - 0.0im) XZY1
(1.0 - 0.0im) XYZ1
(2.0 + 0.0im) ZZ11
source

Index