Pauli Algebra

Data types

PauliPropagation.PauliStringType
PauliString(nqubits::Int, pauli::Symbol, qind::Integer, coeff=1.0)
PauliString(nqubits::Int, paulis::Vector{Symbol}, qinds::Vector{Integer}, coeff=1.0)

Constructor for a PauliString on nqubits qubits from a Symbol (:I, :X, :Y, :Z) or Vector{Symbol}. Provide the index or indices for those symbols as qind or qinds. The coefficient of the Pauli string in the Pauli sum defaults to 1.0.

source
PauliPropagation.PauliStringType
PauliString(nqubits::Int, term::TermType, coeff::CoeffType)

PauliString is a struct that represents a Pauli string on nqubits qubits. Commonly term is an unsigned Integer. See the other PauliString constructors for higher-level usage.

source
PauliPropagation.PauliSumType
PauliSum(nqubits::Int, terms::Dict)

PauliSum is a struct that represents a sum of Pauli strings acting on nqubits qubits. It is a wrapper around a dictionary Dict(Pauli string => coefficient}, where the Pauli strings are typically unsigned Integers for efficiency reasons.

source
PauliPropagation.PauliSumMethod
PauliSum(CoeffType, nq::Int)

Contructor for an empty PauliSum on nqubits qubits. The type of the coefficients can be provided.

source
Base.:*Method
*(pstr::PauliString, c::Number)

Multiply a PauliString by a scalar c. Returns a new PauliString.

source
Base.:*Method
*(pstr1::PauliString, pstr2::PauliString)

Perform a Pauli product of two PauliStrings.

source
Base.:*Method
*(psum::PauliSum, c::Number)

Multiply a PauliSum by a scalar c. This copies the PauliSum.

source
Base.:*Method
*(pstr::PauliString, psum::PauliSum)
*(psum::PauliSum, pstr::PauliString)

Perform a Pauli product of a PauliString with a PauliSum. Returns a PauliSum with complex coefficients.

source
Base.:*Method
*(psum1::PauliSum, psum2::PauliSum)

Perform a Pauli product of two PauliSums. Returns a PauliSum with complex coefficients.

source
Base.:+Method
+(psum1::PauliSum, psum2::PauliSum)

Addition of two PauliSums. Returns a PauliSum.

source
Base.:+Method
+(pstr1::PauliString, pstr2::PauliString)

Addition of two PauliStrings. Returns a PauliSum.

source
Base.:+Method
+(pstr::PauliString, psum::PauliSum)
+(psum::PauliSum, pstr::PauliString)

Addition of a PauliString to a PauliSum. Returns a PauliSum.

source
Base.:+Method
+(psum::PauliSum, c::Number)
+(c::Number, psum::PauliSum)

Addition of c * Identity to a PauliSum. This copies the PauliSum.

source
Base.:-Method
-(pstr1::PauliString, pstr2::PauliString)

Subtract two PauliStrings. Returns a PauliSum.

source
Base.:-Method
-(pstr::PauliString, psum::PauliSum)
-(psum::PauliSum, pstr::PauliString)

Subtract a PauliString from a PauliSum or vice versa. Returns a PauliSum.

source
Base.:-Method
-(psum1::PauliSum, psum2::PauliSum)

Subtract two PauliSums. Returns a PauliSum.

source
Base.:/Method
/(pstr::PauliString, c::Number)

Divide a PauliString by a scalar c. Returns a new PauliString.

source
Base.:/Method
/(psum::PauliSum, c::Number)

Divide a PauliSum by a scalar c. This copies the PauliSum.

source
Base.:==Method
==(psum1::PauliSum, psum2::PauliSum)

Equality check for PauliSum.

source
Base.:≈Method
≈(psum1::PauliSum, psum2::PauliSum)

Approximate equality check for PauliSum. Simply calls isapprox() on the coefficients of the contained Pauli strings.

source
Base.empty!Method
empty!(psum::PauliSum)

Empty the PauliSum by emptying the dictionary on the terms fields.

source
Base.iterateFunction

Iterator for PauliSum returns an iterator over (pstr, coeff) pairs`.

source
Base.similarMethod
similar(psum::PauliSum)

Create a new PauliSum with the same number of qubits and coefficient type as psum. Calls sizehint!() with length(psum) on the dictionary of the new PauliSum.

source
Base.sizehint!Method
sizehint!(psum::PauliSum, n)

Hint to the PauliSum to reserve space for n terms.

source
PauliPropagation.add!Function
add!(psum::PauliSum, pauli::Symbol, qind::Integer, coeff=1.0)
add!(psum::PauliSum, paulis::Vector{Symbol}, qinds::Vector{Integer}, coeff=1.0)

Add a Pauli string to a PauliSum psum. Changes psum in-place. Provide the Pauli string as a Symbol (:I, :X, :Y, :Z) or Vector{Symbol}. Provide the index or indices for those symbols as qind or qinds. The coefficient of the Pauli string in the Pauli sum defaults to 1.0.

source
PauliPropagation.add!Method
add!(psum::PauliSum, pstr::PauliString)

Add a PauliString pstr to a PauliSum psum. Changes psum in-place. psum and pstr need to be defined on the same number of qubits and have the same coefficient type.

source
PauliPropagation.add!Method
add!(psum1::PauliSum, psum2::PauliSum)

Add two PauliSums psum1 and psum2. Changes psum1 in-place. psum1 and psum2 need to be defined on the same number of qubits and have the same coefficient type.

source
PauliPropagation.add!Method
add!(psum::PauliSum{Integer, CoeffType}, pstr::Integer, coeff::CoeffType)

Add a Pauli string pstr with coefficient coeff to a PauliSum psum. This changes psum in-place. pstr needs to have the same type as paulitype(psum), and coeff needs to have the same type as coefftype(psum).

source
PauliPropagation.coefficientsMethod
coefficients(psum::PauliSum)

Returns an iterator over the coefficients of a PauliSum. Call topaulistrings to receive entries as PauliStrings.

source
PauliPropagation.getcoeffMethod
getcoeff(psum::PauliSum, pstr::Vector{Symbol}, qinds::Vector{Int})

Get the coefficient of a Pauli string in a PauliSum by providing the Pauli string pstr as a vector of Symbols acting on qubits qinds. This is consistent with how Pauli strings can be added to a PauliSum via add!(). Defaults to 0 if the Pauli string is not in the PauliSum.

source
PauliPropagation.getcoeffMethod
getcoeff(psum::PauliSum, pauli::Symbol, qind::Integer)

Get the coefficient of a Pauli string in a PauliSum by providing the Pauli string as a Symbol acting on qubit qind. This is consistent with how Pauli strings can be added to a PauliSum via add!(). Defaults to 0 if the Pauli string is not in the PauliSum.

source
PauliPropagation.getcoeffMethod
getcoeff(psum::PauliSum, pstr::Vector{Symbol})

Get the coefficient of a Pauli string in a PauliSum by providing the Pauli string pstr as a vector of Symbols acting on all qubits. This is consistent with how Pauli strings can be added to a PauliSum via add!(). Defaults to 0 if the Pauli string is not in the PauliSum.

source
PauliPropagation.getcoeffMethod
getcoeff(psum::PauliSum, pstr::PauliString)

Get the coefficient of a PauliString in a PauliSum. Defaults to 0 if the Pauli string is not in the PauliSum. Requires that the integer Pauli string in pstr is the same type as the integer Pauli strings in psum.

source
PauliPropagation.getcoeffMethod
getcoeff(psum::PauliSum, pstr::Integer)

Get the coefficient of an integer Pauli string in a PauliSum. Defaults to 0 if the Pauli string is not in the PauliSum. Requires that the integer Pauli string pstr is the same type as the integer Pauli strings in psum.

source
PauliPropagation.normFunction
norm(psum::PauliSum, L=2)

Calculate the norm of a PauliSum with respect to the L-norm. Calls LinearAlgebra.norm on the coefficients of the PauliSum.

source
PauliPropagation.numcoefftypeMethod
numcoefftype(pstr::PauliString)

Get the type of the numerical coefficient of a PauliString. Will return the type of the output of tonumber(pstr.coeff).

source
PauliPropagation.numcoefftypeMethod
numcoefftype(psum::PauliSum)

Get the type of the numerical coefficient of a PauliSum by calling numcoefftype() on the coefficients. If the PauliSum is empty, an error is thrown because the type cannot be inferred.

source
PauliPropagation.paulisMethod
paulis(psum::PauliSum)

Returns an iterator over the integer pauli strings of a PauliSum. Call topaulistrings to receive entries as PauliStrings.

source
PauliPropagation.set!Method
set!(psum::PauliSum{TermType, CoeffType}, pstr::TermType, coeff::CoeffType)

In-place setting the coefficient of a Pauli string in a PauliSum dictionary. The type of the Pauli string needs to be the keytype=TermType of the dictionary, and the coefficient coeff needs to be the valuetype=CoeffType.

source
PauliPropagation.tonumberMethod
tonumber(val::Number)

Trivial function returning a numerical value of a number. Will be overloaded for custom wrapper types like PathProperties.

source

Pauli operations

PauliPropagation.commutatorMethod
commutator(pstr1::Integer, pstr2::Integer)

Calculate the commutator of two integer Pauli strings. Returns a tuple of the coefficient and the potentially integer Pauli string. The coefficient is zero if the Pauli strings commute.

source
PauliPropagation.commutatorMethod
commutator(psum::PauliSum, pstr::PauliString)
commutator(pstr::PauliString, psum::PauliSum)

Calculate the commutator of a PauliSum and a PauliString.

source
PauliPropagation.countxyMethod
countxy(psum::PauliSum)

Function to count the number of X and Y Paulis in a PauliSum. Returns an array of counts.

source
PauliPropagation.countyzMethod
countyz(psum::PauliSum)

Function to count the number of Y and Z Paulis in a PauliSum. Returns an array of counts.

source

Bit operations

PauliPropagation.getinttypeMethod
getinttype(nqubits::Integer)

Function to return the smallest integer type that can hold nqubits. This is the type that will be used internally for representing Pauli strings.

source

Utils

PauliPropagation.getpauliMethod
getpauli(pstr::PauliStringType, qinds::Vector{Integer})

Gets the Paulis on indices qinds of a pstr in the integer representation.

source
PauliPropagation.inttostringMethod
inttostring(pstr::PauliType, nqubits::Integer)

Returns a string representation of an integer Pauli string pstr on nqubits qubits. The characters of the string from left to right are the Paulis on the qubits from 1 to nqubits.

source
PauliPropagation.ispauliMethod
ispauli(pauli1::Union{Symbol, PauliType}, pauli2::Union{Symbol, PauliType})

ispauli(pauli1::Union{Vector{Symbol}, PauliStringType}, pauli2::Union{Vector{Symbol}, PauliStringType})

Check if two Paulis are equal, where one is given as a symbol and the other as an integer.

source
PauliPropagation.setpauliMethod
setpauli(
    pstr::PauliStringType, 
    target_paulis::Vector{Symbol}, 
    qinds::Vector{Integer}
)

Set the Paulis qinds of an integer Pauli string pstr to target_paulis. target_paulis is a vector of symbols. Use tuples in performance critical functions because they are immutable.

source
PauliPropagation.setpauliMethod
setpauli(
    pstr::PauliStringType, 
    target_paulis::PauliStringType, 
    qinds::Vector{Integer}
)

Set the Paulis qinds of an integer Pauli string pstr to target_paulis. Use Tuples for qinds in performance critical functions because they are immutable.

source
PauliPropagation.setpauliMethod
setpauli(pstr::PauliStringType, target_pauli::PauliType, index::Integer)

Sets the Pauli on index index of an integer Pauli string to target_pauli. That Pauli should be provided as integer (0, 1, 2, 3).

source
PauliPropagation.setpauliMethod
setpauli(pstr::PauliStringType, target_pauli::Symbol, index::Integer)

Sets the Pauli on index of an integer Pauli string to target_pauli. That Pauli should be provided as a symbol (:I, :X, :Y, :Z).

source
PauliPropagation.symboltointMethod
symboltoint(pstr::Union{Vector{Symbol}, Symbol})

Maps a symbol or a vector of symbols pstr to an integer Pauli string.

Example:

symboltoint([:X, :I])
>>> 0x01
source
PauliPropagation.symboltointMethod
symboltoint(nqubits::Integer, paulis::Vector{Symbol}, qinds::Vector{Int})

Maps a vector of symbols pstr acting on the indices qinds to an integer Pauli string. Other sites are set to the identity. qinds can be any iterable.

source
PauliPropagation.symboltointMethod
symboltoint(nqubits::Integer, pauli::Symbol, qind::Integer)

Maps a single symbol pauli acting on the index qind to an integer Pauli string. Other sites are set to the identity.

source
PauliPropagation.symboltointMethod
symboltoint(::PauliStringType, paulis, qinds)

Maps a vector of symbols paulis acting on the indices qinds to an integer Pauli string with type PauliStringType. Other sites are set to the identity. qinds can be any iterable.

source
PauliPropagation.symboltointMethod
symboltoint(::PauliStringType, pauli::Symbol, qind::Integer)

Maps a single symbol pauli acting on the index qind to an integer Pauli string with type PauliStringType. Other sites are set to the identity.

source