Pauli Algebra

Pauli operations

LinearAlgebra.trMethod
LinearAlgebra.tr(psum::AbstractPauliSum)

Compute the trace of an AbstractPauliSum 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^nqubits(psum) (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.

source
LinearAlgebra.trMethod
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: The Pauli string to trace.

Returns

  • CT: The trace value of the PauliString.
source
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.commutatorMethod
commutator(vpsum1::VectorPauliSum, vpsum2::VectorPauliSum)

Calculate the commutator of two VectorPauliSums. Returns a VectorPauliSum with complex coefficients.

Example

vpsum = VectorPauliSum(3, [1, 2], [1.]) # 1.0 * X + 1.0 * Y
vpsum2 = VectorPauliSum(3, [7], [0.25]) # 0.25 * ZX
commutator(vpsum, vpsum2) # should return a VectorPauliSum with - 0.5 YX + 0.5 XX
source
PauliPropagation.countxMethod
countx(psum::PauliSum)

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

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.countyMethod
county(psum::PauliSum)

Function to count the number of 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
PauliPropagation.countzMethod
countz(psum::PauliSum)

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

source
PauliPropagation.pauliprodMethod
pauliprod(pstr1::PauliString, pstr2::PauliString)

Calculate the product of two PauliStrings.

Examples

julia> pauliprod(PauliString(1, [:X], [1]), PauliString(1, [:Y], [1])) # X*Y=iZ
source
PauliPropagation.pauliprodMethod
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 = Psum
source
PauliPropagation.traceMethod
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.

source
PauliPropagation.traceMethod
trace(pstr::PauliString)

Wrapper for LinearAlgebra.tr(pstr::PauliString).

Arguments

  • pstr::PauliString: The Pauli string to trace.

Returns

  • CT: The trace value of the PauliString.
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.getpauliMethod
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.

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::PauliStringType, index1::Integer, index2::Integer)

Sets the Paulis from index1 to index2 of an integer Pauli string to target_paulis.

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