A Julia package for efficient manipulation of Pauli operators and quantum states using bitstring representations. The package uses symplectic representation to encode tensor products of Pauli operators as pairs of binary strings, enabling fast operations on systems with up to 128 qubits.
The format for an arbitrary Pauli operator is:
where the Int128 integers, supporting up to 128 qubits. The
PauliBasis{N}: Hermitian, positive Pauli basis elements. These form the basis for linear combinations and are used as keys inPauliSumdictionaries.
struct PauliBasis{N}
z::Int128 # Z operator bitstring
x::Int128 # X operator bitstring
endPauli{N}: General Pauli operator with an arbitrary complex coefficient, allowing representation of scaled and phased Pauli strings.
struct Pauli{N}
s::ComplexF64 # Coefficient
z::Int128 # Z operator bitstring
x::Int128 # X operator bitstring
endPauliSum{N,T}: Linear combination of Pauli operators, implemented as a dictionary mappingPauliBasis{N}to coefficients of typeT.
PauliSum{N,T} = Dict{PauliBasis{N}, T}Ket{N}andBra{N}: Computational basis states represented as bitstrings.
struct Ket{N}
v::Int128 # Occupation number bitstring
end
struct Bra{N}
v::Int128
endKetSum{N,T}: Linear combination of computational basis states.
KetSum{N,T} = Dict{Ket{N}, T}-
DyadBasis{N}: Basis elements for density matrices and operators, representing outer products$|i⟩⟨j|$ .
struct DyadBasis{N}
ket::Ket{N}
bra::Bra{N}
endDyad{N}: Scaled dyads with complex coefficients.
struct Dyad{N}
s::ComplexF64
ket::Ket{N}
bra::Bra{N}
endDyadSum{N,T}: Linear combination of dyads, useful for representing density matrices and general operators.
DyadSum{N,T} = Dict{DyadBasis{N}, T}- Efficient Operations: Pauli multiplication, addition, and tensor products using bitwise operations
- Zero Allocations: Core operations are allocation-free when the number of qubits
Nis a compile-time constant - Flexible Arithmetic: Overloaded operators (
*,+,⊗,⊕) for intuitive manipulation - Quantum Computations:
expectation_value(operator, state)- compute expectation valuesmatrix_element(bra, operator, ket)- compute matrix elements- Conversion to dense matrix representations for verification
using PauliOperators
# Create Pauli operators (3 qubits)
X = Pauli("XII")
Y = Pauli("IYI")
Z = Pauli("IIZ")
# Build a Hamiltonian
H = PauliSum(3, ComplexF64)
H[PauliBasis("XII")] = -1.0
H[PauliBasis("IYI")] = -0.5
H[PauliBasis("IIZ")] = -0.3
# Create a quantum state
ψ = Ket([1, 0, 1]) # |101⟩
# Compute expectation value
E = expectation_value(H, ψ)
# Tensor products
ZZ = Z ⊗ Z # Create a 6-qubit operator
# Direct sums
H_total = H ⊕ H # Combine two 3-qubit HamiltoniansThe package is designed for high performance with zero-allocation operations:
- Pauli multiplication and addition
- Expectation value calculations
- State manipulations
When N (number of qubits) is known at compile time, all core operations are performed without heap allocations, making this package suitable for performance-critical quantum simulations.