Liking cljdoc? Tell your friends :D

org.soulspace.qclojure.domain.hamiltonian

Core Hamiltonian representation and manipulation for quantum systems.

This namespace provides the fundamental building blocks for working with quantum Hamiltonians in the VQE algorithm and other quantum algorithms.

Key Responsibilities:

  • Pauli term creation and validation
  • Hamiltonian expectation value calculations
  • Measurement grouping for hardware efficiency
  • Commuting term analysis

Design Principles:

  • Pure functions with no side effects
  • Hardware-agnostic mathematical operations
  • Composable building blocks for higher-level algorithms
Core Hamiltonian representation and manipulation for quantum systems.

This namespace provides the fundamental building blocks for working with
quantum Hamiltonians in the VQE algorithm and other quantum algorithms.

Key Responsibilities:
- Pauli term creation and validation
- Hamiltonian expectation value calculations  
- Measurement grouping for hardware efficiency
- Commuting term analysis

Design Principles:
- Pure functions with no side effects
- Hardware-agnostic mathematical operations
- Composable building blocks for higher-level algorithms
raw docstring

group-commuting-termsclj

(group-commuting-terms hamiltonian)

Group Hamiltonian terms that can be measured simultaneously.

Terms that commute can be measured in the same quantum circuit execution, reducing the number of measurements needed.

Parameters:

  • hamiltonian: Collection of Pauli terms

Returns: Vector of groups, where each group is a collection of commuting terms

Group Hamiltonian terms that can be measured simultaneously.

Terms that commute can be measured in the same quantum circuit execution,
reducing the number of measurements needed.

Parameters:
- hamiltonian: Collection of Pauli terms

Returns:
Vector of groups, where each group is a collection of commuting terms
sourceraw docstring

group-pauli-terms-by-measurement-basisclj

(group-pauli-terms-by-measurement-basis hamiltonian)

Group Pauli terms by their required measurement basis for hardware execution.

This function is essential for efficient quantum hardware execution, as different Pauli operators require different measurement bases:

  • Z operators: measured directly in computational basis
  • X operators: require H rotation before measurement
  • Y operators: require S†H rotation before measurement

Parameters:

  • hamiltonian: Collection of Pauli terms

Returns: Map with measurement basis as key and list of compatible terms as value Format: {:z [terms...] :x [terms...] :y [terms...] :mixed [terms...]}

Group Pauli terms by their required measurement basis for hardware execution.

This function is essential for efficient quantum hardware execution, as different
Pauli operators require different measurement bases:
- Z operators: measured directly in computational basis
- X operators: require H rotation before measurement
- Y operators: require S†H rotation before measurement

Parameters:
- hamiltonian: Collection of Pauli terms

Returns:
Map with measurement basis as key and list of compatible terms as value
Format: {:z [terms...] :x [terms...] :y [terms...] :mixed [terms...]}
sourceraw docstring

hamiltonian-expectationclj

(hamiltonian-expectation hamiltonian quantum-state)

Calculate expectation value of a Hamiltonian.

⟨H⟩ = Σᵢ cᵢ ⟨Pᵢ⟩ where cᵢ are coefficients and Pᵢ are Pauli strings.

Parameters:

  • hamiltonian: Collection of Pauli terms
  • quantum-state: Quantum state to measure

Returns: Real expectation value (energy)

Calculate expectation value of a Hamiltonian.

⟨H⟩ = Σᵢ cᵢ ⟨Pᵢ⟩ where cᵢ are coefficients and Pᵢ are Pauli strings.

Parameters:
- hamiltonian: Collection of Pauli terms
- quantum-state: Quantum state to measure

Returns:
Real expectation value (energy)
sourceraw docstring

hamiltonian-expectation-density-matrixclj

(hamiltonian-expectation-density-matrix hamiltonian density-matrix)
(hamiltonian-expectation-density-matrix hamiltonian density-matrices weights)

Calculate expectation value of a Hamiltonian for density matrix ρ.

For density matrices (mixed states), the expectation value is calculated as: ⟨H⟩ = Σᵢ cᵢ Tr(ρPᵢ) where cᵢ are coefficients and Pᵢ are Pauli strings.

This function supports both single density matrices and collections of density matrices with optional weights for ensemble averaging.

Parameters:

  • hamiltonian: Collection of Pauli terms
  • density-matrix-or-collection: Either a single density matrix or collection of matrices
  • weights: (optional) Collection of weights for weighted averaging. If not provided, uniform weighting is used for collections.

Returns: For single matrix: Real number representing the expectation value (energy) For collection: Map with :mean, :std-dev, :variance, :weights, :individual-values

Examples: (hamiltonian-expectation-density-matrix h2-hamiltonian single-density-matrix) (hamiltonian-expectation-density-matrix h2-hamiltonian [dm1 dm2 dm3]) (hamiltonian-expectation-density-matrix h2-hamiltonian [dm1 dm2] [0.3 0.7])

Calculate expectation value of a Hamiltonian for density matrix ρ.

For density matrices (mixed states), the expectation value is calculated as:
⟨H⟩ = Σᵢ cᵢ Tr(ρPᵢ) where cᵢ are coefficients and Pᵢ are Pauli strings.

This function supports both single density matrices and collections of density 
matrices with optional weights for ensemble averaging.

Parameters:
- hamiltonian: Collection of Pauli terms
- density-matrix-or-collection: Either a single density matrix or collection of matrices
- weights: (optional) Collection of weights for weighted averaging. If not provided,
           uniform weighting is used for collections.

Returns:
   For single matrix: Real number representing the expectation value (energy)
   For collection: Map with :mean, :std-dev, :variance, :weights, :individual-values

Examples:
   (hamiltonian-expectation-density-matrix h2-hamiltonian single-density-matrix)
   (hamiltonian-expectation-density-matrix h2-hamiltonian [dm1 dm2 dm3])
   (hamiltonian-expectation-density-matrix h2-hamiltonian [dm1 dm2] [0.3 0.7])
sourceraw docstring

pauli-string-expectationclj

(pauli-string-expectation pauli-string quantum-state)

Calculate expectation value of a single Pauli string.

Parameters:

  • pauli-string: String like 'XYZZ' representing Pauli operators
  • quantum-state: Quantum state to measure

Returns: Real expectation value

Calculate expectation value of a single Pauli string.

Parameters:
- pauli-string: String like 'XYZZ' representing Pauli operators
- quantum-state: Quantum state to measure

Returns:
Real expectation value
sourceraw docstring

pauli-termclj

(pauli-term coefficient pauli-string)

Create a Pauli term with coefficient and Pauli string.

Parameters:

  • coefficient: Real coefficient for the term
  • pauli-string: String like 'XYZZ' representing tensor product of Pauli operators

Returns: Map representing a single term in the Hamiltonian

Create a Pauli term with coefficient and Pauli string.

Parameters:
- coefficient: Real coefficient for the term
- pauli-string: String like 'XYZZ' representing tensor product of Pauli operators

Returns:
Map representing a single term in the Hamiltonian
sourceraw docstring

validate-hamiltonianclj

(validate-hamiltonian hamiltonian)

Validate that a Hamiltonian is properly formed.

Parameters:

  • hamiltonian: Collection of Pauli terms

Returns: Boolean indicating validity

Validate that a Hamiltonian is properly formed.

Parameters:
- hamiltonian: Collection of Pauli terms

Returns:
Boolean indicating validity
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close