Pauli Algebra
Data types
PauliPropagation.PauliString — TypePauliString(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.
PauliPropagation.PauliString — TypePauliString(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.
PauliPropagation.PauliSum — TypePauliSum(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.
PauliPropagation.PauliSum — MethodPauliSum(nqubits::Integer)Contructor for an empty PauliSum on nqubits qubits. Element type defaults for Float64.
PauliPropagation.PauliSum — MethodPauliSum(pstr::PauliString)Constructor for a PauliSum on nqubits qubits from a PauliString.
PauliPropagation.PauliSum — MethodPauliSum(pstrs::Vector{PauliString})Constructor for a PauliSum on nqubits qubits from a PauliString.
PauliPropagation.PauliSum — MethodPauliSum(nqubits::Integer, psum::Dict{Vector{Symbol},CoeffType})Constructor for a PauliSum on nqubits qubits from a dictionary of {Vector{Symbols} => coefficients}.
PauliPropagation.PauliSum — MethodPauliSum(nq::Int, COEFFTYPE)Contructor for an empty PauliSum on nqubits qubits. The type of the coefficients can be provided.
PauliPropagation.PauliSum — MethodPauliSum(nq::Integer, pstr::PauliString)Constructor for a PauliSum on nqubits qubits from a PauliString.
Base.:* — Method*(psum::PauliSum, c::Number)Multiply a PauliSum by a scalar c. This copies the PauliSum.
Base.:+ — Method+(pstr1::PauliString{TermType,CoeffType}, pstr2::PauliString{TermType,CoeffType})Addition of two PauliStrings. Returns a PauliSum.
Base.:+ — Method+(psum1::PauliSum, c::Number)Addition of c * Identity to a PauliSum. This copies the PauliSum.
Base.:+ — Method+(psum::PauliSum{TermType,CoeffType}, pstr::PauliString{TermType,CoeffType})Addition of a PauliString to a PauliSum. Returns a PauliSum.
Base.:+ — Method+(psum1::PauliSum{TermType,CoeffType}, psum2::PauliSum{TermType,CoeffType})Addition of two PauliSums. Returns a PauliSum.
Base.:- — Method-(pstr1::PauliString{TermType,CoeffType}, pstr2::PauliString{TermType,CoeffType})Subtract two PauliStrings. Returns a PauliSum.
Base.:- — Method-(psum::PauliSum{TermType,CoeffType}, pstr::PauliString{TermType,CoeffType})Subtract a PauliString to a PauliSum. Returns a PauliSum.
Base.:- — Method-(psum1::PauliSum{TermType,CoeffType}, psum2::PauliSum{TermType,CoeffType})Subtract two PauliSums. Returns a PauliSum.
Base.:/ — Method/(psum::PauliSum, c::Number)Divide a PauliSum by a scalar c. This copies the PauliSum.
Base.:== — Method==(psum1::PauliSum, psum2::PauliSum)Equality check for PauliSum.
Base.:≈ — Method≈(psum1::PauliSum, psum2::PauliSum)Approximate equality check for PauliSum.
Base.copy — MethodCopy a PauliSum by copying its terms field.
Base.delete! — Methoddelete!(psum::PauliSum{TermType, CoeffType}, pstr::TermType)Delete a Pauli string from a PauliSum. 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.
Base.empty! — Methodempty!(psum::PauliSum)Empty the PauliSum by emptying the dictionary on the terms fields.
Base.iterate — FunctionIterator for PauliSum returns the iterator over its terms.
Base.length — Methodlength(psum::PauliSum)Number of terms in the PauliSum.
Base.show — MethodPretty print for PauliString.
Base.show — MethodPretty print for PauliSum.
PauliPropagation._checknumberofqubits — MethodChecks whether the number of qubits nqubits is the same between as the length of the vector pstr.
PauliPropagation._checknumberofqubits — MethodChecks whether the number of qubits nqubits is the same between our datatypes.
PauliPropagation._checknumberofqubits — MethodChecks whether the number of qubits nqubits is the same between our datatypes.
PauliPropagation._checknumberofqubits — MethodChecks whether the number of qubits nqubits is the same between in some collection.
PauliPropagation.add! — Functionadd!(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.
PauliPropagation.add! — Methodadd!(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.
PauliPropagation.add! — Methodadd!(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.
PauliPropagation.add! — Methodadd!(psum::PauliSum{TermType, CoeffType}, pstr::TermType, 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).
PauliPropagation.coefficients — Methodcoefficients(psum::PauliSum)Returns an iterator over the coefficients of a PauliSum. Call topaulistrings to receive entries as PauliStrings.
PauliPropagation.coefftype — Methodcoefftype(pstr::PauliString)Get the coefficient type of a PauliString.
PauliPropagation.coefftype — Methodcoefftype(psum::PauliSum)Get the coefficient type of a PauliSum.
PauliPropagation.getcoeff — Methodgetcoeff(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.
PauliPropagation.getcoeff — Methodgetcoeff(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.
PauliPropagation.getcoeff — Methodgetcoeff(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.
PauliPropagation.getcoeff — Methodgetcoeff(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.
PauliPropagation.getcoeff — Methodgetcoeff(psum::PauliSum{PauliStringType,CoeffType}, pstr::PauliStringType)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.
PauliPropagation.mult! — Methodmult!(psum::PauliSum, c::Number)Multiply a PauliSum by a scalar c in-place.
PauliPropagation.norm — Functionnorm(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.
PauliPropagation.numcoefftype — Methodnumcoefftype(pstr::PauliString)Get the type of the numerical coefficient of a PauliString. Will return the type of the output of tonumber(pstr.coeff).
PauliPropagation.numcoefftype — Methodnumcoefftype(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.
PauliPropagation.paulis — Methodpaulis(psum::PauliSum)Returns an iterator over the integer pauli strings of a PauliSum. Call topaulistrings to receive entries as PauliStrings.
PauliPropagation.paulitype — Methodpaulitype(pstr::PauliString)Get the Pauli integer type of a PauliString.
PauliPropagation.paulitype — Methodpaulitype(psum::PauliSum)Get the Pauli integer type of a PauliSum.
PauliPropagation.set! — Methodset!(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.
PauliPropagation.similar — Methodsimilar(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.
PauliPropagation.tonumber — Methodtonumber(val::Number)Trivial function returning a numerical value of a number. Will be overloaded for custom wrapper types like PathProperties.
PauliPropagation.topaulistrings — Methodtopaulistrings(psum::PauliSum)Returns the Pauli strings in a PauliSum and their coefficients as a list of PauliString.
Pauli operations
PauliPropagation.calculatesign — Methodcalculatesign(pauli1::PauliStringType, pauli2::PauliStringType, pauli3::PauliStringType, changed_indices)Calculate the sign of the product of two integer Pauli strings. Outcomes are either ±1 or ±i. Takes the product of the Paulis as argument for efficiency. Indicate via changed_indices which qubit sites to check. It can be any iterable.
PauliPropagation.calculatesign — Methodcalculatesign(pauli1::PauliStringType, pauli2::PauliStringType, pauli3::PauliStringType)Calculate the sign of the product of two integer Pauli strings. Outcomes are either ±1 or ±i. Takes the product of the Paulis pauli3 as argument for efficiency.
PauliPropagation.calculatesign — Methodcalculatesign(pauli1::PauliStringType, pauli2::PauliStringType)Calculate the sign of the product of two integer Pauli strings. Outcomes are either ±1 or ±i.
PauliPropagation.commutator — Methodcommutator(pstr1::PauliStringType, pstr2::PauliStringType)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.
PauliPropagation.commutator — Methodcommutator(pstr1::PauliString, pstr2::PauliString)Calculate the commutator of two PauliStrings.
PauliPropagation.commutator — Methodcommutator(psum::PauliSum, pstr::PauliString)
commutator(pstr::PauliString, psum::PauliSum)Calculate the commutator of a PauliSum and a PauliString.
PauliPropagation.commutator — Methodcommutator(psum1::PauliSum, psum2::PauliSum)Calculate the commutator of two PauliSums.
PauliPropagation.commutes — Methodcommutes(pstr1::PauliStringType, pstr2::PauliStringType)Check if two integer Pauli strings commute.
PauliPropagation.commutes — Methodcommutes(pstr1::PauliString, pstr2::PauliString)Check if two Pauli strings of type PauliString commute.
PauliPropagation.commutes — Methodcommutes(psum1::PauliSum, psum2::PauliSum)Check if two Pauli sums of type PauliSum commute.
PauliPropagation.commutes — Methodcommutes(pauli1::Symbol, pauli2::PauliType)
commutes(pauli1::PauliType, pauli2::Symbol)Check if two Paulis commute where one is a Symbol and the other is in the integer representation.
PauliPropagation.commutes — Methodcommutes(pauli1::Symbol, pauli2::Symbol)Check if two Paulis of type Symbol commute.
PauliPropagation.containsXorY — MethodcontainsXorY(pstr::PauliStringType)Check if an integer Pauli string contains an X or Y Pauli.
PauliPropagation.containsXorY — MethodcontainsXorY(pstr::PauliString)Check if a Pauli string contains an X or Y Pauli.
PauliPropagation.containsYorZ — MethodcontainsYorZ(pstr::PauliStringType)Check if an integer Pauli string contains a Y or Z Pauli.
PauliPropagation.containsYorZ — MethodcontainsXorY(pstr::PauliString)Check if a Pauli string contains a Y or Z Pauli.
PauliPropagation.countweight — Methodcountweight(pstr::PauliStringType)Function to count the weight of an integer Pauli string.
PauliPropagation.countweight — Methodcountweight(pstr::PauliString)Function to count the weight of a PauliString.
PauliPropagation.countweight — Methodcountweight(psum::PauliSum)Function to count the weight Pauli strings in a PauliSum. Returns an array of weights.
PauliPropagation.countxy — Methodcountxy(pstr::PauliStringType)Function to count the number of X and Y Paulis in an integer Pauli string.
PauliPropagation.countxy — Methodcountxy(pstr::PauliString)Function to count the number of X and Y Paulis in a PauliString.
PauliPropagation.countxy — Methodcountxy(psum::PauliSum)Function to count the number of X and Y Paulis in a PauliSum. Returns an array of counts.
PauliPropagation.countyz — Methodcountyz(pstr::PauliStringType)Function to count the number of Y and Z Paulis in an integer Pauli string.
PauliPropagation.countyz — Methodcountyz(pstr::PauliString)Function to count the number of Y and Z Paulis in a PauliString.
PauliPropagation.countyz — Methodcountyz(psum::PauliSum)Function to count the number of Y and Z Paulis in a PauliSum. Returns an array of counts.
PauliPropagation.generalizedlevicivita — Methodgeneralizedlevicivita(pauli1::PauliType, pauli2::PauliType, pauli3::PauliType)Calculate the sign of the product of two integer Paulis. Outcomes are either ±1 or ±i. Takes the product of the Paulis as argument for efficiency. Indicate via changed_indices which qubit sites to check. It can be any iterable.
Note, this function is the foundation of calculatesign but assumes that the only (potentially) non-identity Pauli is on the first site.
PauliPropagation.pauliprod — Methodpauliprod(pauli1::PauliType, pauli2::PauliType)Calculate the product of two integer Paulis. Indicate via changed_indices which qubit sites to check. It can be any iterable.
PauliPropagation.pauliprod — Methodpauliprod(pauli1::PauliStringType, pauli2::PauliStringType)Calculate the product of two integer Pauli strings.
PauliPropagation.pauliprod — Methodpauliprod(pauli1::PauliType, pauli2::Symbol)Calculate the product of two Paulis where one is in the integer representation and the other is a Symbol.
PauliPropagation.pauliprod — Methodpauliprod(pstr1::PauliString, pstr2::PauliString)Calculate the product of two PauliStrings. For example X*Y = iZ.
PauliPropagation.pauliprod — Methodpauliprod(pauli1::Symbol, pauli2::PauliType)Calculate the product of two Paulis where one is a Symbol and the other is in the integer representation.
PauliPropagation.pauliprod — Methodpauliprod(pauli1::Symbol, pauli2::Symbol)Calculate the product of two Paulis of type Symbol.
Bit operations
PauliPropagation._bitcommutes — Method_bitcommutes(pstr1::PauliStringType, pstr2::PauliStringType)This function checks if two integer Pauli strings commute.
PauliPropagation._bitpaulimultiply — Method_bitpaulimultiply(pstr1::PauliStringType, pstr2::PauliStringType)XOR between two Pauli different non-identity strings gives the third one. Ignores signs or any coefficient.
PauliPropagation._countbitweight — Method_countbitweight(pstr::PauliStringType)This function counts the number of 00 bit pairs in the integer Pauli string.
PauliPropagation._countbitxy — Method _countbitxy(pstr::PauliStringType)This function counts the number of 01 (X) or 10 (Y) bit pairs in the integer Pauli string.
PauliPropagation._countbityz — Method_countbityz(pstr::PauliStringType)This function counts the number of 10 (Y) or 11 (Z) bit pairs in the integer Pauli string.
PauliPropagation._getbit — Method_getbit(pauli::Integer, bitindex::Integer)Gets the bit at index bitindex in the integer Pauli string.
PauliPropagation._getpaulibits — Method_getpaulibits(pstr::PauliStringType, index::Integer)This function extracts the Pauli at position index from the integer Pauli string.
PauliPropagation._paulishiftright — Method_paulishiftright(pstr::PauliStringType)Shift to the right and truncate the first encoded Pauli string. Just a utility function.
PauliPropagation._setbit — Method_setbit(pstr::PauliStringType, target_bit::Integer, bitindex::Integer)Sets a bit at index bitindex in the integer Pauli string to the value of target_bit.
PauliPropagation._setbittoone — Method_setbittoone(pstr::Integer, bitindex::Integer)Sets a bit at index bitindex in the integer Pauli string to 1.
PauliPropagation._setbittozero — Method_setbittozero(pstr::Integer, bitindex::Integer)Sets a bit at index bitindex in the integer Pauli string to 0.
PauliPropagation._setpaulibits — Method_setpaulibits(pstr::PauliStringType, pauli::PauliType, index::Integer)This function sets the Pauli at position index in the integer Pauli string to target_pauli.
PauliPropagation.getinttype — Methodgetinttype(nqubits::Integer)Function to return the smallest integer type that can hold nqubits for memory and speed.
Utils
PauliPropagation._getprettystr — MethodPretty string function.
PauliPropagation.getpauli — Methodgetpauli(pstr::PauliStringType, qinds::Vector{Integer})Gets the Paulis on indices qinds of a pstr in the integer representation.
PauliPropagation.getpauli — Methodgetpauli(pstr::PauliStringType, index::Integer)Gets the Pauli on index index of an integer Pauli string.
PauliPropagation.identitylike — Methodidentitylike(pstr::PauliStringType)Returns an integer Pauli string of the same type as pstr with all Paulis set to identity.
PauliPropagation.identitypauli — Methodidentitypauli(nqubits::Integer)Returns the integer representation of the identity Pauli string acting on nqubits qubits. The type of will be the smallest integer type that can hold the number of qubits, as given by getinttype(nqubits).
PauliPropagation.identitypauli — Methodidentitypauli(TermType<:PauliStringType)Returns the integer representation of the identity Pauli string with type TermType.
PauliPropagation.inttostring — Methodinttostring(pstr::PauliType, nqubits::Integer)Returns a string representation of an integer Pauli string pstr on nqubits qubits.
PauliPropagation.inttosymbol — Methodinttosymbol(pstr::PauliStringType, nqubits::Integer)Maps an integer Pauli string to a vector of symbols.
PauliPropagation.inttosymbol — Methodinttosymbol(pauli::PauliType)Maps an integer Pauli to its corresponding symbol.
PauliPropagation.ispauli — Methodispauli(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.
PauliPropagation.setpauli — Methodsetpauli(
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.
PauliPropagation.setpauli — Methodsetpauli(
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.
PauliPropagation.setpauli — Methodsetpauli(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).
PauliPropagation.setpauli — Methodsetpauli(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).
PauliPropagation.symboltoint — Methodsymboltoint(pstr::Union{Vector{Symbol}, Symbol})Maps a symbol or a vector of symbols pstr to an integer Pauli string.
Example
symboltoint([:X, :I])
# output
0x01PauliPropagation.symboltoint — Methodsymboltoint(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.
PauliPropagation.symboltoint — Methodsymboltoint(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.
PauliPropagation.symboltoint — Methodsymboltoint(pauli::Symbol)Maps a single symbol to its corresponding integer representation.
PauliPropagation.symboltoint — Methodsymboltoint(::TermType, paulis, qinds)Maps a vector of symbols paulis acting on the indices qinds to an integer Pauli string with type TermType. Other sites are set to the identity. qinds can be any iterable.
PauliPropagation.symboltoint — Methodsymboltoint(::TermType, pauli::Symbol, qind::Integer)Maps a single symbol pauli acting on the index qind to an integer Pauli string with type TermType. Other sites are set to the identity.