Zum Haubtinhald schringsn

Quantenannähernder Optimierungsalgorithmus

Zeitschätzung: 22 Minutn uffm Heron-r3-Prozessor (HINWEIS: Nur 'ne Schätzung — dei tatschächliche Laafzeit gann variieren.)

Hindergrund

Deser Tutorial zeegt, wie de'n Quantum Approximate Optimization Algorithm (QAOA) — 'ne hybride (quanten-glassische) iterative Methode — innerhalbb vom Qiskit-Patterns-Rahmen implementiern gannst. Erschd löse mer 's Maximum-Cut (oder Max-Cut)-Probläm fier'n gleenen Graphn, un dann lernste, wie de's im Utility-Maßschdoab ausfiehrn gannst. Alle Hardware-Ausfiehrungen im Tutorial solltn innerhalbb vom Zeitlimit vom frei zugänglischn Open Plan laafen.

's Max-Cut-Probläm is'n Obtimierungsprobläm, was schwersch ze lösn is (genauer gesachd: 's is'n NP-schweres Probläm) mit vielerlei Oowendungen in Clustering, Netzwärgwissnschaft un schtatistischer Fieesig. In däm Tutorial betrachtn mer'n Graphn aus Knootn, die dursch Gäntn mitnanander verbundn sinn, un woll'n die Knootn in zwee Mengen aufdeeln, sodass die Oonzahl von Gäntn, die von däm Schnitt durschqueert wärn, maximiert wird.

Illustratschn von'm Max-Cut-Probläm

Vorraussetzungen

Bevorn de mit däm Tutorial oogängst, schau nach, dass de Folschndes installierd hast:

  • Qiskit SDK v1.0 oder neeer, mit Unnerstietzung fier Visualisieerung
  • Qiskit Runtime v0.22 oder neeer (pip install qiskit-ibm-runtime)

Außerdem brauchste Zugrieff uff'ne Instanz uff der IBM Quantum Platform. Beaachte, dass deser Tutorial ned im Open Plan ausgefiehrd wärn gann, weil er Workloads mit Sessions verweendt, was nur mit dem Premium-Plan zugelassn is.

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

Deel I. QAOA im gleenen Maßschdoab

Der erschde Deel von däm Tutorial nutzt'n Max-Cut-Probläm im gleenen Maßschdoab, um die Schritte ze zeechn, mit denen mer'n Obtimierungsprobläm uff'm Quantecomputer lösd.

Um 'n bissle Hintergrund ze criegen, bevorm mer das Probläm uff'n Quantealgorithmus abbildn, gann mer bässer verstehn, wie's Max-Cut-Probläm zu 'nem glassischn kombinatorischn Obtimierungsprobläm wird — oofongt mer damit, die Minimierung von ner Funktschen f(x)f(x) ze betrachtn:

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

dabei is der Eingabewärd xx 'n Vektor, dassen Gombonentn jeweels 'nem Gnotn vom Graphn entsprechn. Dann schränkn mer jede von dene Gombonentn uff 00 oder 11 ein (was bedeit: drin oder nisch drin im Schnitt). Deser gleene Beispielfall nutzt 'n Graphn mit n=5n=5 Knootn.

Mer könnte 'ne Funktschen fier 'n Knootnpaar i,ji,j schreibn, die zeecht, ob die entsprechennte Gante (i,j)(i,j) im Schnitt is. Zum Beispiel is die Funktschen xi+xj2xixjx_i + x_j - 2 x_i x_j genau dann 1, wenn entweder xix_i oder xjx_j gleich 1 is (was bedeit, die Gante is im Schnitt), un sonnst null. 's Probläm, die Oonzahl von Gäntn im Schnitt ze maximiern, läsd sich formuliern 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 sich als 'ne Minimierung umschreebm lässd:

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.

's Minimum von f(x)f(x) lieecht hier vor, wenn die Oonzahl der Gäntn, die vom Schnitt durschqueert wärn, maximal is. Wie de siehst, hat das noch nix mit Quantecomputing ze du. Mer müssn das Probläm in was umformuliern, was'n Quantecomputer vastehn gann. Fang mit der Initialisierung von deim Probläm oo, indeem de'n Graphn mit n=5n=5 Knootn erstellst.

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)

Ausgabe der vorherigen Code-Zälle

Schritt 1: Glassische Eingabn uff's Quanteprobläm abbildn

Der erschde Schritt vom Musder is es, 's glassische Probläm (Graphn) in quantemäßsche Circuits un Operatorn umzuwandln. Dafier gibt's drei Hauptschritte:

  1. 'Ne Reihe von mathematischn Umformulierungen verwennd, um das Probläm in der Notatschn von Quadratic Unconstrained Binary Optimization (QUBO)-Problähmn darzustelln.
  2. 's Obtimierungsprobläm als Hamiltonian umschreebm, dassen Grundsuschstand der Lösung entspricht, die die Gostenfunktschen minimiert.
  3. 'Nen Quantecircuit erstell, der'n Grundsuschstand von däm Hamiltonian dursch'n Vorgang ähnlich der Quantenglüehung voorbereidt.

Hinweis: Bei der QAOA-Methodik willste letztlich 'nen Operator (Hamiltonian) habn, der die Gostenfunktschen von unserm hybriden Algorithmus darstellt, sowie 'nen parametrisierten Circuit (Ansatz), der Quantenzustände mit Kandidatenlösungen fier 's Probläm darstellt. De gannst von dene Kandidatenzuständn sampln un sie dann mit der Gostenfunktschen auswärtn.

Graph → Obtimierungsprobläm

Der erschde Schritt beim Abbildn is 'n Notatschnswäggsel. Das Folschnde drückt 's Probläm in QUBO-Notatschn aus:

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

dabei is QQ 'ne n×nn\times n-Matrix aus reellen Zahln, nn entspricht der Oonzahl von Knootn in deim Graphn, xx is der Vektor von binären Variabln, den mer schon kenntngelärnd habn, un xTx^T bedeutet die Transbosiertng von Vektor xx.

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

Obtimierungsprobläm → Hamiltonian

Dann gannste 's QUBO-Probläm als Hamiltonian umformuliern (hier 'ne Matrix, die die Energie von'm System darstellt):

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

Umformulierungsschritte vom QAOA-Probläm zum Hamiltonian

Um ze zeechn, wie's QAOA-Probläm uff diese Weise umgeschrieebm wärn gann, tausch erschd die binären Variabln xix_i dursch 'ne neie Mengn von Variabln zi{1,1}z_i\in\{-1, 1\} aus, via:

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

Hier gannste sehn, dass wenn xix_i gleich 00 is, dann muss ziz_i gleich 11 sinn. Wenn die xix_i's dursch die ziz_i's im Obtimierungsprobläm (xTQxx^TQx) erseztd wärn, lässd sich 'ne äquivalente Formulierung ablaeidn.

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}) definiern, 'n Vorfaktor wegläsn un'n gonschdantn n2n^2-Term, goommt mer bei zween äquivalentn Formulierungen von demselbn Obtimierungsprobläm oo.

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

Hier hängt bb von QQ ab. Beaachte, dass mer zum Erhaaldn von zTQz+bTzz^TQz + b^Tz den Faktor 1/4 un 'n gonschdantn Versatz n2n^2 weggläsn haabn, die bei der Obtimierung kenne Rolle spieln.

Jetzt, um 'ne Quantenformulierung von'm Probläm ze kriengn, befördert mer die ziz_i-Variabln zu 'ner Pauli-ZZ-Matrix, etwa 'ner 2×22\times 2-Matrix der Form:

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

Wenn de diese Matrizen in 's Obtimierungsprobläm obn eiführst, griggte de'n Hamiltonian:

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

Dazu erinnern: Die ZZ-Matrizen sinn in'n Berechnungsraum vom Quantecomputer eingebedded, also in'n Hilbert-Raum der Größe 2n×2n2^n\times 2^n. Deshalbb sollde de Ausdrieck wie ZiZjZ_iZ_j als Tensorprodukt ZiZjZ_i\otimes Z_j verstehn, das in'n 2n×2n2^n\times 2^n-Hilbert-Raum eingebedded is. Bei 'nem Probläm mit fünf Entscheeidungsvariabln wird der Ausdruck Z1Z3Z_1Z_3 zum Beispiel als IZ3IZ1II\otimes Z_3\otimes I\otimes Z_1\otimes I verstannd, wobei II die 2×22\times 2-Identitätsmatrix is.

Deser Hamiltonian wird als der Gostenfunktschn-Hamiltonian bezäächnet. Er hat die Eigenschaft, dass sein Grundsuschstand der Lösung entspricht, die die Gostenfunktschen f(x)f(x) minimiert. Um dein Obtimierungsprobläm ze lösn, musste jetzt'n Grundsuschstand von HCH_C (oder 'nen Zustand mit hoher Übberlappung damit) uff'm Quantecomputer voorbereeidn. Dann wird 's Sampln von däm Zustand mit hoher Wahrscheinlichkeet die Lösung fier min f(x)min~f(x) liefern. Betrachtn mer jetzt'n Hamiltonian HCH_C fier's Max-Cut-Probläm. Jedem Knootn vom Graphn is 'n Qubit im Zustand 0|0\rangle oder 1|1\rangle zugeordnet, wobei der Wärd die Mengn oogibt, der Gnotn zugehört. 's Ziel vom Probläm is es, die Oonzahl der Gäntn (v1,v2)(v_1, v_2) ze maximiern, bei denen v1=0v_1 = |0\rangle un v2=1v_2 = |1\rangle gilt, oder umgekährd. Wenn mer'n ZZ-Operator jedem Qubit zuordnet, wobei:

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

dann gehört 'ne Gante (v1,v2)(v_1, v_2) genau dann zum Schnitt, wenn der Eigenwärd von (Z1v1)(Z2v2)=1(Z_1|v_1\rangle) \cdot (Z_2|v_2\rangle) = -1 is; mit annern Wortn, die Qubits von v1v_1 un v2v_2 sinn verschieden. Genauso gehört (v1,v2)(v_1, v_2) ned zum Schnitt, wenn der Eigenwärd von (Z1v1)(Z2v2)=1(Z_1|v_1\rangle) \cdot (Z_2|v_2\rangle) = 1 is. Beaachte, dass's uns ned uff'n genaun Quantezustand von jedem Gnotn ookommt, sunnern nur darauf, ob se übbr 'ne Gante gleich oder verschieden sinn. 's Max-Cut-Probläm ferderd, 'ne Zuweisung von Qubits uff Knootn ze findn, sodass der Eigenwärd von folschndem Hamiltonian minimiert wird:

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

Mit annern Wortn: bi=0b_i = 0 fier alle ii beim Max-Cut-Probläm. Der Wärd QijQ_{ij} gibt's Gewicht von der Gante oo. In däm Tutorial betrachtn mer'n ungewichttn Graphn, also Qij=1.0Q_{ij} = 1.0 fier alle 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])

Hamiltonian → Quantencircuit

Der Hamiltonian HCH_C enthält die quantenmäßsche Definition von deim Probläm. Jetzt gannste'n Quantencircuit erstellen, der dabei hälft, gute Lösngen vom Quantecomputer zu sampln. Der QAOA is von der Quantenglüehung inspiriert un bringt abwechselnd Schichtn von Operatorn in'n Quantencircuit.

Die Grundidee is, im Grundsuschstand von'nem bekannten System zu startn, Hn0H^{\otimes n}|0\rangle obn, un dann 's System in'n Grundsuschstand vom Gostenoperator ze lenkn. Das passiert, indeem mer die Operatorn exp{iγkHC}\exp\{-i\gamma_k H_C\} un exp{iβkHm}\exp\{-i\beta_k H_m\} mit Winkeln γ1,...,γp\gamma_1,...,\gamma_p un β1,...,βp \beta_1,...,\beta_p~ oowendet.

Der Quantencircuit, den de erstellst, is parametrisiert nach γi\gamma_i un βi\beta_i, sodass de verschiednne Wärde fier γi\gamma_i un βi\beta_i ausprobieern un vom Ergebniszustand sampln gannst.

Circuit-Diagramm mit QAOA-Schichtn

In däm Fall probierste'n Beispiel mit einer QAOA-Schicht, die zween Parameter enthält: γ1\gamma_1 un β1\beta_1.

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

circuit.draw("mpl")

Ausgabe der vorherigen Code-Zälle

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

Schritt 2: Probläm fier die Quantehardwareausfiehrung obtimieern

Der Circuit obn enthält 'ne Reihe von Abstraktschonen, die nitzlich is, um übbr Quantealgorithmn nachzedenggn, aber ned uff der Hardware ausgefiehrd wärn gann. Um uff'm QPU laafen ze gönnen, muss der Circuit 'ne Reihe von Oberatschonen durchlaafen, die den Transpilatschn- oder Circuit-Obtimierung-Schritt vom Muster ausmachn.

Die Qiskit-Bibliotheg bietet 'ne Reihe von Transpilatschnspässen, die 'ne breitere Palette von Circuit-Transformatschn abdeckn. De musst sicherstelln, dass dein Circuit fier deinen Zweck obtimiert is.

Die Transpilatschn gann meehrere Schritte umfassn, wie:

  • Initiale Abbildung der Qubits im Circuit (zum Beispiel Entscheeidungsvariabln) uff physische Qubits uff'm Gerät.
  • Entfaltung der Instruktschonen im Quantencircuit in die hardware-nativen Instruktschonen, die das Backend vastehd.
  • Routing von Qubits im Circuit, die mitnanander interagieern, zu physischn Qubits, die nebenanandr liengn.
  • Fählerunnerdrickung dursch Hinzufiengn von Single-Qubit-Gates zur Rauschunnerdrickung mit dynamischem Entkoppln.

Mehr Informatschn iebr Transpilatschn finddste in unsern Dokus.

Der folschnde Code transformiert un obtimiert'n abstraktn Circuit in 'n Format, das bereit zur Ausfiehrung uff einem der übbr die Cloud zugänglischn Geräte is — mit dem Qiskit IBM Runtime-Dienscht.

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')>

Ausgabe der vorherigen Code-Zälle

Schritt 3: Ausfiehrung mit Qiskit-Primitiven

Im QAOA-Workflow wärn die obtimalen QAOA-Parameter in 'ner iterativen Obtimierungsschleife gefundn, die 'ne Reihe von Circuit-Auswärtngen ausfiehrd un 'nen glassischn Optimierer nutzd, um die obtimalen βk\beta_k- un γk\gamma_k-Parameter ze findn. Diese Ausfiehrungsschleife wird in folschnden Schrittn ausgefiehrd:

  1. Die Anfangsparameter definiern
  2. 'Ne neie Session instantiiern, die die Obtimierungsschleife un 's Primitive zum Sampln vom Circuit enthält
  3. Sobald 'n optimaler Parametersatz gefundn wurrd, führt mer'n Circuit noch mal aus, um 'ne endgültige Värdeilung ze criengn, die im Noochbarbeeitungsschritt verweendd wird.

Circuit mit Anfangsparametern definiern

Mer starn mit willkürlich gewählten Parametern.

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

Backend un Ausfiehrungsprimitiv definiern

Nutz die Qiskit Runtime-Primitive, um mit IBM®-Backends ze interagieern. Die zwee Primitive sinn Sampler un Estimator, un die Wahl vom Primitiv hängt davon ab, welche Art von Mässung de uff'm Quantecomputer machen willst. Fier die Minimierung von HCH_C nutzde'n Estimator, weil die Mässung der Gostenfunktschen eenfach dem Erwartungswärd HC\langle H_C \rangle entspricht.

Ausfiehrn

Die Primitive bieten vielerlei Ausfiehrungsmodi zum Plaanen von Workloads uff Quantegerätn, un'n QAOA-Workflow läfd iterativ in 'ner Session.

Illustratschn, die &#39;s Verhaltn von Single-Job-, Batch- un Session-Laufzeitmodi zeeched.

De gannst die sampler-basierte Gostenfunktschen in die SciPy-Minimierungsroutine eieplugn, um die obtimalen Parameter ze findn.

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

Der Optimierer hat's geschaffd, die Gostn ze reduziern un bässere Parameter fier'n Circuit ze findn.

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

Ausgabe der vorherigen Code-Zälle

Sobald de die obtimalen Parameter fier'n Circuit gefundn hast, gannste diese Parameter zuweisn un die endgültige Värdeilung sampln, die mit den obtimiertn Parametern entstehd. Hier sollde'n Sampler-Primitiv genutzd wärn, weil's die Wahrscheinlichkeedsvärdeilung von Bitstring-Mässungen is, die dem obtimalen Schnitt vom Graphn entsprichn.

Hinweis: Das bedeit, 'nen Quantenzustand ψ\psi im Computer voorzubereeidn un ihn dann ze mässn. 'Ne Mässung kollabiert'n Zustand uff 'nen einzeln Berechnungsbasissuschstand — zum Beispiel 010101110000... — was 'ner Kandidatenlösung xx fier unser Ursprungsoptimierungsprobläm entspricht (maxf(x)\max f(x) oder minf(x)\min f(x), je nach Aufgabe).

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

Ausgabe der vorherigen Code-Zälle

# 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: Noochbarbeitung un Rückgoabe vom Ergebnis im gewünschtn glassischn Format

Der Noochbarbeeitungsschritt interpretierd die Sampling-Ausgabe, um 'ne Lösung fier dein ursprünglisches Probläm zurückzegeebm. In däm Fall interessiert dich der Bitstring mit der höchstn Wahrscheinlichkeet, weil der'n obtimalen Schnitt bestimmt. Durch die Symmetrien im Probläm gibt's vier mögliche Lösngen, un 's Sampling-Verfahrn lied eine davon mit etwas höherer Wahrscheinlichkeet zurück — aber wie de in der Värdeilungsdarstellung unten siehst, sinn vier Bitstrings deutlich wahrscheinlicher als der 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()

Ausgabe der vorherigen Code-Zälle

Besctn Schnitt visualisiern

Vom obtimalen Bitstring aus gannste dann desen Schnitt uff'm ursprünglischn Graphn visualisiern.

# 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)

Ausgabe der vorherigen Code-Zälle

Un berächne den Wärd vom 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

Deel II. Jetzt uff groß!

De hast Zugrieff uff viele Geräte mit übbr 100 Qubits uff IBM Quantum® Platform. Wähl eens aus, uff dem de Max-Cut uff'm 100-Gnotn-gewichttn Graphn lösen willst. Das is'n „Utility-Scale"-Probläm. Die Schritte zum Aufbau von'm Workflow sinn dieselbn wie obn, aber mit'nem viel größern Graphn.

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)

Ausgabe der vorherigen Code-Zälle

Schritt 1: Glassische Eingabn uff's Quanteprobläm abbildn

Graph → Hamiltonian

Wandel zunächst den Graphn, denn de lösn willst, direkt in 'nen Hamiltonian um, der fier QAOA geeignet is.

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(['IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII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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, 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])

Hamiltonian → Quantencircuit

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)

Ausgabe der vorherigen Code-Zälle

Schritt 2: Probläm fier die Quanteausfiehrung obtimieern

Um den Circuit-Obtimierungsschritt uff Utility-Scale-Problähmn hochzusgaliern, gannste die hoochleistungsfähigen Transpilatschnssdrategien nutzn, die mit Qiskit SDK v1.0 eingefiert wordn sinn. Weitere Tools sinn der neue Transpilerdienst mit KI-verbässerten Transpilatschnspässn.

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)

Ausgabe der vorherigen Code-Zälle

Schritt 3: Ausfiehrung mit Qiskit-Primitiven

Um QAOA auszufiehrn, musste die obtimalen Parameter γk\gamma_k un βk\beta_k wissn, die in'n variatschen Schaltkreis reinkommn. Obtimier diese Parameter, indeem de'ne Obtimierungsschleife uff'm Gerät ooläfst. Die Zälle schiggd Jobs, bis der Gostenfunktschnswärd konvergiert is un die obtimalen Parameter fier γk\gamma_k un βk\beta_k bestimmt wordn sinn.

Kandidatenlösung durch Ooläfn der Obtimierung uff'm Gerät findn

Erschd loo de Obtimierungsschleife fier die Circuit-Parameter uff'm Gerät oo.

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 die obtimalen Parameter vom Ooläfn von QAOA uff'm Gerät gefundn wordn sinn, weise die Parameter dem Circuit zu.

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

Ausgabe der vorherigen Code-Zälle

Zum Schluss führe'n Circuit mit den obtimalen Parametern aus, um aus der entsprechendn Värdeilung ze sampln.

# 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()
}

Prief nach, ob die Gostn in der Obtimierungsschleife uff'n beschtimmdn Wärd konvergierd sinn.

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

Ausgabe der vorherigen Code-Zälle

Schritt 4: Noochbarbeitung un Rückgoabe vom Ergebnis im gewünschtn glassischn Format

Da die Wahrscheinlichkeet fier jede Lösung gering is, zieh die Lösung raus, die den niedrigschn Gostn 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]

Als nächstes visualisier'n Schnitt. Knootn von derselbn Farbe ghörn zesamm zu einer Gruppe.

plot_result(graph_100, best_sol_bitstring_100)

Ausgabe der vorherigen Code-Zälle

Beräächne den Wärd vom 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 musste den Zielwärd von jedem Sample beräächnen, das de uff'm Quantecomputer gemässn hast. Das Sample mit dem niedrigschn Zielwärd is die vom Quantecomputer zurückgegeebne 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
)

Zum Schluss gannste die kumulative Värdeilungsfunktschen plotten, um ze sehn, wie jedes Sample zur Gesamtwahrscheinlichkeedsvärdeilung un zum entsprechendn Zielwärd beiträcht. Die horizontale Breite zeeged die Spannweite der Zielwärde der Samples in der Endvärdeilung. Idealerweise würdste sehn, dass die kumulative Värdeilungsfunktschen am untern Ende der Zielwärdachse „Sprüng" macht. Das würde bedeein, dass wenige Lösngen mit geringen Gostn 'ne hohe Wahrscheinlichkeet habn, gesampled ze wärn. 'Ne glatte, breite Gurve deutet drauf hin, dass jedes Sample ähnlich wahrscheinlich is un sehr verschiednne Zielwärde, niedrig oder hoch, habn gann.

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

Ausgabe der vorherigen Code-Zälle

Schlussfolgerung

Deser Tutorial hat gezeecht, wie mer'n Obtimierungsprobläm mit'nem Quantecomputer lösd — mithilfe vom Qiskit-Patterns-Rahmen. Die Demonstration hat'n Utility-Scale-Beispiel eigeschlossn, mit Circuit-Größn, die glassisch ned exakt simuliert wärn gönnen. Im Augenblick übertreefn Quantecomputer glassische Rechner bei der kombinatorischn Obtimierung ned, wegen Rauschn. Aber die Hardware verbässert sich schrittweis, un neue Algorithmen fier Quantecomputer wärn ständig entwickeld. Tatsächlich wird viel Forschung uff hybride Quanteheuristiken fier kombdinatorische Obtimierung mit glassischn Simulatschonen durchgefiert, die nur 'ne gleene Oonzahl von Qubits zulassn, typischerweis um die 20 Qubits. Jetzt, mit größern Qubitoonzahln un Gerätn mit weniger Rauschn, wärn Forscher oofongen gönnen, diese Quanteheuristiken bei großn Problähmgrößn uff Quantehardware ze benchmargn.

Tutorial-Umfrage

Bitte nimm dir kurz Zeit fier diese gheeze Umfrage, um Feedback zu däm Tutorial ze geebm. Deine Einschätzung hälft uns, unser Angebot un die Nutzerärfahrung ze verbässern.

Link zur Umfrage