Type Reference
Abstract Types
OperatorAlgebra.AbstractOp — TypeAbstractOp{Tid,Tmat}Abstract base type for all operator types in OperatorAlgebra.
Type Parameters
Tid: Type of site identifiers (e.g.,Int,String)Tmat: Element type of the underlying matrix representation
Subtypes
Concrete Types
Op
OperatorAlgebra.Op — TypeOp{Tid,Tmat} <: AbstractOp{Tid,Tmat}A single-site operator acting on a specific site in a tensor product space.
Fields
mat::AbstractMatrix{Tmat}: The matrix representation of the operatorsite::Tid: The site identifier where the operator acts
Type Parameters
Tid: Type of site identifiersTmat: Element type of the matrix
Constructors
Op(mat::AbstractMatrix, site)Create a single-site operator with matrix mat acting on site.
Examples
# Create Pauli X operator on site 1
σx = Op(PAULI_X, 1)
# Create a custom operator on site "A"
custom_op = Op([1.0 0.0; 0.0 -1.0], "A")Operations
OpChain
OperatorAlgebra.OpChain — TypeOpChain{Tid,Tmat} <: AbstractOp{Tid,Tmat}A product (chain) of operators representing non-commutative multiplication.
An OpChain is created automatically when multiplying operators together. It represents the product O₁ × O₂ × ... × Oₙ, where the order matters for non-commuting operators.
Fields
ops::Vector{<:AbstractOp{Tid,Tmat}}: Vector of operators in the product
Type Parameters
Tid: Type of site identifiers (automatically promoted)Tmat: Element type of matrices (automatically promoted)
Constructors
OpChain(ops::Vararg{AbstractOp})Create an operator chain from multiple operators. Types are automatically promoted.
Examples
# Create a chain by multiplication
σx = Op(PAULI_X, 1)
σy = Op(PAULI_Y, 2)
σz = Op(PAULI_Z, 3)
chain = σx * σy * σz # Creates OpChain automatically
# Operators on the same site are merged
op1 = Op([1 0; 0 2], 1)
op2 = Op([2 0; 0 1], 1)
merged = op1 * op2 # Single Op with matrix multiplication
# Adjoint reverses order
chain' == σz' * σy' * σx' # trueOperations
- Scalar multiplication:
2.0 * chain,chain * 2.0 - Adjoint:
chain'(reverses order and takes adjoint of each operator) - Multiplication: Extends the chain
OpSum
OperatorAlgebra.OpSum — TypeOpSum{Tid,Tmat} <: AbstractOp{Tid,Tmat}A sum of operators representing linear combinations.
An OpSum is created automatically when adding operators together. It represents the sum O₁ + O₂ + ... + Oₙ.
Fields
ops::Vector{<:AbstractOp{Tid,Tmat}}: Vector of operators in the sum
Type Parameters
Tid: Type of site identifiers (automatically promoted)Tmat: Element type of matrices (automatically promoted)
Constructors
OpSum(ops::Vararg{AbstractOp})Create an operator sum from multiple operators. Types are automatically promoted.
Examples
# Create a sum by addition
σx = Op(PAULI_X, 1)
σz = Op(PAULI_Z, 2)
H = σx + σz # Creates OpSum automatically
# Operators on the same site are merged
op1 = Op([1 0; 0 0], 1)
op2 = Op([0 0; 0 1], 1)
merged = op1 + op2 # Single Op with matrix addition
# Build a Hamiltonian
H = sum(Op(PAULI_X, i) for i in 1:5) # OpSum of X operators
# Scalar multiplication
H_scaled = 2.0 * H # Scales all termsNotes
applyandapply!are not defined forOpSumon product states, as the result is generally not a product state. Convert to a matrix representation first usingsparseorLinearMap.
Type Functions
Base.eltype — Methodeltype(op::AbstractOp)Return the element type of the operator's matrix representation.
OperatorAlgebra.sitetype — Functionsitetype(op::AbstractOp)Return the type used for site identifiers in the operator.