qplex.algorithms package¶
Subpackages¶
- qplex.algorithms.mixers package
- Submodules
- qplex.algorithms.mixers.cardinality_mixer module
- qplex.algorithms.mixers.composite_mixer module
- qplex.algorithms.mixers.inequality_mixer module
- qplex.algorithms.mixers.mixer_factory module
- qplex.algorithms.mixers.partition_mixer module
- qplex.algorithms.mixers.quantum_mixer module
- qplex.algorithms.mixers.standard_mixer module
- Module contents
Submodules¶
qplex.algorithms.base_algorithm module¶
- class qplex.algorithms.base_algorithm.Algorithm(model)[source]¶
Bases:
ABCAbstract base class for quantum algorithms.
This class provides a template for quantum algorithms, encapsulating the common elements and enforcing the implementation of specific methods in subclasses. It is designed for variational quantum algorithms like QAOA and VQE, which require creating quantum circuits and updating parameters for optimization.
- model¶
The optimization model to be solved, typically defined using the QuadraticProgram class from qiskit_optimization.
- Type:
Model
- qubo¶
The QUBO (Quadratic Unconstrained Binary Optimization) encoding of the problem, initialized as None and generated as needed.
- Type:
QuadraticProgram or None
- iteration¶
The current iteration number of the optimization process, used to track the progress of the algorithm.
- Type:
int
- circuit¶
A string representation of the quantum circuit, in OpenQASM3 format. Initially set to None and constructed via the create_circuit method in the subclass.
- Type:
str or None
- abstract create_circuit() str[source]¶
Creates a quantum circuit in the form of an OpenQASM3 string from an optimization model.
This method constructs the circuit using the quantum algorithm’s ansatz and problem-specific gates. It needs to be implemented by subclasses like QAOA or VQE.
- Returns:
An OpenQASM3 string representing the quantum circuit.
- Return type:
str
- abstract get_starting_point() ndarray[source]¶
Defines the starting point for the optimization process.
This method provides the initial parameter values for the optimization routine, often used in variational quantum algorithms to begin parameter tuning.
- Returns:
An array representing the starting point parameters for the optimization.
- Return type:
np.ndarray
- remove_parameters()[source]¶
Removes the parameter input lines from the quantum circuit string.
This method removes lines in the circuit string that declare parameter inputs (i.e., input float[64] thetaX;) but keeps the placeholders (like ‘thetaX’) in the circuit. This is useful for working with unparameterized circuits or circuits where parameters are defined externally, such as when using the GGAE workflow from QPLEX.
- Raises:
AttributeError – If the ‘circuit’ attribute is not defined or is None.
- abstract update_params(params: ndarray) str[source]¶
Updates the parameters of the quantum circuit.
This method updates the circuit’s gates according to new parameters, often used in variational quantum algorithms where parameters are iteratively optimized.
- Parameters:
params (np.ndarray) – The new set of parameters for the circuit, typically representing angles for rotation gates or other tunable parameters.
- Returns:
The updated OpenQASM3 string with the new parameter values.
- Return type:
str
qplex.algorithms.qaoa module¶
- class qplex.algorithms.qaoa.QAOA(model, p: int, seed: int, penalty: float, mixer: QuantumMixer | None = None)[source]¶
Bases:
AlgorithmQuantum Approximate Optimization Algorithm (QAOA).
This class implements the QAOA algorithm for solving combinatorial optimization problems using quantum resources. It creates a quantum circuit, updates parameters, and provides a starting point for the optimization process.
- p¶
The number of repetitions of the two parameterized unitary operations.
- Type:
int
- n¶
The number of qubits in the quantum circuit, which corresponds to the number of binary variables in the optimization problem.
- Type:
int
- circuit¶
The OpenQASM3 representation of the quantum circuit.
- Type:
str
- num_params¶
The number of parameters for the QAOA variational circuit, which is equal to 2 times the number of repetitions (p).
- Type:
int
- create_circuit(*args, **kwargs) str[source]¶
Creates a quantum circuit in the form of an OpenQASM3 string for QAOA.
The circuit is constructed based on the QUBO encoding of the model, including all the necessary gates for the QAOA ansatz. The ansatz includes mixing and problem unitary operations with parameterized rotation angles.
- Parameters:
kwargs (dict) – Optional parameters, including ‘penalty’ for the QUBO conversion.
- Returns:
An OpenQASM3 string representing the quantum circuit for QAOA.
- Return type:
str
- get_starting_point() ndarray[source]¶
Defines the starting point for the QAOA optimization.
The starting point consists of a set of randomly initialized parameters (rotation angles) for the variational QAOA circuit.
- Returns:
An array representing the starting point for QAOA, initialized with random values between 0 and 1.
- Return type:
np.ndarray
- update_params(params: ndarray) str[source]¶
Updates the parameters of the QAOA circuit.
The circuit is updated by replacing the placeholder angles (‘thetaX’) with the values provided in the parameter array. This allows the quantum circuit to be re-parameterized as part of a variational optimization process.
- Parameters:
params (np.ndarray) – The new set of parameters for the QAOA circuit, typically representing rotation angles in the circuit’s gates.
- Returns:
The updated OpenQASM3 string for the QAOA circuit with the new parameter values.
- Return type:
str
qplex.algorithms.vqe module¶
- class qplex.algorithms.vqe.VQE(model, layers: int, seed: int, penalty: float, ansatz: str)[source]¶
Bases:
AlgorithmVariational Quantum Eigensolver (VQE).
This class implements the VQE algorithm for solving optimization problems using a variational approach. It creates a quantum circuit, updates parameters, and provides a starting point for the optimization.
- layers¶
The number of layers in the VQE ansatz.
- Type:
int
- n¶
The number of qubits in the quantum circuit.
- Type:
int
- circuit¶
The OpenQASM3 representation of the VQE circuit.
- Type:
str
- num_params¶
The number of parameters for the VQE variational circuit.
- Type:
int
- create_circuit(*args, **kwargs) str[source]¶
Creates a quantum circuit in the form of an OpenQASM3 string for VQE.
The circuit is constructed based on the QUBO encoding of the model, including all necessary gates for the VQE ansatz.
- Parameters:
kwargs – Optional parameters, including ‘penalty’ for QUBO conversion.
- Returns:
An OpenQASM3 string representing the quantum circuit for VQE.
- Return type:
str
- get_starting_point() ndarray[source]¶
Defines the starting point for the VQE optimization.
- Returns:
An array representing the starting point for VQE, initialized with random values.
- Return type:
np.ndarray
- update_params(params: ndarray) str[source]¶
Updates the parameters of the VQE circuit.
The circuit is updated by replacing the placeholder angles with the values provided in the parameter array.
- Parameters:
params (np.ndarray) – The new set of parameters for the VQE circuit.
- Returns:
The updated OpenQASM3 string for the VQE circuit.
- Return type:
str
Module contents¶
This module provides the different gate-based algorithms.