Type Reference

Abstract Types

OperatorAlgebra.AbstractOpType
AbstractOp{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

  • Op: Single-site operator
  • OpChain: Product of operators
  • OpSum: Sum of operators

See also: Op, OpChain, OpSum

source

Concrete Types

Op

OperatorAlgebra.OpType
Op{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 operator
  • site::Tid: The site identifier where the operator acts

Type Parameters

  • Tid: Type of site identifiers
  • Tmat: 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

  • Scalar multiplication: 2.0 * op, op * 2.0
  • Adjoint: op'
  • Multiplication with other operators: op1 * op2 (creates OpChain or merges if same site)
  • Addition with other operators: op1 + op2 (creates OpSum or merges if same site)

See also: OpChain, OpSum, apply, atsite

source

OpChain

OperatorAlgebra.OpChainType
OpChain{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'  # true

Operations

  • Scalar multiplication: 2.0 * chain, chain * 2.0
  • Adjoint: chain' (reverses order and takes adjoint of each operator)
  • Multiplication: Extends the chain

See also: Op, OpSum, apply, sparse

source

OpSum

OperatorAlgebra.OpSumType
OpSum{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 terms

Notes

  • apply and apply! are not defined for OpSum on product states, as the result is generally not a product state. Convert to a matrix representation first using sparse or LinearMap.

See also: Op, OpChain, sparse, LinearMap

source

Type Functions

Base.eltypeMethod
eltype(op::AbstractOp)

Return the element type of the operator's matrix representation.

source