Zum Hauptinhalt springe

Quantum Approximate Optimization Algorithm

Nutzungsschätzung: 22 Minuta auf emm Heron r3 Prozessor (HINWEIS: Des isch nur a Schätzung. Dei Laufzeit ka variiere.)

Hintergrund

Des Tutorial demonstriert d'Implementierung vo dem Quantum Approximate Optimization Algorithm (QAOA) – aner hybride (quanten-klassische) iterative Methode – im Kontext vo Qiskit-Patterns. Mr werde zunächst des Maximum-Cut (oder Max-Cut) Problem für a kleina Graphen löse und dann lerne, wie mer's auf Utility-Skala ausführt. Alli Hardware-Ausführunge im Tutorial sollet innerhalb vo dem Zeitlimit für de frei zugängliche Open Plan funktioniere.

Des Max-Cut-Problem isch a Optimierungsproblem, wo schwer z'löse isch (genauer gsagt isch's a NP-hartes Problem) und a Reihe vo verschiedene Anwendunge in Clustering, Netzwerkwissenschaft und statistischer Physik hend. Des Tutorial betrachtet a Graphen vo Knoten, wo durch Kante verbunde send, und zielt drauf ab, d'Knoten in zwei Menge z'partitioniere, so dass d'Anzahl vo de durch den Schnitt durchquerte Kante maximiert wird.

Illustration of a max-cut problem

Voraussetzunge

Schau vor dem Aafange vo diesem Tutorial, dass des Folgende installiert isch:

  • Qiskit SDK v1.0 oder neier, mit Visualisierungs-Unterstützung
  • Qiskit Runtime v0.22 oder neier (pip install qiskit-ibm-runtime)

Zusätzlich wird Zugang z'aner Instanz auf dr IBM Quantum Platform benötigt. Beachtet, dass des Tutorial ned im Open Plan ausgeführt werde ka, da's Workloads mit Sessions ausführt, wo nur mit Premium Plan-Zugang verfügbar send.

Einrichtung

import matplotlib
import matplotlib.pyplot as plt
import rustworkx as rx
from rustworkx.visualization import mpl_draw as draw_graph
import numpy as np
from scipy.optimize import minimize
from collections import defaultdict
from typing import Sequence

from qiskit.quantum_info import SparsePauliOp
from qiskit.circuit.library import QAOAAnsatz
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import Session, EstimatorV2 as Estimator
from qiskit_ibm_runtime import SamplerV2 as Sampler

Teil I. QAOA im kleina Maßstab

Dr erschte Teil vo diesem Tutorial verwendet a kleines Max-Cut-Problem, um d'Schritte z'r Lösung vo amm Optimierungsproblem mit emm Quantencomputer z'veranschauliche.

Um a bessere Kontext z'gebe, bevor des Problem auf a Quantenalgorithmus abgbildet wird, ka mr besser verstehe, wie des Max-Cut-Problem z'amm klassische kombinatorische Optimierungsproblem wird, indem mr zunächst d'Minimierung vo aner Funktion f(x)f(x) betrachtet

minx{0,1}nf(x),\min_{x\in \{0, 1\}^n}f(x),

wobei d'Eingabe xx a Vektor isch, wo sei Komponente jedem Knoten vo amm Graphen entspreche. Dann wird jede vo diese Komponente auf entweder 00 oder 11 beschränkt (wo repräsentiere, ob se im Schnitt enthalte send oder ned). Dieser kleinskalige Beispielfall verwendet a Graphen mit n=5n=5 Knoten.

Mr kennet a Funktion vo amm Knotenpaar i,ji,j schreibe, wo azeigt, ob d'entsprechende Kante (i,j)(i,j) im Schnitt liegt. Zum Beispiel isch d'Funktion xi+xj2xixjx_i + x_j - 2 x_i x_j genau dann 1, wenn entweder xix_i oder xjx_j gleich 1 isch (was bedeutet, dass d'Kante im Schnitt liegt) und sunsch null. Des Problem, d'Kante im Schnitt z'maximiere, ka formuliert werde als

maxx{0,1}n(i,j)xi+xj2xixj,\max_{x\in \{0, 1\}^n} \sum_{(i,j)} x_i + x_j - 2 x_i x_j,

was als Minimierung umgschriebe werde ka in dr Form

minx{0,1}n(i,j)2xixjxixj.\min_{x\in \{0, 1\}^n} \sum_{(i,j)} 2 x_i x_j - x_i - x_j.

Des Minimum vo f(x)f(x) in diesem Fall liegt vor, wenn d'Anzahl vo de durch de Schnitt durchquerte Kante maximal isch. Wie mr sehe kennet, hend des noch nix mit Quantencomputing z'tue. Des Problem muss in ebbes umformuliert werre, wo a Quantencomputer verstehe ka. Initialisiert des Problem, indem a Graphen mit n=5n=5 Knoten erstellt wird.

n = 5

graph = rx.PyGraph()
graph.add_nodes_from(np.arange(0, n, 1))
edge_list = [
(0, 1, 1.0),
(0, 2, 1.0),
(0, 4, 1.0),
(1, 2, 1.0),
(2, 3, 1.0),
(3, 4, 1.0),
]
graph.add_edges_from(edge_list)
draw_graph(graph, node_size=600, with_labels=True)

Output of the previous code cell

Schritt 1: Klassische Eingabe auf a Quantenproblem abbilden

Dr erschte Schritt vo dem Pattern besteht drin, des klassische Problem (Graph) auf quantenmechanische Schaltkreise und Operatoren abz'bilde. Dazu send drei Hauptschritte z'unternehme:

  1. Verwendung vo aner Reihe vo mathematische Umformulierunge, um des Problem mithilfe vo dr Notation vo Quadratic Unconstrained Binary Optimization (QUBO) Probleme darzustelle.
  2. Umformulierung vo dem Optimierungsproblem als Hamilton-Operator, für de dr Grundzustand dr Lösung entspricht, wo d'Kostenfunktion minimiert.
  3. Erstellung vo amm Quantenschaltkreis, wo de Grundzustand vo diesem Hamilton-Operator über a Prozess ähnlich dem Quantum Annealing vorbereitet.

Hinweis: In dr QAOA-Methodik wollet mr letztendlich a Operator (Hamilton-Operator) hend, wo d'Kostenfunktion vo unsere hybride Algorithmus darstellt, sowie a parametrisierten Schaltkreis (Ansatz), wo Quantenzuständ mit Kandidatenlösunge für des Problem darstellt. Mr kennet aus diese Kandidatenzuständ samplen und se dann mit dr Kostenfunktion bewerte.

Graph → Optimierungsproblem

Dr erschte Schritt vo dr Abbildung isch a Notationsänderung. Des Folgende drückt des Problem in QUBO-Notation aus:

minx{0,1}nxTQx,\min_{x\in \{0, 1\}^n}x^T Q x,

wobei QQ a n×nn\times n Matrix vo reelle Zahle isch, nn dr Anzahl vo de Knoten im Graphen entspricht, xx dr oben eiführte Vektor vo binäre Variable isch und xTx^T d'Transponierte vo dem Vektor xx bezeichnet.

Maximize
-2*x_0*x_1 - 2*x_0*x_2 - 2*x_0*x_4 - 2*x_1*x_2 - 2*x_2*x_3 - 2*x_3*x_4 + 3*x_0
+ 2*x_1 + 3*x_2 + 2*x_3 + 2*x_4

Subject to
No constraints

Binary variables (5)
x_0 x_1 x_2 x_3 x_4

Optimierungsproblem → Hamilton-Operator

Mr kennet dann des QUBO-Problem als Hamilton-Operator umformuliere (do a Matrix, wo d'Energie vo amm System darstellt):

HC=ijQijZiZj+ibiZi.H_C=\sum_{ij}Q_{ij}Z_iZ_j + \sum_i b_iZ_i.

Umformulierungsschritte vom QAOA-Problem zum Hamilton-Operator

Um z'demonstriere, wie des QAOA-Problem auf diese Weise umgschriebe werde ka, ersetzt mr zunächst d'binäre Variable xix_i durch a neie Satz vo Variable zi{1,1}z_i\in\{-1, 1\} über

xi=1zi2.x_i = \frac{1-z_i}{2}.

Do kennet mr sehe, dass wenn xix_i gleich 00 isch, dann ziz_i gleich 11 sei muss. Wenn d'xix_i durch d'ziz_i im Optimierungsproblem (xTQxx^TQx) ersetzt werde, ka a äquivalente Formulierung erhalte werde.

xTQx=ijQijxixj=14ijQij(1zi)(1zj)=14ijQijzizj14ij(Qij+Qji)zi+n24.x^TQx=\sum_{ij}Q_{ij}x_ix_j \\ =\frac{1}{4}\sum_{ij}Q_{ij}(1-z_i)(1-z_j) \\=\frac{1}{4}\sum_{ij}Q_{ij}z_iz_j-\frac{1}{4}\sum_{ij}(Q_{ij}+Q_{ji})z_i + \frac{n^2}{4}.

Wenn mer jetzt bi=j(Qij+Qji)b_i=-\sum_{j}(Q_{ij}+Q_{ji}) definiere, de Vorfaktor entferne und de konstante Term n2n^2 weglasse, erhalte mer d'beide äquivalente Formulierunge vo demselbe Optimierungsproblem.

minx{0,1}nxTQxminz{1,1}nzTQz+bTz\min_{x\in\{0,1\}^n} x^TQx\Longleftrightarrow \min_{z\in\{-1,1\}^n}z^TQz + b^Tz

Do hängt bb vo QQ ab. Beachtet, dass mer z'r Erlangung vo zTQz+bTzz^TQz + b^Tz de Faktor 1/4 und a konstante Offset vo n2n^2 wegglasse hend, wo bei dr Optimierung kei Rolle spielet.

Um jetzt a Quantenformulierung vo dem Problem z'erhalte, erhebe mer d'Variable ziz_i z'aner Pauli ZZ Matrix, wie aner 2×22\times 2 Matrix vo dr Form

Zi=(1001).Z_i = \begin{pmatrix}1 & 0 \\ 0 & -1\end{pmatrix}.

Wenn mr diese Matrize im obige Optimierungsproblem einsetzt, erhaltet mr de folgende Hamilton-Operator

HC=ijQijZiZj+ibiZi.H_C=\sum_{ij}Q_{ij}Z_iZ_j + \sum_i b_iZ_i.

Beachtet auch, dass d'ZZ Matrize in de Rechenraum vo dem Quantencomputer eingebettet send, des heißt in a Hilbert-Raum vo dr Größe 2n×2n2^n\times 2^n. Deswege sollet mr Terme wie ZiZjZ_iZ_j als des Tensorprodukt ZiZjZ_i\otimes Z_j verstehe, wo in de 2n×2n2^n\times 2^n Hilbert-Raum eingebettet isch. Zum Beispiel wird in amm Problem mit fünf Entscheidungsvariable dr Term Z1Z3Z_1Z_3 als IZ3IZ1II\otimes Z_3\otimes I\otimes Z_1\otimes I verstande, wobei II d'2×22\times 2 Einheitsmatrix isch.

Dieser Hamilton-Operator wird als Kostenfunktions-Hamilton-Operator bezeichnet. Er hend d'Eigenschaft, dass sei Grundzustand dr Lösung entspricht, wo d'Kostenfunktion f(x)f(x) minimiert. Um des Optimierungsproblem z'löse, muss jetzt de Grundzustand vo HCH_C (oder a Zustand mit hoher Überlappung damit) auf dem Quantencomputer präpariert werre. Des Sampeln aus diesem Zustand wird dann mit hoher Wahrscheinlichkeit d'Lösung z'min f(x)min~f(x) liefera. Betrachte mer jetzt de Hamilton-Operator HCH_C für des Max-Cut Problem. Jedem Knoten vo dem Graphen wird a Qubit im Zustand 0|0\rangle oder 1|1\rangle zugeordnet, wobei dr Wert d'Menge angibt, z'der dr Knoten ghört. Des Ziel vo dem Problem isch's, d'Anzahl vo de Kante (v1,v2)(v_1, v_2) z'maximiere, für wo v1=0v_1 = |0\rangle und v2=1v_2 = |1\rangle gilt, oder umgekehrt. Wenn mer de ZZ Operator jedem Qubit zuordnet, wobei

Z0=0Z1=1 Z|0\rangle = |0\rangle \qquad Z|1\rangle = -|1\rangle

dann ghört a Kante (v1,v2)(v_1, v_2) zum Schnitt, wenn dr Eigenwert vo (Z1v1)(Z2v2)=1(Z_1|v_1\rangle) \cdot (Z_2|v_2\rangle) = -1 isch; mit andere Wort, d'mit v1v_1 und v2v_2 assoziierte Qubits send unterschiedlich. Ebenso ghört (v1,v2)(v_1, v_2) ned zum Schnitt, wenn dr Eigenwert vo (Z1v1)(Z2v2)=1(Z_1|v_1\rangle) \cdot (Z_2|v_2\rangle) = 1 isch. Beachtet, dass uns dr genaue Qubit-Zustand, wo jedem Knoten zugeordnet isch, ned interessiert, sunsch nur, ob se über a Kante hinweg gleich send oder ned. Des Max-Cut-Problem verlangt vo uns, a Zuordnung vo de Qubits auf d'Knoten z'finde, so dass dr Eigenwert vo dem folgende Hamilton-Operator minimiert wird

HC=(i,j)eQijZiZj. H_C = \sum_{(i,j) \in e} Q_{ij} \cdot Z_i Z_j.

Mit andere Wort, bi=0b_i = 0 für alli ii im Max-Cut-Problem. Dr Wert vo QijQ_{ij} bezeichnet des Gewicht vo dr Kante. In diesem Tutorial betrachte mer a ungewichtete Graphen, des heißt Qij=1.0Q_{ij} = 1.0 für alli i,ji, j.

def build_max_cut_paulis(
graph: rx.PyGraph,
) -> list[tuple[str, list[int], float]]:
"""Convert the graph to Pauli list.

This function does the inverse of `build_max_cut_graph`
"""
pauli_list = []
for edge in list(graph.edge_list()):
weight = graph.get_edge_data(edge[0], edge[1])
pauli_list.append(("ZZ", [edge[0], edge[1]], weight))
return pauli_list

max_cut_paulis = build_max_cut_paulis(graph)
cost_hamiltonian = SparsePauliOp.from_sparse_list(max_cut_paulis, n)
print("Cost Function Hamiltonian:", cost_hamiltonian)
Cost Function Hamiltonian: SparsePauliOp(['IIIZZ', 'IIZIZ', 'ZIIIZ', 'IIZZI', 'IZZII', 'ZZIII'],
coeffs=[1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j])

Hamilton-Operator → Quantenschaltkreis

Dr Hamilton-Operator HCH_C enthält d'Quantendefinition vo dem Problem. Jetzt kennet mr a Quantenschaltkreis erstelle, wo dabei hilft, guete Lösunge vom Quantencomputer z'samplen. Dr QAOA isch inspiriert vom Quantum Annealing und wendet abwechselnde Schichte vo Operatoren im Quantenschaltkreis a.

D'allgemeine Idee besteht drin, im Grundzustand vo amm bekannte System z'beginne, Hn0H^{\otimes n}|0\rangle obe, und dann des System in de Grundzustand vo dem Kostenoperator z'steuere, wo mr interessiert send. Des gschieht durch Anwendung vo de Operatoren exp{iγkHC}\exp\{-i\gamma_k H_C\} und exp{iβkHm}\exp\{-i\beta_k H_m\} mit Winkeln γ1,...,γp\gamma_1,...,\gamma_p und β1,...,βp \beta_1,...,\beta_p~.

Dr generierte Quantenschaltkreis isch parametrisiert durch γi\gamma_i und βi\beta_i, so dass mr verschiedene Werte vo γi\gamma_i und βi\beta_i ausprobiere und aus dem resultierenden Zustand samplen kennet.

Circuit diagram with QAOA layers

In diesem Fall wird a Beispiel mit aner QAOA-Schicht probiert, wo zwei Parameter enthält: γ1\gamma_1 und β1\beta_1.

circuit = QAOAAnsatz(cost_operator=cost_hamiltonian, reps=2)
circuit.measure_all()

circuit.draw("mpl")

Output of the previous code cell

circuit.parameters
ParameterView([ParameterVectorElement(β[0]), ParameterVectorElement(β[1]), ParameterVectorElement(γ[0]), ParameterVectorElement(γ[1])])

Schritt 2: Problem für Quanten-Hardware-Ausführung optimiere

Dr obige Schaltkreis enthält a Reihe vo Abstraktione, wo nützlich send, um über Quantenalgorithmen nachz'denke, aber auf dr Hardware ned ausführbar send. Um auf aner QPU ausgeführt werde z'könne, muss dr Schaltkreis a Reihe vo Operatione durchlaufe, wo de Transpilations- oder Schaltkreis-Optimierungs-Schritt vo dem Pattern ausmache.

D'Qiskit-Bibliothek bietet a Reihe vo Transpilations-Pässen, wo a breite Palette vo Schaltkreistransformatione abdeckt. Der Schaltkreis muss für de eigene Zweck optimiert sei.

D'Transpilation ka mehrere Schritte umfasse, wie zum Beispiel:

  • Initiales Mapping vo de Qubits im Schaltkreis (wie Entscheidungsvariable) auf physische Qubits auf dem Gerät.
  • Unrolling vo de Anweisunge im Quantenschaltkreis z'de hardware-native Anweisunge, wo des Backend versteht.
  • Routing vo beliebige Qubits im Schaltkreis, wo interagiere, z'physische Qubits, wo benachbart zueinander send.
  • Fehlerunterdrückung durch Hinzufüge vo Einzelqubit-Gates z'r Rauschunterdrückung mit dynamischer Entkopplung.

Weitere Informationen z'r Transpilation findet mr in unserer Dokumentation.

Dr folgende Code transformiert und optimiert de abstrakte Schaltkreis in a Format, wo z'r Ausführung auf emm vo de über d'Cloud zugängliche Geräte mit dem Qiskit IBM Runtime Service bereit isch.

service = QiskitRuntimeService()
backend = service.least_busy(
operational=True, simulator=False, min_num_qubits=127
)
print(backend)

# Create pass manager for transpilation
pm = generate_preset_pass_manager(optimization_level=3, backend=backend)

candidate_circuit = pm.run(circuit)
candidate_circuit.draw("mpl", fold=False, idle_wires=False)
<IBMBackend('test_heron_pok_1')>

Output of the previous code cell

Schritt 3: Ausführung mit Qiskit Primitives

Im QAOA-Workflow werde d'optimale QAOA-Parameter in aner iterativen Optimierungsschleife gfunde, wo a Reihe vo Schaltkreisbewertunge ausführt und a klassische Optimierer verwendet, um d'optimale βk\beta_k und γk\gamma_k Parameter z'finde. Diese Ausführungsschleife wird über d'folgende Schritte ausgeführt:

  1. Definiere vo de initialen Parameter
  2. Instanziierung vo aner neie Session, wo d'Optimierungsschleife und des Primitive enthält, wo zum Samplen vo dem Schaltkreis verwendet wird
  3. Sobald a optimale Parametersatz gfunde isch, wird de Schaltkreis a letzts Mal ausgeführt, um a finale Verteilung z'erhalte, wo im Post-Processing-Schritt verwendet wird.

Schaltkreis mit initialen Parametern definiere

Mer beginne mit willkürlich gwählte Parametern.

initial_gamma = np.pi
initial_beta = np.pi / 2
init_params = [initial_beta, initial_beta, initial_gamma, initial_gamma]

Backend und Ausführungs-Primitive definiere

Verwend d'Qiskit Runtime Primitives, um mit IBM® Backends z'interagiere. D'beide Primitives send Sampler und Estimator, und d'Wahl vo dem Primitive hängt davon ab, welche Art vo Messung auf dem Quantencomputer ausgeführt werre soll. Für d'Minimierung vo HCH_C verwend de Estimator, da d'Messung vo dr Kostenfunktion einfach dr Erwartungswert vo HC\langle H_C \rangle isch.

Ausführe

D'Primitives biete a Vielzahl vo Ausführungsmodi z'r Planung vo Workloads auf Quantengeräten, und a QAOA-Workflow läuft iterativ in aner Session.

Illustration showing the behavior of Single job, Batch, and Session runtime modes.

Mr kennet d'sampler-basierte Kostenfunktion in d'SciPy-Minimierungsroutine eistecke, um d'optimale Parameter z'finde.

def cost_func_estimator(params, ansatz, hamiltonian, estimator):
# transform the observable defined on virtual qubits to
# an observable defined on all physical qubits
isa_hamiltonian = hamiltonian.apply_layout(ansatz.layout)

pub = (ansatz, isa_hamiltonian, params)
job = estimator.run([pub])

results = job.result()[0]
cost = results.data.evs

objective_func_vals.append(cost)

return cost
objective_func_vals = []  # Global variable
with Session(backend=backend) as session:
# If using qiskit-ibm-runtime<0.24.0, change `mode=` to `session=`
estimator = Estimator(mode=session)
estimator.options.default_shots = 1000

# Set simple error suppression/mitigation options
estimator.options.dynamical_decoupling.enable = True
estimator.options.dynamical_decoupling.sequence_type = "XY4"
estimator.options.twirling.enable_gates = True
estimator.options.twirling.num_randomizations = "auto"

result = minimize(
cost_func_estimator,
init_params,
args=(candidate_circuit, cost_hamiltonian, estimator),
method="COBYLA",
tol=1e-2,
)
print(result)
message: Return from COBYLA because the trust region radius reaches its lower bound.
success: True
status: 0
fun: -1.6295230263157894
x: [ 1.530e+00 1.439e+00 4.071e+00 4.434e+00]
nfev: 26
maxcv: 0.0

Dr Optimierer konnt d'Kosten reduziere und bessere Parameter für de Schaltkreis finde.

plt.figure(figsize=(12, 6))
plt.plot(objective_func_vals)
plt.xlabel("Iteration")
plt.ylabel("Cost")
plt.show()

Output of the previous code cell

Sobald d'optimale Parameter für de Schaltkreis gfunde send, kennet mr diese Parameter zuwise und d'mit de optimierte Parametern erhaltene finale Verteilung sampeln. Do sollet des Sampler Primitive verwendet werde, da's d'Wahrscheinlichkeitsverteilung vo Bitstring-Messunge isch, wo dem optimale Schnitt vo dem Graphen entspreche.

Hinweis: Des bedeutet, a Quantenzustand ψ\psi im Computer z'präpariere und en dann z'messe. A Messung wird de Zustand in a einzelne Berechnungsbasiszustand kollabiere lasse - zum Beispiel 010101110000... - wo aner Kandidatenlösung xx für unser ursprüngliche Optimierungsproblem (maxf(x)\max f(x) oder minf(x)\min f(x) je nach Aufgabe) entspricht.

optimized_circuit = candidate_circuit.assign_parameters(result.x)
optimized_circuit.draw("mpl", fold=False, idle_wires=False)

Output of the previous code cell

# If using qiskit-ibm-runtime<0.24.0, change `mode=` to `backend=`
sampler = Sampler(mode=backend)
sampler.options.default_shots = 10000

# Set simple error suppression/mitigation options
sampler.options.dynamical_decoupling.enable = True
sampler.options.dynamical_decoupling.sequence_type = "XY4"
sampler.options.twirling.enable_gates = True
sampler.options.twirling.num_randomizations = "auto"

pub = (optimized_circuit,)
job = sampler.run([pub], shots=int(1e4))
counts_int = job.result()[0].data.meas.get_int_counts()
counts_bin = job.result()[0].data.meas.get_counts()
shots = sum(counts_int.values())
final_distribution_int = {key: val / shots for key, val in counts_int.items()}
final_distribution_bin = {key: val / shots for key, val in counts_bin.items()}
print(final_distribution_int)
{28: 0.0328, 11: 0.0343, 2: 0.0296, 25: 0.0308, 16: 0.0303, 27: 0.0302, 13: 0.0323, 7: 0.0312, 4: 0.0296, 9: 0.0295, 26: 0.0321, 30: 0.031, 23: 0.0324, 31: 0.0303, 21: 0.0335, 15: 0.0317, 12: 0.0309, 29: 0.0297, 3: 0.0313, 5: 0.0312, 6: 0.0274, 10: 0.0329, 22: 0.0353, 0: 0.0315, 20: 0.0326, 8: 0.0322, 14: 0.0306, 17: 0.0295, 18: 0.0279, 1: 0.0325, 24: 0.0334, 19: 0.0295}

Schritt 4: Nachbearbeitung und Rückgabe vo dem Ergebnis im gwünschte klassische Format

Dr Nachbearbeitungsschritt interpretiert d'Sampling-Ausgabe, um a Lösung für des ursprüngliche Problem zurückz'gebe. In diesem Fall send mr an dem Bitstring mit dr höchste Wahrscheinlichkeit interessiert, da dieser de optimale Schnitt bestimmt. D'Symmetrien im Problem erlaubet vier möglichi Lösunge, und dr Sampling-Prozess wird a davon mit aner etwas höhere Wahrscheinlichkeit zurückgebe, aber mr kennet in dr unten dargestellte Verteilung sehe, dass vier vo de Bitstrings deutlich wahrscheinlicher send als dr Rest.

# auxiliary functions to sample most likely bitstring
def to_bitstring(integer, num_bits):
result = np.binary_repr(integer, width=num_bits)
return [int(digit) for digit in result]

keys = list(final_distribution_int.keys())
values = list(final_distribution_int.values())
most_likely = keys[np.argmax(np.abs(values))]
most_likely_bitstring = to_bitstring(most_likely, len(graph))
most_likely_bitstring.reverse()

print("Result bitstring:", most_likely_bitstring)
Result bitstring: [0, 1, 1, 0, 1]
matplotlib.rcParams.update({"font.size": 10})
final_bits = final_distribution_bin
values = np.abs(list(final_bits.values()))
top_4_values = sorted(values, reverse=True)[:4]
positions = []
for value in top_4_values:
positions.append(np.where(values == value)[0])
fig = plt.figure(figsize=(11, 6))
ax = fig.add_subplot(1, 1, 1)
plt.xticks(rotation=45)
plt.title("Result Distribution")
plt.xlabel("Bitstrings (reversed)")
plt.ylabel("Probability")
ax.bar(list(final_bits.keys()), list(final_bits.values()), color="tab:grey")
for p in positions:
ax.get_children()[int(p[0])].set_color("tab:purple")
plt.show()

Output of the previous code cell

Beste Schnitt visualisiere

Aus dem optimale Bitstring kennet mr dann diese Schnitt auf dem ursprüngliche Graphen visualisiere.

# auxiliary function to plot graphs
def plot_result(G, x):
colors = ["tab:grey" if i == 0 else "tab:purple" for i in x]
pos, _default_axes = rx.spring_layout(G), plt.axes(frameon=True)
rx.visualization.mpl_draw(
G, node_color=colors, node_size=100, alpha=0.8, pos=pos
)

plot_result(graph, most_likely_bitstring)

Output of the previous code cell

Und berechnet de Wert vo dem Schnitt:

def evaluate_sample(x: Sequence[int], graph: rx.PyGraph) -> float:
assert len(x) == len(
list(graph.nodes())
), "The length of x must coincide with the number of nodes in the graph."
return sum(
x[u] * (1 - x[v]) + x[v] * (1 - x[u])
for u, v in list(graph.edge_list())
)

cut_value = evaluate_sample(most_likely_bitstring, graph)
print("The value of the cut is:", cut_value)
The value of the cut is: 5

Teil II. Skaliert's hoch!

Mr hend Zugang z'vielen Geräten mit über 100 Qubits auf dr IBM Quantum® Platform. Wählet oins aus, auf dem Max-Cut auf amm 100-Knoten-gewichtete Graphen glöst werde soll. Des isch a Problem im "Utility-Maßstab". D'Schritte zum Aufbau vo dem Workflow send d'gleiche wie obe, jedoch mit amm viel größere Graphen.

n = 100  # Number of nodes in graph
graph_100 = rx.PyGraph()
graph_100.add_nodes_from(np.arange(0, n, 1))
elist = []
for edge in backend.coupling_map:
if edge[0] < n and edge[1] < n:
elist.append((edge[0], edge[1], 1.0))
graph_100.add_edges_from(elist)
draw_graph(graph_100, node_size=200, with_labels=True, width=1)

Output of the previous code cell

Schritt 1: Klassische Eingabe auf a Quantenproblem abbilden

Graph → Hamilton-Operator

Konvertiert zunächst de Graphen, der gelöst werre soll, direkt in a Hamilton-Operator, wo für QAOA geeignet isch.

max_cut_paulis_100 = build_max_cut_paulis(graph_100)

cost_hamiltonian_100 = SparsePauliOp.from_sparse_list(max_cut_paulis_100, 100)
print("Cost Function Hamiltonian:", cost_hamiltonian_100)
Cost Function Hamiltonian: SparsePauliOp(['IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIZZ', 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIZZ', 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII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, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j,
1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j,
1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j,
1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j,
1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j,
1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j,
1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j,
1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j,
1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j])

Hamilton-Operator → Quantenschaltkreis

circuit_100 = QAOAAnsatz(cost_operator=cost_hamiltonian_100, reps=1)
circuit_100.measure_all()

circuit_100.draw("mpl", fold=False, scale=0.2, idle_wires=False)

Output of the previous code cell

Schritt 2: Problem für Quantenausführung optimiere

Um de Schaltkreis-Optimierungsschritt auf Utility-Scale-Probleme z'skaliere, kennet mr d'in Qiskit SDK v1.0 eiführte Hochleistungs-Transpilationsstrategien nutze. Weitere Werkzeuge umfasset de neie Transpiler-Service mit KI-erweiterte Transpiler-Pässen.

pm = generate_preset_pass_manager(optimization_level=3, backend=backend)

candidate_circuit_100 = pm.run(circuit_100)
candidate_circuit_100.draw("mpl", fold=False, scale=0.1, idle_wires=False)

Output of the previous code cell

Schritt 3: Ausführung mit Qiskit Primitives

Um QAOA ausz'führe, müsset mr d'optimale Parameter γk\gamma_k und βk\beta_k kenne, wo in de variationelle Schaltkreis eigesetzt werde sollet. Optimiert diese Parameter, indem a Optimierungsschleife auf dem Gerät ausgeführt wird. D'Zelle sendet Jobs, bis dr Wert vo dr Kostenfunktion konvergiert isch und d'optimale Parameter für γk\gamma_k und βk\beta_k bestimmt send.

Kandidatenlösung durch Ausführung vo dr Optimierung auf dem Gerät finde

Führet zunächst d'Optimierungsschleife für d'Schaltkreisparameter auf amm Gerät aus.

initial_gamma = np.pi
initial_beta = np.pi / 2
init_params = [initial_beta, initial_gamma]

objective_func_vals = [] # Global variable
with Session(backend=backend) as session:
# If using qiskit-ibm-runtime<0.24.0, change `mode=` to `session=`
estimator = Estimator(mode=session)

estimator.options.default_shots = 1000

# Set simple error suppression/mitigation options
estimator.options.dynamical_decoupling.enable = True
estimator.options.dynamical_decoupling.sequence_type = "XY4"
estimator.options.twirling.enable_gates = True
estimator.options.twirling.num_randomizations = "auto"

result = minimize(
cost_func_estimator,
init_params,
args=(candidate_circuit_100, cost_hamiltonian_100, estimator),
method="COBYLA",
)
print(result)
message: Return from COBYLA because the trust region radius reaches its lower bound.
success: True
status: 0
fun: -3.9939191365979383
x: [ 1.571e+00 3.142e+00]
nfev: 29
maxcv: 0.0

Sobald d'optimale Parameter aus dr Ausführung vo QAOA auf dem Gerät gfunde worre send, weist mr d'Parameter dem Schaltkreis z'.

optimized_circuit_100 = candidate_circuit_100.assign_parameters(result.x)
optimized_circuit_100.draw("mpl", fold=False, idle_wires=False)

Output of the previous code cell

Führet schließlich de Schaltkreis mit de optimale Parametern aus, um aus dr entsprechende Verteilung z'samplen.

# If using qiskit-ibm-runtime<0.24.0, change `mode=` to `backend=`
sampler = Sampler(mode=backend)
sampler.options.default_shots = 10000

# Set simple error suppression/mitigation options
sampler.options.dynamical_decoupling.enable = True
sampler.options.dynamical_decoupling.sequence_type = "XY4"
sampler.options.twirling.enable_gates = True
sampler.options.twirling.num_randomizations = "auto"

pub = (optimized_circuit_100,)
job = sampler.run([pub], shots=int(1e4))

counts_int = job.result()[0].data.meas.get_int_counts()
counts_bin = job.result()[0].data.meas.get_counts()
shots = sum(counts_int.values())
final_distribution_100_int = {
key: val / shots for key, val in counts_int.items()
}

Überprüft, dass d'in dr Optimierungsschleife minimierten Kosten auf a bestimmte Wert konvergiert send.

plt.figure(figsize=(12, 6))
plt.plot(objective_func_vals)
plt.xlabel("Iteration")
plt.ylabel("Cost")
plt.show()

Output of the previous code cell

Schritt 4: Nachbearbeitung und Rückgabe vo dem Ergebnis im gwünschte klassische Format

Da d'Wahrscheinlichkeit vo jeder Lösung gering isch, extrahiert mr d'Lösung, wo de niedrigste Kosten entspricht.

_PARITY = np.array(
[-1 if bin(i).count("1") % 2 else 1 for i in range(256)],
dtype=np.complex128,
)

def evaluate_sparse_pauli(state: int, observable: SparsePauliOp) -> complex:
"""Utility for the evaluation of the expectation value of a measured state."""
packed_uint8 = np.packbits(observable.paulis.z, axis=1, bitorder="little")
state_bytes = np.frombuffer(
state.to_bytes(packed_uint8.shape[1], "little"), dtype=np.uint8
)
reduced = np.bitwise_xor.reduce(packed_uint8 & state_bytes, axis=1)
return np.sum(observable.coeffs * _PARITY[reduced])

def best_solution(samples, hamiltonian):
"""Find solution with lowest cost"""
min_cost = 1000
min_sol = None
for bit_str in samples.keys():
# Qiskit use little endian hence the [::-1]
candidate_sol = int(bit_str)
# fval = qp.objective.evaluate(candidate_sol)
fval = evaluate_sparse_pauli(candidate_sol, hamiltonian).real
if fval <= min_cost:
min_sol = candidate_sol

return min_sol

best_sol_100 = best_solution(final_distribution_100_int, cost_hamiltonian_100)
best_sol_bitstring_100 = to_bitstring(int(best_sol_100), len(graph_100))
best_sol_bitstring_100.reverse()

print("Result bitstring:", best_sol_bitstring_100)
Result bitstring: [1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1]

Visualisiert als Nächsts de Schnitt. Knoten vo dr gleiche Farb ghöre zur gleiche Gruppe.

plot_result(graph_100, best_sol_bitstring_100)

Output of the previous code cell

Berechnet de Wert vo dem Schnitt.

cut_value_100 = evaluate_sample(best_sol_bitstring_100, graph_100)
print("The value of the cut is:", cut_value_100)
The value of the cut is: 124

Jetzt müsset mr de Zielfunktionswert vo jeder Probe berechne, wo auf dem Quantencomputer gmesse worre send. D'Probe mit dem niedrigste Zielfunktionswert isch d'vom Quantencomputer zurückgegebene Lösung.

# auxiliary function to help plot cumulative distribution functions
def _plot_cdf(objective_values: dict, ax, color):
x_vals = sorted(objective_values.keys(), reverse=True)
y_vals = np.cumsum([objective_values[x] for x in x_vals])
ax.plot(x_vals, y_vals, color=color)

def plot_cdf(dist, ax, title):
_plot_cdf(
dist,
ax,
"C1",
)
ax.vlines(min(list(dist.keys())), 0, 1, "C1", linestyle="--")

ax.set_title(title)
ax.set_xlabel("Objective function value")
ax.set_ylabel("Cumulative distribution function")
ax.grid(alpha=0.3)

# auxiliary function to convert bit-strings to objective values
def samples_to_objective_values(samples, hamiltonian):
"""Convert the samples to values of the objective function."""

objective_values = defaultdict(float)
for bit_str, prob in samples.items():
candidate_sol = int(bit_str)
fval = evaluate_sparse_pauli(candidate_sol, hamiltonian).real
objective_values[fval] += prob

return objective_values
result_dist = samples_to_objective_values(
final_distribution_100_int, cost_hamiltonian_100
)

Schließlich kennet mr d'kumulative Verteilungsfunktion plotte, um z'visualisiere, wie jede Probe z'r gesamte Wahrscheinlichkeitsverteilung beiträgt und dem entsprechende Zielfunktionswert. D'horizontale Streuung zeigt de Bereich vo de Zielfunktionswerte vo de Proben in dr finalen Verteilung. Idealerweise würdet mr sehe, dass d'kumulative Verteilungsfunktion "Sprünge" am untere Ende vo dr Zielfunktionswert-Achse hend. Des würde bedeute, dass wenig Lösunge mit niedrige Kosten a hohe Wahrscheinlichkeit hend, gsampelt z'werde. A glatte, breite Kurve zeigt a, dass jede Probe ähnlich wahrscheinlich isch und se sehr unterschiedliche Zielfunktionswerte hend kennet, niedrig oder hoch.

fig, ax = plt.subplots(1, 1, figsize=(8, 6))
plot_cdf(result_dist, ax, "Eagle device")

Output of the previous code cell

Fazit

Des Tutorial hend demonstriert, wie mer a Optimierungsproblem mit amm Quantencomputer unter Verwendung vo dem Qiskit Patterns Framework löst. D'Demonstration hend a Beispiel im Utility-Maßstab enthalt mit Schaltkreisgrößen, wo ned exakt klassisch simuliert werde kennet. Derzeit übertreffet Quantencomputer klassische Computer bei kombinatorischer Optimierung aufgrund vo Rauschen ned. D'Hardware verbessert sich aber stetig, und neie Algorithmen für Quantencomputer werde kontinuierlich entwickelt. In dr Tat wird a Großteil vo dr Forschung, wo an Quantenheuristiken für kombinatorische Optimierung arbeitet, mit klassische Simulatione getestet, wo nur a kleini Anzahl vo Qubits erlaubet, typischerweise etwa 20 Qubits. Jetzt, mit größere Qubit-Zahlen und Geräten mit weniger Rauschen, werde Forscher in dr Lage sei, diese Quantenheuristiken bei große Problemgrößen auf Quanten-Hardware z'benchmarken.

Tutorial-Umfrage

Bitte nehmets an derer kurze Umfrage teil, um Feedback z'diesem Tutorial z'gebe. Dei Erkenntnisse werden uns helfe, unsere Inhaltsangebote und Benutzererfahrung z'verbessere.

Link z'r Umfrage