Pauli Algebra
Data types
PauliPropagation.PauliString — Type
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.
PauliPropagation.PauliString — Type
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.
PauliPropagation.PauliSum — Type
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.
PauliPropagation.PauliSum — Method
PauliSum(nqubits::Integer)Contructor for an empty PauliSum on nqubits qubits. Element type defaults for Float64.
PauliPropagation.PauliSum — Method
PauliSum(pstr::PauliString)Constructor for a PauliSum on nqubits qubits from a PauliString.
PauliPropagation.PauliSum — Method
PauliSum(pstrs::Vector{PauliString})Constructor for a PauliSum on nqubits qubits from a PauliString.
PauliPropagation.PauliSum — Method
PauliSum(nq::Integer, pstr::PauliString)Constructor for a PauliSum on nqubits qubits from a PauliString.
PauliPropagation.PauliSum — Method
PauliSum(CoeffType, nq::Int)Contructor for an empty PauliSum on nqubits qubits. The type of the coefficients can be provided.
Base.empty! — Method
empty!(psum::PauliSum)Empty the PauliSum by emptying the dictionary on the terms fields.
Base.iterate — Function
Iterator for PauliSum returns an iterator over (pstr, coeff) pairs`.
Base.length — Method
length(psum::PauliSum)Number of terms in the PauliSum.
Base.similar — Method
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.
Base.sizehint! — Method
sizehint!(psum::PauliSum, n)Hint to the PauliSum to reserve space for n terms.
PauliPropagation._checknumberofqubits — Method
Checks whether the number of qubits nqubits is the same between in some collection.
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.
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.
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.
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).
PauliPropagation.coefficients — Method
coefficients(psum::PauliSum)Returns an iterator over the coefficients of a PauliSum. Call topaulistrings to receive entries as PauliStrings.
PauliPropagation.coefftype — Method
coefftype(pstr::PauliString)Get the coefficient type of a PauliString.
PauliPropagation.coefftype — Method
coefftype(psum::PauliSum)Get the coefficient type of a PauliSum.
PauliPropagation.getcoeff — Method
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.
PauliPropagation.getcoeff — Method
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.
PauliPropagation.getcoeff — Method
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.
PauliPropagation.getcoeff — Method
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.
PauliPropagation.getcoeff — Method
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.
PauliPropagation.mult! — Method
mult!(psum::PauliSum, c::Number)Multiply a PauliSum by a scalar c in-place.
PauliPropagation.norm — Function
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.
PauliPropagation.numcoefftype — Method
numcoefftype(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 — Method
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.
PauliPropagation.paulis — Method
paulis(psum::PauliSum)Returns an iterator over the integer pauli strings of a PauliSum. Call topaulistrings to receive entries as PauliStrings.
PauliPropagation.paulitype — Method
paulitype(pstr::PauliString)Get the Pauli integer type of a PauliString.
PauliPropagation.paulitype — Method
paulitype(psum::PauliSum)Get the Pauli integer type of a PauliSum.
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.
PauliPropagation.tonumber — Method
tonumber(val::Number)Trivial function returning a numerical value of a number. Will be overloaded for custom wrapper types like PathProperties.
PauliPropagation.topaulistrings — Method
topaulistrings(psum::PauliSum)Returns the Pauli strings in a PauliSum and their coefficients as a list of PauliString.
Pauli operations
LinearAlgebra.tr — Method
LinearAlgebra.tr(pstr::PauliString)Compute the trace of a PauliString operator.
The trace of any non-identity Pauli operator (e.g., X, Y, Z, or their tensor products) is zero. The identity operator I has a trace equal to the dimension of the Hilbert space, 2^N, where N is the number of qubits.
A PauliString represents a single term, typically of the form coeff * P_1 P_2 ... P_N. If the pstr.term bitmask is 0x00, it signifies the identity operator across all pstr.nqubits. In this case, the trace is pstr.coeff * 2^pstr.nqubits. For any other pstr.term value (representing a non-identity Pauli operator), the trace is 0.0.
Arguments
pstr::PauliString{TT, CT}: The Pauli string to trace.
Returns
CT: The trace value of thePauliString.
LinearAlgebra.tr — Method
LinearAlgebra.tr(psum::PauliSum)Compute the trace of a PauliSum operator.
The trace is a linear operation: Tr(A + B) = Tr(A) + Tr(B). Since individual non-identity PauliString terms have a trace of zero (as per tr(::PauliString)), only the coefficient of the identity operator contributes to the total trace of a PauliSum.
The coefficient of the identity term (0x00) is retrieved from this mapping using get(psum.terms, 0x00, 0). This coefficient is then multiplied by 2^psum.nqubits (the dimension of the Hilbert space). If the identity term (0x00) is not explicitly present in psum.terms, its coefficient is implicitly zero, resulting in a total trace of 0.0.
Arguments
psum::PauliSum: The Pauli sum to trace.
Returns
CT: The trace value of the PauliSum.
PauliPropagation.commutator — Method
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.
PauliPropagation.commutator — Method
commutator(pstr1::PauliString, pstr2::PauliString)Calculate the commutator of two PauliStrings.
PauliPropagation.commutator — Method
commutator(psum::PauliSum, pstr::PauliString)
commutator(pstr::PauliString, psum::PauliSum)Calculate the commutator of a PauliSum and a PauliString.
PauliPropagation.commutator — Method
commutator(psum1::PauliSum, psum2::PauliSum)Calculate the commutator of two PauliSums.
PauliPropagation.commutes — Method
commutes(pstr1::Integer, pstr2::Integer)Check if two integer Pauli strings commute.
PauliPropagation.commutes — Method
commutes(pstr1::PauliString, pstr2::PauliString)Check if two Pauli strings of type PauliString commute.
PauliPropagation.commutes — Method
commutes(psum1::PauliSum, psum2::PauliSum)Check if two Pauli sums of type PauliSum commute.
PauliPropagation.containsXorY — Method
containsXorY(pstr::Integer)Check if an integer Pauli string contains an X or Y Pauli.
PauliPropagation.containsXorY — Method
containsXorY(pstr::PauliString)Check if a Pauli string contains an X or Y Pauli.
PauliPropagation.containsYorZ — Method
containsYorZ(pstr::Integer)Check if an integer Pauli string contains a Y or Z Pauli.
PauliPropagation.containsYorZ — Method
containsXorY(pstr::PauliString)Check if a Pauli string contains a Y or Z Pauli.
PauliPropagation.countweight — Method
countweight(pstr::Integer)Function to count the weight of an integer Pauli string.
PauliPropagation.countweight — Method
countweight(pstr::PauliString)Function to count the weight of a PauliString.
PauliPropagation.countweight — Method
countweight(psum::PauliSum)Function to count the weight Pauli strings in a PauliSum. Returns an array of weights.
PauliPropagation.countx — Method
countx(pstr::Integer)Function to count the number of X Paulis in an integer Pauli string.
PauliPropagation.countx — Method
countx(pstr::PauliString)Function to count the number of X Paulis in a PauliString.
PauliPropagation.countx — Method
countx(psum::PauliSum)Function to count the number of X Paulis in a PauliSum. Returns an array of counts.
PauliPropagation.countxy — Method
countxy(pstr::Integer)Function to count the number of X and Y Paulis in an integer Pauli string.
PauliPropagation.countxy — Method
countxy(pstr::PauliString)Function to count the number of X and Y Paulis in a PauliString.
PauliPropagation.countxy — Method
countxy(psum::PauliSum)Function to count the number of X and Y Paulis in a PauliSum. Returns an array of counts.
PauliPropagation.county — Method
county(pstr::Integer)Function to count the number of Y Paulis in an integer Pauli string.
PauliPropagation.county — Method
county(pstr::PauliString)Function to count the number of Y Paulis in a PauliString.
PauliPropagation.county — Method
county(psum::PauliSum)Function to count the number of Y Paulis in a PauliSum. Returns an array of counts.
PauliPropagation.countyz — Method
countyz(pstr::Integer)Function to count the number of Y and Z Paulis in an integer Pauli string.
PauliPropagation.countyz — Method
countyz(pstr::PauliString)Function to count the number of Y and Z Paulis in a PauliString.
PauliPropagation.countyz — Method
countyz(psum::PauliSum)Function to count the number of Y and Z Paulis in a PauliSum. Returns an array of counts.
PauliPropagation.countz — Method
countz(pstr::Integer)Function to count the number of Z Paulis in an integer Pauli string.
PauliPropagation.countz — Method
countz(pstr::PauliString)Function to count the number of Z Paulis in a PauliString.
PauliPropagation.countz — Method
countz(psum::PauliSum)Function to count the number of Z Paulis in a PauliSum. Returns an array of counts.
PauliPropagation.pauliprod — Method
pauliprod(pstr1::Integer, pstr2::Integer)Calculate the product of two integer Pauli strings.
PauliPropagation.pauliprod — Method
pauliprod(pstr1::PauliString, pstr2::PauliString)Calculate the product of two PauliStrings.
Examples
julia> pauliprod(PauliString(1, [:X], [1]), PauliString(1, [:Y], [1])) # X*Y=iZPauliPropagation.pauliprod — Method
pauliprod(psum1::PauliSum, psum2::PauliSum)Calculate the product of two PauliSums. Default returns a PauliSum{TT, ComplexF64} where TT is the type of the new Pauli Strings.
Examples
psum = PauliSum(PauliString(3, [:Y], [2]))
psum_identity = PauliSum(PauliString(3, [:I], [1]))
pauliprod(psum, psum_identity) # Psum * I = PsumPauliPropagation.trace — Method
trace(pstr::PauliString)Wrapper for LinearAlgebra.tr(pstr::PauliString).
Arguments
pstr::PauliString{TT, CT}: The Pauli string to trace.
Returns
CT: The trace value of thePauliString.
PauliPropagation.trace — Method
trace(psum::PauliSum)Wrapper for LinearAlgebra.tr(psum::PauliSum).
Arguments
psum::PauliSum: The Pauli sum to trace.
Returns
CT: The trace value of the PauliSum.
Bit operations
PauliPropagation.getinttype — Method
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.
Utils
PauliPropagation.getpauli — Method
getpauli(pstr::PauliStringType, qinds::Vector{Integer})Gets the Paulis on indices qinds of a pstr in the integer representation.
PauliPropagation.getpauli — Method
getpauli(pstr::PauliStringType, qind1::Int, qind2::Int)Gets the Paulis from qind1 to qind2 of a pstr in the integer representation. This function is useful for extracting a continuous sub-PauliString.
PauliPropagation.inttostring — Method
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.
PauliPropagation.inttosymbol — Method
inttosymbol(pstr::PauliStringType, nqubits::Integer)Maps an integer Pauli string to a vector of symbols.
PauliPropagation.inttosymbol — Method
inttosymbol(pauli::PauliType)Maps an integer Pauli to its corresponding symbol.
PauliPropagation.ispauli — Method
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.
PauliPropagation.setpauli — Method
setpauli(pstr::PauliStringType, target_paulis::PauliStringType, index1::Integer, index2::Integer)Sets the Paulis from index1 to index2 of an integer Pauli string to target_paulis.
PauliPropagation.setpauli — Method
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.
PauliPropagation.setpauli — Method
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.
PauliPropagation.setpauli — Method
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).
PauliPropagation.setpauli — Method
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).
PauliPropagation.symboltoint — Method
symboltoint(pstr::Union{Vector{Symbol}, Symbol})Maps a symbol or a vector of symbols pstr to an integer Pauli string.
Example:
symboltoint([:X, :I])
>>> 0x01PauliPropagation.symboltoint — Method
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.
PauliPropagation.symboltoint — Method
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.
PauliPropagation.symboltoint — Method
symboltoint(pauli::Symbol)Maps a single symbol to its corresponding integer representation.
PauliPropagation.symboltoint — Method
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.
PauliPropagation.symboltoint — Method
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.