QAOAProblem#
- class QAOAProblem(cost_operator, mixer, cl_cost_function, init_function=None, callback=False)[source]#
Central structure to facilitate treatment of QAOA problems.
This class encapsulates the cost operator, mixer operator, and classical cost function for a specific QAOA problem instance. It also provides methods to set the initial state preparation function, classical cost post-processing function, and optimizer for the problem.
For a quick demonstration, we import the relevant functions from already implemented problem instances:
from networkx import Graph G = Graph() G.add_edges_from([[0,3],[0,4],[1,3],[1,4],[2,3],[2,4]]) from qrisp.qaoa import (QAOAProblem, create_maxcut_cost_operator, create_maxcut_cl_cost_function, RX_mixer) maxcut_instance = QAOAProblem(cost_operator = create_maxcut_cost_operator(G), mixer = RX_mixer, cl_cost_function = create_maxcut_cl_cost_function(G)) from qrisp import QuantumVariable res = maxcut_instance.run(qarg = QuantumVariable(5), depth = 4, max_iter = 25) print(res) #Yields: {'11100': 0.2847, '00011': 0.2847, '10000': 0.0219, '01000': 0.0219, '00100': 0.0219, '11011': 0.0219, '10111': 0.0219, '01111': 0.0219, '00010': 0.02, '11110': 0.02, '00001': 0.02, '11101': 0.02, '00000': 0.0173, '11111': 0.0173, '10010': 0.0143, '01010': 0.0143, '11010': 0.0143, '00110': 0.0143, '10110': 0.0143, '01110': 0.0143, '10001': 0.0143, '01001': 0.0143, '11001': 0.0143, '00101': 0.0143, '10101': 0.0143, '01101': 0.0143, '11000': 0.0021, '10100': 0.0021, '01100': 0.0021, '10011': 0.0021, '01011': 0.0021, '00111': 0.0021}
For an in-depth tutorial, make sure to check out MaxCut QAOA Implementation!
- Parameters:
- cost_operatorfunction
A function receiving a QuantumVariable or QuantumArray and parameter \(\gamma\). This function performs the application of the cost operator.
- mixerfunction
A function receiving a QuantumVariable or QuantumArray and parameter \(\beta\). This function performs the application mixing operator.
- cl_cost_functionfunction
The classical cost function for the specific QAOA problem instance, which takes a dictionary of measurement results as input.
- init_functionfunction, optional
A function receiving a QuantumVariable or QuantumArray for preparing the inital state. By default, the uniform superposition state \(\ket{+}^n\) is prepared.
- callbackBooelan, optional
If
True
, intermediate results are stored. The default isFalse
.
Methods#
|
Run the specific QAOA problem instance with given quantum arguments, depth of QAOA circuit, measurement keyword arguments (mes_kwargs) and maximum iterations for optimization (max_iter). |
|
This function allows for training of a circuit with a given |
|
Compiles the circuit that is evaluated by the |
|
This method enables convenient data collection regarding performance of the implementation. |
|
Set the initial state preparation function for the QAOA problem. |
Visualizes the cost during the optimization process. |