View on GitHub
Open this notebook in GitHub to run it yourself
Output:
Electric Grid Optimization using QAOA
For a set of N power plants (sources) and M consumers, the goal is to supply power to all consumers while meeting the constraints of the power plants and minimizing the total cost of supplying power. The model here is a minor variation of [1]. Mathematical model, minimizing the objective function: where is the required values of the transmitted power from source to consumer . The unit cost of transmitting power from node to node is . Constraint: the sum of powers flowing from power plant transmission lines to all customer nodes must be up to the power of the source : Each consumer receives power : This example takes and . Note the use of two kinds of constraints: equality and inequality.Building the Problem

Output:
Solving with Classiq
Take the specific example outlined above.Generating Parameters for the Quantum Circuit
Synthesizing the QAOA Circuit and Solving the Problem
Synthesize and view the QAOA circuit (ansatz) used to solve the optimization problem:Output:
Output:
optimize method of the CombinatorialProblem object.
For the classical optimization part of QAOA, define the maximum number of classical iterations (maxiter) and the -parameter (quantile) for running CVaR-QAOA, an improved variation of the QAOA algorithm [3]:
Output:

Best Solution Statistics
| solution | probability | cost | |
|---|---|---|---|
| 415 | {‘x’: [[0, 1, 0, 0], [1, 0, 0, 1], [0, 0, 1, 0… | 0.000488 | 3.4 |
| 1022 | {‘x’: [[0, 1, 0, 1], [0, 0, 0, 0], [1, 0, 1, 0… | 0.000488 | 4.5 |
| 348 | {‘x’: [[1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0… | 0.000488 | 21.9 |
| 169 | {‘x’: [[0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 1… | 0.000977 | 23.3 |
| 1215 | {‘x’: [[0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 0… | 0.000488 | 23.5 |

Best Solution
Output:
Output:
| B1 | B2 | B3 | B4 | |
|---|---|---|---|---|
| A1 | 0 | 1 | 0 | 0 |
| A2 | 1 | 0 | 0 | 1 |
| A3 | 0 | 0 | 1 | 0 |

Comparing to a Classical Solver
Output:
Output:
| B1 | B2 | B3 | B4 | |
|---|---|---|---|---|
| A1 | 1.000000 | 0.000000 | 0.000000 | 0.000000 |
| A2 | 0.000000 | 1.000000 | 0.000000 | 1.000000 |
| A3 | 0.000000 | -0.000000 | 1.000000 | 0.000000 |
