Liking cljdoc? Tell your friends :D

org.soulspace.qclojure.application.algorithm.vqe

Variational Quantum Eigensolver (VQE) Algorithm Implementation

VQE is a quantum-classical hybrid algorithm for finding the ground state energy of quantum systems. It uses a parameterized quantum circuit (ansatz) to prepare trial states and classical optimization to minimize the energy expectation value.

Key Features:

  • Multiple ansatz types (hardware-efficient, UCCSD-inspired, symmetry-preserving)
  • Pauli string Hamiltonian representation with measurement grouping
  • Integration with fastmath optimization for classical optimization
  • Comprehensive analysis and convergence monitoring
  • Support for both gate-based and measurement-based implementations

Algorithm Flow:

  1. Initialize parameterized quantum circuit (ansatz)
  2. Prepare trial state |ψ(θ)⟩ with parameters θ
  3. Measure expectation value ⟨ψ(θ)|H|ψ(θ)⟩
  4. Use classical optimizer to update parameters
  5. Repeat until convergence

This implementation targets production use with real quantum hardware.

Variational Quantum Eigensolver (VQE) Algorithm Implementation

VQE is a quantum-classical hybrid algorithm for finding the ground state energy
of quantum systems. It uses a parameterized quantum circuit (ansatz) to prepare
trial states and classical optimization to minimize the energy expectation value.

Key Features:
- Multiple ansatz types (hardware-efficient, UCCSD-inspired, symmetry-preserving)
- Pauli string Hamiltonian representation with measurement grouping
- Integration with fastmath optimization for classical optimization
- Comprehensive analysis and convergence monitoring
- Support for both gate-based and measurement-based implementations

Algorithm Flow:
1. Initialize parameterized quantum circuit (ansatz)
2. Prepare trial state |ψ(θ)⟩ with parameters θ
3. Measure expectation value ⟨ψ(θ)|H|ψ(θ)⟩
4. Use classical optimizer to update parameters
5. Repeat until convergence

This implementation targets production use with real quantum hardware.
raw docstring

comprehensive-vqe-analysisclj

(comprehensive-vqe-analysis backend vqe-result analysis-options)

Comprehensive VQE analysis combining generic variational analysis with VQE-specific insights.

This function orchestrates a complete analysis of VQE results by combining:

  1. Standard variational algorithm analysis (convergence, performance, landscape)
  2. VQE-specific analysis (quantum state, chemical accuracy, hardware metrics)

This approach eliminates code duplication while providing both generic and specialized analysis.

Use Cases:

  • Complete post-optimization assessment of VQE runs
  • Research analysis combining algorithmic and domain-specific insights
  • Benchmarking VQE against other variational algorithms
  • Production monitoring of VQE quantum chemistry workflows

Parameters:

  • vqe-result: Complete VQE result map from variational-quantum-eigensolver
  • analysis-options: Comprehensive analysis options
    • :backend - Backend for additional analysis computations
    • :landscape-analysis? - Whether to perform expensive landscape analysis (default: false)
    • :confidence-level - Statistical confidence level (default: 0.95)
    • :chemical-accuracy-threshold - Chemical accuracy threshold (default: 0.0016 Ha)

Returns: Comprehensive analysis combining generic variational and VQE-specific insights

Comprehensive VQE analysis combining generic variational analysis with VQE-specific insights.

This function orchestrates a complete analysis of VQE results by combining:
1. Standard variational algorithm analysis (convergence, performance, landscape)
2. VQE-specific analysis (quantum state, chemical accuracy, hardware metrics)

This approach eliminates code duplication while providing both generic and specialized analysis.

Use Cases:
- Complete post-optimization assessment of VQE runs
- Research analysis combining algorithmic and domain-specific insights
- Benchmarking VQE against other variational algorithms
- Production monitoring of VQE quantum chemistry workflows

Parameters:
- vqe-result: Complete VQE result map from variational-quantum-eigensolver
- analysis-options: Comprehensive analysis options
  - :backend - Backend for additional analysis computations
  - :landscape-analysis? - Whether to perform expensive landscape analysis (default: false)
  - :confidence-level - Statistical confidence level (default: 0.95)
  - :chemical-accuracy-threshold - Chemical accuracy threshold (default: 0.0016 Ha)

Returns:
Comprehensive analysis combining generic variational and VQE-specific insights
sourceraw docstring

heisenberg-hamiltonianclj

(heisenberg-hamiltonian num-sites)
(heisenberg-hamiltonian num-sites coupling)
(heisenberg-hamiltonian num-sites coupling periodic)

Create a Heisenberg model Hamiltonian for a 1D chain.

H = J Σᵢ (XᵢXᵢ₊₁ + YᵢYᵢ₊₁ + ZᵢZᵢ₊₁)

Parameters:

  • num-sites: Number of sites in the chain
  • coupling: Coupling strength J (default: 1.0)
  • periodic: Whether to use periodic boundary conditions (default: true)

Returns: Collection of Pauli terms

Create a Heisenberg model Hamiltonian for a 1D chain.

H = J Σᵢ (XᵢXᵢ₊₁ + YᵢYᵢ₊₁ + ZᵢZᵢ₊₁)

Parameters:
- num-sites: Number of sites in the chain
- coupling: Coupling strength J (default: 1.0)
- periodic: Whether to use periodic boundary conditions (default: true)

Returns:
Collection of Pauli terms
sourceraw docstring

molecular-hydrogen-hamiltonianclj

(molecular-hydrogen-hamiltonian)
(molecular-hydrogen-hamiltonian bond-distance)

Create the molecular hydrogen (H₂) Hamiltonian in the STO-3G basis using Jordan-Wigner encoding.

This implementation provides the standard H₂ Hamiltonian used in quantum computing literature, mapped to a 4-qubit system via the Jordan-Wigner transformation. The qubit mapping follows the standard convention:

qubit 0: First spin orbital qubit 1: Second spin orbital
qubit 2: Third spin orbital qubit 3: Fourth spin orbital

The Hartree-Fock reference states |0011⟩ and |1100⟩ are degenerate in this representation, with the true ground state being a superposition that VQE should discover.

High-precision coefficients from Kandala et al. Nature (2017) ensure:

  • Hartree-Fock energy: EXACTLY -1.117 Ha (μHa precision)
  • VQE ground state target: ~-1.137 Ha
  • Accuracy for quantum hardware implementations

Parameters:

  • bond-distance: H-H bond distance in Angstroms (coefficient set is optimized for 0.735 Å)

Returns: Collection of Pauli terms representing the H₂ molecular Hamiltonian with μHa precision

Create the molecular hydrogen (H₂) Hamiltonian in the STO-3G basis using Jordan-Wigner encoding.

This implementation provides the standard H₂ Hamiltonian used in quantum computing literature,
mapped to a 4-qubit system via the Jordan-Wigner transformation. The qubit mapping follows
the standard convention:

qubit 0: First spin orbital
qubit 1: Second spin orbital  
qubit 2: Third spin orbital
qubit 3: Fourth spin orbital

The Hartree-Fock reference states |0011⟩ and |1100⟩ are degenerate in this representation,
with the true ground state being a superposition that VQE should discover.

High-precision coefficients from Kandala et al. Nature (2017) ensure:
- Hartree-Fock energy: EXACTLY -1.117 Ha (μHa precision)
- VQE ground state target: ~-1.137 Ha
- Accuracy for quantum hardware implementations

Parameters:
- bond-distance: H-H bond distance in Angstroms (coefficient set is optimized for 0.735 Å)

Returns:
Collection of Pauli terms representing the H₂ molecular Hamiltonian with μHa precision
sourceraw docstring

variational-quantum-eigensolverclj

(variational-quantum-eigensolver backend options)

Main VQE algorithm implementation using enhanced variational algorithm template.

This function orchestrates the VQE process using the enhanced template, supporting all ansatz types and optimization methods while maintaining backward compatibility with the original interface.

Supported ansatz types:

  • :hardware-efficient - Hardware-efficient ansatz with configurable layers and entangling gates
  • :chemistry-inspired - Chemistry-inspired ansatz with excitation layers
  • :uccsd - UCCSD ansatz for chemistry problems
  • :symmetry-preserving - Symmetry-preserving ansatz for fermionic systems
  • :custom - Custom ansatz function provided in options

Supported optimization methods:

  • :gradient-descent - Basic gradient descent with parameter shift gradients
  • :adam - Adam optimizer with parameter shift gradients
  • :quantum-natural-gradient - Quantum Natural Gradient using Fisher Information Matrix
  • :nelder-mead - Derivative-free Nelder-Mead simplex method
  • :powell - Derivative-free Powell's method
  • :cmaes - Covariance Matrix Adaptation Evolution Strategy (robust)
  • :bobyqa - Bound Optimization BY Quadratic Approximation (handles bounds well)
  • :gradient - Fastmath gradient-based optimizers (not available in this version)

Parameters:

  • backend: Quantum backend implementing QuantumBackend protocol
  • options: Additional options map for execution
    • :optimization-method - Optimization method to use (default: :adam)
    • :max-iterations - Maximum iterations for optimization (default: 500)
    • :tolerance - Convergence tolerance (default: 1e-6)
    • :ansatz-type - Ansatz type to use (default: :hardware-efficient)
    • :num-qubits - Number of qubits in the circuit (default: 2)
    • :num-layers - Number of layers for hardware-efficient ansatz (default: 1)
    • :num-excitation-layers - Number of excitation layers for chemistry-inspired ansatz (default: 1)
    • :num-excitations - Number of excitations for UCCSD ansatz (default: 2)
    • :num-particles - Number of particles for symmetry-preserving ansatz (default: 2)
    • :shots - Number of shots for circuit execution (default: 1024)

Returns: Map containing VQE results and analysis

Example: (variational-quantum-eigensolver backend {:hamiltonian [(ham/pauli-term -1.052373245772859 "ZI") (ham/pauli-term 0.39793742484318045 "XX") (ham/pauli-term -0.39793742484318045 "YY") (ham/pauli-term -0.01128010425623538 "IZ")] :ansatz-type :hardware-efficient :num-qubits 2 :num-layers 2 :optimization-method :adam :max-iterations 100 :tolerance 1e-5 :shots 2048})

Main VQE algorithm implementation using enhanced variational algorithm template.

This function orchestrates the VQE process using the enhanced template,
supporting all ansatz types and optimization methods while maintaining
backward compatibility with the original interface.

Supported ansatz types:
- :hardware-efficient - Hardware-efficient ansatz with configurable layers and entangling gates
- :chemistry-inspired - Chemistry-inspired ansatz with excitation layers
- :uccsd - UCCSD ansatz for chemistry problems
- :symmetry-preserving - Symmetry-preserving ansatz for fermionic systems
- :custom - Custom ansatz function provided in options
 
Supported optimization methods:
- :gradient-descent - Basic gradient descent with parameter shift gradients
- :adam - Adam optimizer with parameter shift gradients
- :quantum-natural-gradient - Quantum Natural Gradient using Fisher Information Matrix
- :nelder-mead - Derivative-free Nelder-Mead simplex method
- :powell - Derivative-free Powell's method
- :cmaes - Covariance Matrix Adaptation Evolution Strategy (robust)
- :bobyqa - Bound Optimization BY Quadratic Approximation (handles bounds well)
- :gradient - Fastmath gradient-based optimizers (not available in this version)

Parameters:
- backend: Quantum backend implementing QuantumBackend protocol
- options: Additional options map for execution
  - :optimization-method - Optimization method to use (default: :adam)
  - :max-iterations - Maximum iterations for optimization (default: 500)
  - :tolerance - Convergence tolerance (default: 1e-6)
  - :ansatz-type - Ansatz type to use (default: :hardware-efficient)
  - :num-qubits - Number of qubits in the circuit (default: 2)
  - :num-layers - Number of layers for hardware-efficient ansatz (default: 1)
  - :num-excitation-layers - Number of excitation layers for chemistry-inspired ansatz (default: 1)
  - :num-excitations - Number of excitations for UCCSD ansatz (default: 2)
  - :num-particles - Number of particles for symmetry-preserving ansatz (default: 2)
  - :shots - Number of shots for circuit execution (default: 1024)

Returns:
Map containing VQE results and analysis

Example:
(variational-quantum-eigensolver backend
  {:hamiltonian [(ham/pauli-term -1.052373245772859 "ZI")
                 (ham/pauli-term 0.39793742484318045 "XX")
                 (ham/pauli-term -0.39793742484318045 "YY")
                 (ham/pauli-term -0.01128010425623538 "IZ")]
   :ansatz-type :hardware-efficient
   :num-qubits 2
   :num-layers 2
   :optimization-method :adam
   :max-iterations 100
   :tolerance 1e-5
   :shots 2048})
sourceraw docstring

vqe-circuit-constructorclj

(vqe-circuit-constructor config)

Create ansatz circuit constructor function for VQE from configuration.

This function creates the appropriate ansatz function based on VQE configuration, handling all supported ansatz types and their parameters.

Parameters:

  • config: VQE configuration map with ansatz settings

Returns: Function that takes parameters and returns a quantum circuit

Create ansatz circuit constructor function for VQE from configuration.

This function creates the appropriate ansatz function based on VQE configuration,
handling all supported ansatz types and their parameters.

Parameters:
- config: VQE configuration map with ansatz settings

Returns:
Function that takes parameters and returns a quantum circuit
sourceraw docstring

vqe-hamiltonian-constructorclj

(vqe-hamiltonian-constructor config)

Construct Hamiltonian for VQE from configuration options.

This function extracts the Hamiltonian setup logic from the main VQE algorithm, allowing it to be used with the variational algorithm template.

Parameters:

  • config: VQE configuration map containing :hamiltonian

Returns: Hamiltonian (collection of Pauli terms) for VQE

Construct Hamiltonian for VQE from configuration options.

This function extracts the Hamiltonian setup logic from the main VQE algorithm,
allowing it to be used with the variational algorithm template.

Parameters:
- config: VQE configuration map containing :hamiltonian

Returns:
Hamiltonian (collection of Pauli terms) for VQE
sourceraw docstring

vqe-parameter-countclj

(vqe-parameter-count config)

Calculate required parameter count for VQE ansatz configuration.

This function determines how many parameters are needed for the specified ansatz type and configuration.

Parameters:

  • config: VQE configuration map with ansatz settings

Returns: Number of parameters required for the ansatz

Calculate required parameter count for VQE ansatz configuration.

This function determines how many parameters are needed for the specified
ansatz type and configuration.

Parameters:
- config: VQE configuration map with ansatz settings

Returns:
Number of parameters required for the ansatz
sourceraw docstring

vqe-result-processorclj

(vqe-result-processor optimization-result config)

Process and format VQE-specific results from optimization.

This function takes the base optimization results and adds VQE-specific analysis, formatting, and metadata to create the final VQE result map.

Parameters:

  • optimization-result: Base optimization result from template
  • config: Original VQE configuration

Returns: VQE-specific result map with analysis and metadata

Process and format VQE-specific results from optimization.

This function takes the base optimization results and adds VQE-specific
analysis, formatting, and metadata to create the final VQE result map.

Parameters:
- optimization-result: Base optimization result from template
- config: Original VQE configuration

Returns:
VQE-specific result map with analysis and metadata
sourceraw docstring

vqe-specific-analysisclj

(vqe-specific-analysis backend vqe-result analysis-options)

VQE-specific analysis that complements the generic variational algorithm analysis.

This function focuses on quantum chemistry and VQE-specific metrics that are not covered by the generic variational algorithm analysis functions. It should be used in combination with the standard variational analysis tools.

VQE-Specific Features:

  • Quantum state characterization and validation
  • Molecular energy analysis and chemical accuracy assessment
  • Hardware compatibility metrics for quantum chemistry applications
  • VQE-specific convergence recommendations

Parameters:

  • vqe-result: Complete VQE result map
  • analysis-options: Options for VQE-specific analysis
    • :backend - Quantum backend for additional state analysis
    • :confidence-level - Statistical confidence level (default: 0.95)
    • :chemical-accuracy-threshold - Threshold for chemical accuracy (default: 0.0016 Ha)

Returns: VQE-specific analysis report to complement standard variational analysis

VQE-specific analysis that complements the generic variational algorithm analysis.

This function focuses on quantum chemistry and VQE-specific metrics that are not
covered by the generic variational algorithm analysis functions. It should be used
in combination with the standard variational analysis tools.

VQE-Specific Features:
- Quantum state characterization and validation
- Molecular energy analysis and chemical accuracy assessment
- Hardware compatibility metrics for quantum chemistry applications
- VQE-specific convergence recommendations

Parameters:
- vqe-result: Complete VQE result map
- analysis-options: Options for VQE-specific analysis
  - :backend - Quantum backend for additional state analysis
  - :confidence-level - Statistical confidence level (default: 0.95)
  - :chemical-accuracy-threshold - Threshold for chemical accuracy (default: 0.0016 Ha)

Returns:
VQE-specific analysis report to complement standard variational analysis
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