core.converters.qaoa#
This module implements the Quantum Approximate Optimization Algorithm (QAOA) converter for the Qamomile framework [Farhi et al., 2014]. The parameterized state \(|\vec{\beta},\vec{\gamma}\rangle\) of \(p\)-layer QAOA is defined as:
where \(H_P\) is the cost Hamiltonian, \(H_M\) is the mixer Hamiltonian and \(\gamma_l\) and \(\beta_l\) are the variational parameters. The 2 \(p\) variational parameters are optimized classically to minimize the expectation value \(\langle \vec{\beta},\vec{\gamma}|H_P|\vec{\beta},\vec{\gamma}\rangle\).
This module provides functionality to convert optimization problems which written by jijmodeling into QAOA circuits (\(U(\vec{\beta},\vec{\gamma})\)), construct cost Hamiltonians (\(H_P\)), and decode quantum computation results.
The QAOAConverter class extends the QuantumConverter base class, specializing in QAOA-specific operations such as ansatz circuit generation and result decoding.
Key Features: - Generation of QAOA ansatz circuits - Construction of cost Hamiltonians for QAOA - Decoding of quantum computation results into classical optimization solutions
Note: This module requires jijmodeling and jijmodeling_transpiler for problem representation.
Edward Farhi, Jeffrey Goldstone, and Sam Gutmann. A quantum approximate optimization algorithm. 2014. URL: https://arxiv.org/abs/1411.4028, arXiv:1411.4028.
Classes#
QAOA (Quantum Approximate Optimization Algorithm) converter class. |
Module Contents#
- class QAOAConverter(compiled_instance, relax_method: jijmodeling_transpiler.core.pubo.RelaxationMethod = jmt.pubo.RelaxationMethod.AugmentedLagrangian, normalize_model: bool = False, normalize_ising: Literal['abs_max', 'rms'] | None = None)#
Bases:
qamomile.core.converters.converter.QuantumConverter
QAOA (Quantum Approximate Optimization Algorithm) converter class.
This class provides methods to convert optimization problems into QAOA circuits, construct cost Hamiltonians, and decode quantum computation results.
Examples:
from qamomile.core.qaoa.qaoa import QAOAConverter # Initialize with a compiled optimization problem instance qaoa_converter = QAOAConverter(compiled_instance) # Generate QAOA circuit and cost Hamiltonian p = 2 # Number of QAOA layers qaoa_circuit = qaoa_converter.get_ansatz_circuit(p) cost_hamiltonian = qaoa_converter.get_cost_hamiltonian()
Initialize the QuantumConverter.
This method initializes the converter with the compiled instance of the optimization problem
- Parameters:
compiled_instance – The compiled instance of the optimization problem.
relax_method (jmt.pubo.RelaxationMethod) – The relaxation method for PUBO conversion. Defaults to AugmentedLagrangian.
normalize_model (bool) – The objective function and the constraints are normalized using the maximum absolute value of the coefficients contained in each. Defaults to False
normalize_ising (Literal["abs_max", "rms"] | None) – The normalization method for the Ising Hamiltonian. Available options: - “abs_max”: Normalize by absolute maximum value - “rms”: Normalize by root mean square Defaults to None.
- get_cost_ansatz(gamma: qamomile.core.circuit.Parameter, name: str = 'Cost') qamomile.core.circuit.QuantumCircuit #
Generate the cost ansatz circuit (\(e^{-\gamma H_P}\)) for QAOA. This function is mainly used when you have designed your own mixer Hamiltonian and only need the cost Hamiltonian.
- Parameters:
gamma (qm_c.Parameter) – The gamma parameter for the cost ansatz.
name (str, optional) – Name of the circuit. Defaults to “Cost”.
- Returns:
The cost ansatz circuit.
- Return type:
qm_c.QuantumCircuit
- get_qaoa_ansatz(p: int, initial_hadamard: bool = True) qamomile.core.circuit.QuantumCircuit #
Generate the complete QAOA ansatz circuit.
- Parameters:
p (int) – Number of QAOA layers.
initial_hadamard (bool, optional) – Whether to apply initial Hadamard gates. Defaults to True.
- Returns:
The complete QAOA ansatz circuit.
- Return type:
qm_c.QuantumCircuit
- get_cost_hamiltonian() qamomile.core.operator.Hamiltonian #
Construct the cost Hamiltonian for QAOA.
- Returns:
The cost Hamiltonian.
- Return type:
qm_o.Hamiltonian