ionq-qctrl extension.
What is Max-Cut?
Max-Cut is a combinatorial optimization problem: given a graph, partition its nodes into two groups to maximize the number of edges crossing the partition. For non-planar graphs there is no known polynomial-time classical solution, making it a strong candidate for quantum optimization.Requirements
- An IonQ Quantum Cloud account and API key stored as
IONQ_API_KEY - A Q-CTRL account for Fire Opal with an API key stored as
FIREOPAL_API_KEY - The
ionqandionq-qctrlPython packages
1. Imports and setup
Client() reads IONQ_API_KEY from your environment automatically:
2. Define the problem graph
Create a random graph to use as the Max-Cut input and visualize it:nx.gnm_random_graph(n, m) produces a random graph with n nodes and m edges. Swap in any networkx graph here — weighted graphs are also supported.
3. Build and submit the QAOA workload
Construct aQctrlQaoa workload, specifying "maxcut" as the problem type and passing the graph as the problem definition:
4. Retrieve results
Calljob.results() to wait for completion and fetch the output. The returned object contains the optimizer’s findings:
| Field | Description |
|---|---|
processing_status | Final status of the Fire Opal optimization run |
optimal_cost | Best (lowest) cost value found across all QAOA iterations |
optimal_bitstring | The node partition corresponding to the best cut found |
optimal_bitstring encodes which partition each node belongs to: a 0 or 1 per node, where nodes with different values are on opposite sides of the cut.

