Zum Hauptinhalt springe

Quante-Näherungs-Optimierungsalgorithmus

Zitschätzig: 22 Minute uf emene Heron-r3-Prozässor (HINWYS: Das isch nur e Schätzig. Dini Uusfüehrigszit cha abwiiche.)

Hintergrund

Dä Tutorial zeigt, wie mer de Quante-Näherungs-Optimierungsalgorithmus (QAOA) — e hybride (quante-klassischi) iterativi Methode — im Rahme vo Qiskit-Patterns umsetzt. Du lösch zerschte s'Maximum-Cut- (oder Max-Cut-) Problem für e chline Graph und lernsch de, wie mer's in Utility-Scale uusfüehre cha. Alli Hardware-Uusfüehrige im Tutorial sötte innerhalb vom Zitlimit vom frei zugängliche Open Plan laafe.

S'Max-Cut-Problem isch es Optimierungsproblem, wo schwer z'löse isch (genauer gseit, isch's es NP-schweres Problem) mit verschiedene Aawändigsfäll im Clustering, i de Netzwärchwiisseschaft und i dr statistische Physik. Dä Tutorial betrachtet ene Graph vo Knöte, wo dur Kante verbunde sind, und wott d'Knöte in zwee Mengene ufteile, sodass d'Aaazahl vo de dur dä Schnitt duerquärte Kante maximiert wird.

Illustratio vom Max-Cut-Problem

Voraussetzige

Bevor du mit däm Tutorial afangsch, vergewisseri dich, dass du s'Folgende installiert hesch:

  • Qiskit SDK v1.0 oder neuer, mit Unterstitzig für Visualisieriig
  • Qiskit Runtime v0.22 oder neuer (pip install qiskit-ibm-runtime)

Zudem bruuchsch du Zuegriff uf e Instanz uf de IBM Quantum Platform. Bitte beachte, dass dä Tutorial nöd im Open Plan uusgfüehrt wärde cha, will er Workloads mit Sessions betribt, wo nur im Premium Plan verfüegbar sind.

Setup

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 chline Massstab

Im erschte Teil vo däm Tutorial wird e chlinmassstäblichs Max-Cut-Problem bruucht, zum d'Schritte zum Löse vomeme Optimierungsproblem mit emene Quantecomputer z'illustriere.

Um etwas Kontext z'gäh, bevor mer das Problem uf ene Quantealgorithmus abbilde, cha mer s'Max-Cut-Problem besser als klassischs kombinatorischs Optimierungsproblem verstah, indem mer zerschte d'Minimierig vomere Funktion f(x)f(x) betrachtet

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

wo dr Iiput xx en Vektor isch, desse Komponente de Knöte vom Graph entspreche. De Beschränkt jedi vo dene Komponente uf 00 oder 11 (was bedütet, dass si im Schnitt drinn oder nöd drinn sind). Dises chline Bispiil nimmt ene Graph mit n=5n=5 Knöte.

Du chasch e Funktion vomeme Paar vo Knöte i,ji,j schriibe, wo azeigt, ob d'entsprechende Kante (i,j)(i,j) im Schnitt isch. Zum Bispiil isch d'Funktion xi+xj2xixjx_i + x_j - 2 x_i x_j nur denn 1, wenn entweder xix_i oder xjx_j gleich 1 isch (was bedütet, dass d'Kante im Schnitt isch), und sonsch 0. S'Problem vom Maximiere vo de Kante im Schnitt cha so formuliert wärde:

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 Minimierig umgschriibe wärde cha:

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 vo f(x)f(x) isch i däm Fall denn, wenn d'Aaazahl vo de dur de Schnitt duerquärte Kante maximal isch. Wie du gsesch, het das no nüüt mit Quantecomputing z'tüe. Du muesch das Problem in öppis umformuliere, wo e Quantecomputer verstah cha. Initialisier dis Problem, indem du ene Graph mit n=5n=5 Knöte erstellsch.

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)

Uusgab vo de vorherige Code-Zälle

Schritt 1: Klassischi Iiput uf es Quanteproblem abbilden

Dr erschte Schritt vom Pattern isch s'Abbilde vom klassische Problem (Graph) uf Quanteschaltkreis und Operatore. Dafür git's drei Hauptschritte:

  1. E Reihe vo mathematische Umformulierige nutze, zum das Problem in dr Notation vo Quadratic Unconstrained Binary Optimization (QUBO) darzstelle.
  2. S'Optimierungsproblem als Hamiltonian umschriibe, desse Grundzuestand dr Lösig entspricht, wo d'Kostenfunktion minimiert.
  3. Ene Quanteschaltkreis erstelle, wo de Grundzuestand vo däm Hamiltonian dur en ähnliche Prozäss wie Quanteannealing vorbereitet.

Hinwys: Bim QAOA-Verfahre witt du schlussändlich ene Operator (Hamiltonian) ha, wo d'Kostenfunktion vo uusem hybride Algorithmus repräsentiert, sowie ene parametrisierte Schaltkreis (Ansatz), wo Quantezueständ mit Kandidatenlösige für s'Problem darstellt. Du chasch von dene Kandidatenzueständ samplen und si de mit dr Kostenfunktion bewärte.

Graph → Optimierungsproblem

Dr erschte Schritt bim Abbilde isch e Notationsänderig. S'Folgende drückt das Problem in QUBO-Notation uus:

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

wo QQ e n×nn\times n-Matrix vo reelle Zahle isch, nn dr Aaazahl vo Knöte im Graph entspricht, xx dr Vektor vo binäre Variabele isch, wie oben iiigfüehrt, und xTx^T de Transposita vom Vektor xx bedütet.

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 → Hamiltonian

Du chasch s'QUBO-Problem de als Hamiltonian umformuliere (hie e Matrix, wo d'Energie vomeme System repräsentiert):

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

Umformulierigs-Schritte vom QAOA-Problem zum Hamiltonian

Um z'zeige, wie das QAOA-Problem so umgschriibe wärde cha, ersetzt mer zerschte d'binäre Variabele xix_i dur e neui Satz vo Variabele zi{1,1}z_i\in\{-1, 1\} via

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

Hie gsiehsch, dass wenn xix_i gleich 00 isch, ziz_i gleich 11 sy mueß. Wenn d'xix_i's dur d'ziz_i's im Optimierungsproblem (xTQxx^TQx) ersetzt wärde, chan mer e äquivalenti Formulierig erhalte.

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}) definiert, de Vorfaktor weglaat und de konstante n2n^2-Term entfernt, chöme mer zu de zwee äquivalente Formulierige vom gliche 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

Hie hängt bb vo QQ ab. Beachte, dass zum Erhalte vo zTQz+bTzz^TQz + b^Tz dr Faktor 1/4 und e konstante Verschiebig vo n2n^2 weggloo worde sind, wo bi dr Optimierig kei Rolle spieled.

Um jetzt e Quanteformulierig vom Problem z'erhalte, wärde d'ziz_i-Variabele zu Pauli-ZZ-Matrize befördert, also zu 2×22\times 2-Matrize vo dr Form

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

Wenn du die Matrize im Optimierungsproblem oben iisetzt, erhälsch de folgende Hamiltonian

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

Vergiss ou nöd, dass d'ZZ-Matrize im rechnerische Raum vom Quantecomputer iibettet sind, also im Hilbert-Raum dr Grösse 2n×2n2^n\times 2^n. Drum söttsch Ausdrück wie ZiZjZ_iZ_j als Tensorprodukt ZiZjZ_i\otimes Z_j iibettet im 2n×2n2^n\times 2^n-Hilbert-Raum verstah. Zum Bispiil isch dr Term Z1Z3Z_1Z_3 bi emem Problem mit füüf Entscheidigsvariabele als IZ3IZ1II\otimes Z_3\otimes I\otimes Z_1\otimes I z'verstah, wo II d'2×22\times 2-Identitätsmatrix isch.

Dä Hamiltonian wird dr Kostenfunktions-Hamiltonian gnennt. Er het d'Eigenschaft, dass sy Grundzuestand dr Lösig entspricht, wo d'Kostenfunktion f(x)f(x) minimiert. Drum muesch jetzt, zum dis Optimierungsproblem z'löse, de Grundzuestand vo HCH_C (oder en Zuestand mit grossem Üüberlappig damit) uf em Quantecomputer vorbereite. S'Samplen von däm Zuestand wird de mit hoher Wahrschynlichkeit d'Lösig für min f(x)\min~f(x) ergäh. Mir betrachte jetzt de Hamiltonian HCH_C für s'Max-Cut-Problem. Me ordnet jedem Knote vom Graph en Qubit im Zuestand 0|0\rangle oder 1|1\rangle zue, wo dr Wärt azeigt, in welcher Mengene dr Knote isch. S'Ziel vom Problem isch, d'Aaazahl vo 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 dem ZZ-Operator jedem Qubit zuordnet, wo gilt

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

de ghört e Kante (v1,v2)(v_1, v_2) zum Schnitt, wenn dr Eigenwärt vo (Z1v1)(Z2v2)=1(Z_1|v_1\rangle) \cdot (Z_2|v_2\rangle) = -1 isch; mit andere Wort, d'Qubits vo v1v_1 und v2v_2 sind verschidde. Entsprechend ghört (v1,v2)(v_1, v_2) nöd zum Schnitt, wenn dr Eigenwärt vo (Z1v1)(Z2v2)=1(Z_1|v_1\rangle) \cdot (Z_2|v_2\rangle) = 1 isch. Beachte, dass es nöd uf de exakte Qubit-Zuestand vu jedem Knote aakommt, sondern nur ob si ueber e Kante gliche oder verschidde sind. S'Max-Cut-Problem fordert e Zueordig vo de Qubits uf de Knöte, wo de Eigenwärt vom folgende Hamiltonian minimiert

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 bim Max-Cut-Problem. Dr Wärt QijQ_{ij} bezeichnet s'Gwicht vo dr Kante. I däm Tutorial betrachte mer ene ungewichtete Graph, also 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])

Hamiltonian → Quanteschaltkreis

Dr Hamiltonian HCH_C enthält d'Quantedefinitio vo dim Problem. Jetzt chasch ene Quanteschaltkreis erstelle, wo hilft, gueti Lösige vom Quantecomputer z'samplen. Dr QAOA isch vom Quanteannealing inspiriert und wendet abwächsligi Schicht vo Operatore im Quanteschaltkreis aa.

D'allgemeini Idee isch, im Grundzuestand vomeme bekannte System z'starte, Hn0H^{\otimes n}|0\rangle wie oben, und de s'System in de Grundzuestand vom Kostenoperator z'stüüre, wo di interessiert. Das wird gmacht, indem d'Operatore exp{iγkHC}\exp\{-i\gamma_k H_C\} und exp{iβkHm}\exp\{-i\beta_k H_m\} mit Winkele γ1,...,γp\gamma_1,...,\gamma_p und β1,...,βp \beta_1,...,\beta_p~ aagwendet wärde.

Dr Quanteschaltkreis, wo du generiersch, isch parametrisiert dur γi\gamma_i und βi\beta_i, also chasch verschiddi Wärt für γi\gamma_i und βi\beta_i uusprobiere und vom resultierete Zuestand samplen.

Schaltkreisdiagramm mit QAOA-Schichte

I däm Fall probiersch es Bispiil mit einere QAOA-Schicht mit zwee Parametere: γ1\gamma_1 und β1\beta_1.

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

circuit.draw("mpl")

Uusgab vo de vorherige Code-Zälle

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

Schritt 2: Problem für d'Quantehardware-Uusfüehrig optimiere

Dr Schaltkreis oben enthält e Reihe vo Abstraktione, wo nütz sind zum Dänke über Quantealgorithme, sich aber nöd direkt uf dr Hardware uusfüehre lönd. Um uf emene QPU laufe z'chönne, mueß dr Schaltkreis e Reihe vo Operatione durchlaufe, wo de Transpilierigs- oder Schaltkreisoptimierigs-Schritt vo em Pattern usmache.

D'Qiskit-Bibliothek bietet e Reihe vo Transpilierungspassene, wo e groossi Bandbreite vo Schaltkreistransformatione abdecke. Du muesch sicherstelle, dass din Schaltkreis für din Zwäck optimiert isch.

D'Transpilierig cha mehere Schritte umfasse, zum Bispiil:

  • Erscht-Abbildig vo de Qubits im Schaltkreis (wie Entscheidigsvariabele) uf physikalischi Qubits uf em Gerät.
  • Abrole vo de Iischtruktiöne im Quanteschaltkreis zu de Hardware-nativen Iischtruktiöne, wo de Backend versteht.
  • Routing vo allne Qubits im Schaltkreis, wo mitanand interagiere, zu physikalische Qubits, wo benachbart sind.
  • Fählerunderdückig dur s'Addiere vo Einzel-Qubit-Gates, zum Rüsche mit dynamischem Entkopplen z'underdrücke.

Meh Informatiöne über d'Transpilierig finsch in uuserer Dokumentatio.

Dr folgende Code transformiert und optimiert de abstrakten Schaltkreis in es Format, wo für d'Uusfüehrig uf einere vo de über d'Cloud zugängliche Devices mit em 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')>

Uusgab vo de vorherige Code-Zälle

Schritt 3: Uusfüehre mit Qiskit-Primitiven

Bim QAOA-Workflow wärde d'optimale QAOA-Parameter in ememe iterative Optimierigsloup gfunde, wo e Reihe vo Schaltkreisauswärtige dureführt und ene klassische Optimierer bruucht, um d'optimale βk\beta_k- und γk\gamma_k-Parameter z'finde. Dä Uusfüehrigsloup wird über die Schritte uusgfüehrt:

  1. D'Anfangsparameter definiere
  2. E neui Session instanziere, wo de Optimierigsloup und s'Primitiv enthält, das zum Samplen vom Schaltkreis bruucht wird
  3. Sobald e optimali Satz vo Parametere gfunde worden isch, de Schaltkreis e letzts Mal uusfüehre, um e schlussendlichs Verteilung z'erhalte, wo im Nachbearbeitigsschritt bruucht wird.

Schaltkreis mit Anfangsparameter definiere

Mir fange mit willkürlich gwählte Parametere aa.

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

Backend und Uusfüehrigsprimitiv definiere

Bruuch d'Qiskit-Runtime-Primitive, um mit IBM®-Backends z'interagiere. D'zwee Primitive sind Sampler und Estimator, und d'Wahl vom Primitiv hängt davon ab, was für Mässige du uf em Quantecomputer uusfüehre witt. Für d'Minimierig vo HCH_C bruuchsch de Estimator, will d'Mässig vo dr Kostenfunktion eifach dr Erwärtigswärt HC\langle H_C \rangle isch.

Uusfüehre

D'Primitive biete e Vielfalt vo Uusfüehrigsmodi, zum Workloads uf Quantedevices z'plane, und en QAOA-Workflow lauft iterativ in einere Session.

Illustratio, wo s&#39;Verhalte vo einzelne Job, Batch und Session Runtime-Modi zeigt.

Du chasch d'sampler-basierti Kostenfunktion in de SciPy-Minimierungsroutine iisetze, zum 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 het d'Chooste reduziert und besseri Parameter für de Schaltkreis gfunde.

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

Uusgab vo de vorherige Code-Zälle

Sobald du d'optimale Parameter für de Schaltkreis gfunde hesch, chasch dene Parameter zuewyyse und d'schlussendlichi Verteilung samplen, wo mit de optimierte Parametere ermittlet wird. Hie sollsch s'Sampler-Primitiv bruuche, will's d'Wahrschynlichkeitsverteilig vo Bitstrig-Mässige isch, wo de optimale Schnitt vom Graph entspreche.

Hinwys: Das bedütet, ene Quantezuestand ψ\psi im Rächner vorzubereite und in denn z'mässe. E Mässig kollabiert de Zuestand in ene einzelne Berechnigsbasis-Zuestand — zum Bispiil 010101110000... — was einere Kandidatenlösig xx für uuses ursprünglichs Optimierungsproblem (maxf(x)\max f(x) oder minf(x)\min f(x) je nach Ufgab) entspricht.

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

Uusgab vo de vorherige 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: Nachbearbeitig und Ergebnis im gwünschte klassische Format

Dr Nachbearbeitigsschritt interpretiert de Sampling-Uusgab, um e Lösig für dis ursprünglichs Problem z'liiefere. I däm Fall interessierst di für de Bitstrig mit dr höchste Wahrschynlichkeit, will däm de optimale Schnitt bestimmt. D'Symmetrie im Problem erlaubt vier möglichs Lösige, und dr Sampling-Prozäss wird eine davon mit en chli höherer Wahrschynlichkeit zurückgäh, aber du gsiehsch in dr ufgzeichnete Verteilig unge, dass vier Bitstrige deutlich wahrschynlicher sind als d'übrige.

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

Uusgab vo de vorherige Code-Zälle

Beste Schnitt visualisiere

Vom optimale Bitstrig uus chasch de dä Schnitt uf em ursprüngliche Graph 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)

Uusgab vo de vorherige Code-Zälle

Und de Wärt vom Schnitt bärechne:

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. Hochskaliere!

Du hesch Zuegriff uf viili Devices mit über 100 Qubits uf dr IBM Quantum® Platform. Wähl eines uus, uf wäm du Max-Cut uf emene gewichtete Graph mit 100 Knöte lösch. Das isch es «Utility-Scale»-Problem. D'Schritte zum Uufbau vom Workflow sind dieselbe wie oben, aber mit emem vill grösserem Graph.

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)

Uusgab vo de vorherige Code-Zälle

Schritt 1: Klassischi Iiput uf es Quanteproblem abbilden

Graph → Hamiltonian

Konvertier zerschte de Graph, wo du löse witt, direkt in ene Hamiltonian, wo für QAOA geignet 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', 'IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII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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 → Quanteschaltkreis

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)

Uusgab vo de vorherige Code-Zälle

Schritt 2: Problem für d'Quanteuusfüehrig optimiere

Um de Schaltkreisoptimierigs-Schritt uf Utility-Scale-Probleme z'skaliere, chasch d'Hochleistigungs-Transpilierungsstrategien nutze, wo im Qiskit SDK v1.0 iiigfüehrt worde sind. Ander Wärchzüüg umfassend de neue Transpiler-Service mit KI-gstiitzte Transpilierungspassene.

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)

Uusgab vo de vorherige Code-Zälle

Schritt 3: Uusfüehre mit Qiskit-Primitiven

Um QAOA uuszfüehre, muesch d'optimale Parameter γk\gamma_k und βk\beta_k für de Variationsschaltkreis kenne. Optimier dene Parameter, indem du ene Optimierungsloup uf em Gerät uusfüehrsch. D'Zälle schickt Jobs, bis dr Kostefunktionswärt konvergiert isch und d'optimale Parameter für γk\gamma_k und βk\beta_k bestimmt worde sind.

Kandidatenlösig finde, indem du d'Optimierig uf em Gerät uusfüehrsch

Zerschte führsch de Optimierungsloup für d'Schaltkreisparameter uf ememe Gerät uus.

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 vom Uusfüehre vom QAOA uf em Gerät gfunde worde sind, wärde die dem Schaltkreis zuewyyse.

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

Uusgab vo de vorherige Code-Zälle

Schlussändlich de Schaltkreis mit de optimale Parametere uusfüehre, um von dr entsprechende Verteilig 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üef, ob d'Koste, wo im Optimierungsloup minimiert worde sind, zu ememe bestimmte Wärt konvergiert sind.

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

Uusgab vo de vorherige Code-Zälle

Schritt 4: Nachbearbeitig und Ergebnis im gwünschte klassische Format

Well d'Wahrschynlichkeit vo jede Lösig gring isch, extrahier d'Lösig, wo de tiischte Koste 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 de Schnitt visualisiere. Knöte vo dr gliche Farb ghöre zur gliche Gruppene.

plot_result(graph_100, best_sol_bitstring_100)

Uusgab vo de vorherige Code-Zälle

De Wärt vom Schnitt bärechne.

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 muesch de Zielwärt vo jedem Sample bärechne, wo du uf em Quantecomputer gmässe hesch. S'Sample mit em tiischte Zielwärt isch d'Lösig, wo vom Quantecomputer zurückgäh wird.

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

Schlussändlich chasch d'kumulative Verteilungsfunktion ufzeichne, um z'visualisiere, wie jedes Sample zur gesamte Wahrschynlichkeitsverteilig und zum entsprechende Zielwärt biitragt. D'horizontale Ausdehning zeigt d'Bandbreite vo de Zielwärt vo de Samples i dr schlussendliche Verteilig. Im idealfall würsch gseh, dass d'kumulative Verteilungsfunktion «Sprünge» am unteren Änd vo dr Zielwärt-Achse macht. Das würde bedüte, dass wenigi Lösige mit tiefer Koste e hohi Wahrschynlichkeit händ, sampled z'wärde. E glatti, breiti Churvi zeigt, dass jedes Sample ähnlich wahrschynlich isch und sehr verschiddi Zielwärt ha chan, nidrig oder hoch.

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

Uusgab vo de vorherige Code-Zälle

Schluss

Dä Tutorial het zeigt, wie mer es Optimierungsproblem mit ememe Quantecomputer löst und dä Qiskit-Patterns-Rahme verwendet. D'Demonstration het es Utility-Scale-Bispiil iigschlossen, mit Schaltkreisgrössen, wo klassisch nöd exakt simuliert wärde chönne. Momentan übertreffe Quantecomputer klassischi Rächner nöd bim kombinatorische Optimiere, will's no Rüsche gid. Aber d'Hardware verbesseret sich stetisch, und neui Algorithme für Quantecomputer wärde laufend entwicklet. Tatsächlich wird vill vo dr Forschig zu quanteheuristischen Methode für kombinatorischs Optimiere mit klassische Simulatione gteistet, wo nur e chlini Aaazahl vo Qubits erlauben, typically so um die 20. Jetzt, mit grössere Qubit-Aaazahle und Devices mit weniger Rüsche, wärde Forschendi d'Möglichkeit ha, dene Quante-Heuristike bi grosse Problemgrössen uf Quantehardware z'benche.

Tutorial-Umfrag

Nimm kurz an dere Umfrag teil und gib uns Feedback zu däm Tutorial. Dini Rückmäldige hälfe uus, uuseri Inhalt und d'Benutzererfahrig z'verbessere.

Link zur Umfrag