08 QAOA Optimization Results

This notebook demonstrates the accessible information post QAOA optimization with the results object. The user can access different aspects of the optimization run through the results object.

Let’s start with a few import statements

[1]:
import networkx as nx
import numpy as np
from openqaoa.problems import MinimumVertexCover, NumberPartition, Knapsack
import matplotlib.pyplot as plt
from pprint import pprint
from openqaoa.backends import create_device, DeviceLocal

Problem Statement

We begin by creating the problem statement (and its subsequent translation into QUBO) to be optimized using QAOA. As an example, we consider the Knapsack problem class for this tutorial. The user can pass the following parameters to define a Knapsack problem: - Item values - Item weights - Knapsack weight capacity - Penalty coefficient

For this notebook, however, we create a problem instance using the random_instance method of the class

[2]:
kp_prob = Knapsack.random_instance(n_items=5, quantum=True,seed=1234)
kp_qubo = kp_prob.qubo
pprint(kp_qubo.asdict())
{'constant': 216.5,
 'metadata': {},
 'n': 9,
 'problem_instance': {'n_items': 5,
                      'penalty': 8,
                      'problem_type': 'knapsack',
                      'values': [4, 4, 4, 2, 1],
                      'weight_capacity': 13,
                      'weights': [4, 1, 2, 1, 2]},
 'terms': [[0, 1],
           [0, 2],
           [0, 3],
           [1, 2],
           [1, 3],
           [2, 3],
           [4, 5],
           [4, 6],
           [4, 7],
           [8, 4],
           [5, 6],
           [5, 7],
           [8, 5],
           [6, 7],
           [8, 6],
           [8, 7],
           [0, 4],
           [0, 5],
           [0, 6],
           [0, 7],
           [0, 8],
           [1, 4],
           [1, 5],
           [1, 6],
           [1, 7],
           [8, 1],
           [2, 4],
           [2, 5],
           [2, 6],
           [2, 7],
           [8, 2],
           [3, 4],
           [3, 5],
           [3, 6],
           [3, 7],
           [8, 3],
           [0],
           [1],
           [2],
           [3],
           [4],
           [5],
           [6],
           [7],
           [8]],
 'weights': [8.0,
             16.0,
             32.0,
             32.0,
             64.0,
             128.0,
             16.0,
             32.0,
             16.0,
             32.0,
             8.0,
             4.0,
             8.0,
             8.0,
             16.0,
             8.0,
             16.0,
             4.0,
             8.0,
             4.0,
             8.0,
             32.0,
             8.0,
             16.0,
             8.0,
             16.0,
             64.0,
             16.0,
             32.0,
             16.0,
             32.0,
             128.0,
             32.0,
             64.0,
             32.0,
             64.0,
             4.0,
             8.0,
             16.0,
             32.0,
             18.0,
             6.0,
             10.0,
             5.0,
             8.5]}

Optimization using OpenQAOA

We perform the usual steps of: - creating and configuring the QAOA model - compiling the model with the problem statement - optimizing the problem

[3]:
from openqaoa import QAOA
[4]:
q = QAOA()
q.set_circuit_properties(p=3, init_type='ramp')
q.compile(kp_qubo)
[5]:
q.optimize()

Access the results object

Once the optimization process terminates, the user has access to information on the optimization process. This can be accessed in the form of a Result object, by calling the .results attribute of the model post optimization.

[6]:
result = q.result
[7]:
result.most_probable_states
[7]:
{'solutions_bitstrings': ['000100000'], 'bitstring_energy': 200.0}

Re-run the problem with a different backend: Qiskit statevector_simulator

Using the qiskit statevector simulator as the backend, we repeat the optimization. One of the fields of the results object is the data stored on the measurement outcomes of the intermediate circuit executions during the optimization process. The user has access to either the intermediate statevectors if using a statevector_simulator backend, or counts_dictionaries if using shot-based simulators or real QPUs. The size of these dictionaries will be proportional to the n_shots used. Since this feature may require storage of large data objects, this feature is turned OFF by default. The user can switch this ON by configuring the QAOA model by passing the optimization_progress boolean as True. Apart from the measurement_outcomes, the results object also stores the intermediate results (comprising of the angle log) and the optimized results.

[8]:
q_qiskit_sv = QAOA()
qiskit_dev = create_device(location='local',name='qiskit.statevector_simulator')
q_qiskit_sv.set_device(qiskit_dev)
[9]:
q_qiskit_sv.compile(kp_qubo)
[10]:
q_qiskit_sv.optimize()
[11]:
qiskit_results = q_qiskit_sv.result
[12]:
qiskit_results.most_probable_states
[12]:
{'solutions_bitstrings': ['000110000'], 'bitstring_energy': 4.0}
[13]:
qiskit_results.evals
[13]:
{'number_of_evals': 29, 'jac_evals': 0, 'qfim_evals': 0}
[14]:
qiskit_results.intermediate
[14]:
{'angles': [[0.35, 0.35],
  [1.35, 0.35],
  [1.35, 1.35],
  [1.822370451816, -0.531400111329],
  [1.586185225908, -0.090700055665],
  [1.107374603994, 0.289726314092],
  [0.874986723481, 0.197553254086],
  [1.061288073991, 0.405920254349],
  [1.356749567622, 0.27205918316],
  [1.232062085808, 0.280892748626],
  [1.067097208615, 0.241935295883],
  [1.138417610573, 0.28613545869],
  [1.085761155786, 0.312296678656],
  [1.097653929758, 0.277493198488],
  [1.114323922504, 0.293295925906],
  [1.121078540299, 0.289370331086],
  [1.114212406068, 0.301107629967],
  [1.116886829692, 0.290347995138],
  [1.112660388281, 0.292272524149],
  [1.11071674546, 0.292080300711],
  [1.112904142973, 0.290334669429],
  [1.112590602338, 0.293246589977],
  [1.112725510973, 0.291788605133],
  [1.112902347789, 0.292305085495],
  [1.112850690299, 0.292790626515],
  [1.112940982498, 0.292064021179],
  [1.112895403108, 0.29240484406],
  [1.112952227072, 0.292308557835],
  [1.112967290836, 0.292209698931]],
 'cost': [215.55245864841,
  208.588874735772,
  221.582286182776,
  212.62173527352,
  215.216018459443,
  179.815570626776,
  313.36769175789,
  211.934595122054,
  218.217638222992,
  219.781419765252,
  198.565209954299,
  247.560664098383,
  197.159286442288,
  207.518056913936,
  128.097355833634,
  188.036080217214,
  293.554491742425,
  154.509608519926,
  107.576203467122,
  108.893427313291,
  156.196908347037,
  126.258690107777,
  112.040420605493,
  107.514186284575,
  112.440380627188,
  108.475984285951,
  107.746629951845,
  107.504668550891,
  107.631894060712],
 'measurement_outcomes': [],
 'job_id': ['12dad73d-50f7-42ff-be85-5b9d013e210e',
  '1f47131e-7ab1-4af1-83ff-6a2c4c8e8424',
  '620afba1-b65f-48cb-806a-f9fb26a6c347',
  '9d637f51-f619-4251-9787-80cc720647ca',
  'af4290ab-4ee8-4b5f-bb3f-f700df02976e',
  '21e42777-b18e-495f-addd-63967c114873',
  'f7d42e4a-52e1-4ec3-a160-4d5cc835e73d',
  '822aaac2-5a29-47fc-b42c-bbf1ca8d6fb5',
  'c550cb1c-29e2-47da-9cc3-9491c734db78',
  '70303a9f-af16-4633-9219-6530e76b36f7',
  'ec955c2a-8c3c-4976-a647-9027e8d1ea7c',
  '174460d2-a343-4513-a734-be60bbf018a8',
  '1f0dd9dc-5275-4671-8a43-67813de6bf54',
  '31d6f2e6-018e-45bc-9af7-88f8202d23ce',
  'e52daea1-8390-4e36-b6da-1d0e19b33cd7',
  'c7bf23f3-eb80-4944-865a-5f5d889c7f6b',
  '5fc48189-ff9c-4d27-87db-36558992cac7',
  '19bdb8cf-747a-471b-b366-a9ea98bd64d3',
  'b69d322d-84ba-4930-bf8b-77c7411ede1d',
  '7752ec27-3c09-41af-bc10-c9790a62becf',
  'b3e5ec62-e1f3-46bf-9948-84337a2bdca0',
  '9256efc8-716a-4cf0-865e-e77d70711ff9',
  'ea4071e6-c452-4e92-bf23-a5f21c228ed7',
  '911df042-75c4-4199-bdbb-5ee948899dda',
  '763cc6b1-f1f5-4074-b68d-e3b7c73fa8de',
  '7d92cabb-063a-449c-89d2-84ef977a9f43',
  '13590efa-e3bd-4386-a704-403c356bf128',
  '992165ff-296e-4548-9a04-5d46d3fac7f4',
  '5f6cdbb7-bf2a-45d9-a7ba-4a52a6d02e6c']}
[15]:
qiskit_results.optimized
[15]:
{'angles': [1.112952227072, 0.292308557835],
 'cost': 107.504668550891,
 'measurement_outcomes': array([-2.45038508e-02-1.31208386e-02j, -7.82037753e-03+2.95082418e-03j,
         2.32850424e-03+6.71403316e-03j,  6.51869564e-03+2.47645307e-03j,
         6.31419259e-04+2.15739573e-02j,  1.21970025e-02+3.06943569e-02j,
        -2.10600470e-02+2.54040035e-03j, -1.19348249e-02-1.79557096e-02j,
         3.60238581e-02+4.52349435e-03j,  1.96379191e-02+2.57784054e-02j,
        -3.29316639e-02+6.64535862e-03j, -2.52911156e-02-1.17057990e-02j,
         7.48297581e-02-5.36130483e-03j,  1.94147356e-02+1.13535257e-02j,
        -3.18224578e-02+3.48823962e-03j, -3.29357646e-02-3.49317348e-03j,
         1.75639626e-02-3.93792374e-02j,  4.86234144e-02+3.83632637e-03j,
        -1.43423709e-02+4.97953049e-02j, -3.25383382e-02+2.03805640e-02j,
         7.04492162e-02-8.90484726e-02j,  5.07025748e-02-7.40178930e-03j,
        -2.97370199e-02+5.61325400e-02j, -4.76425208e-02+3.64062942e-02j,
         5.88773933e-02-1.10629248e-01j,  3.13071234e-02-1.52502538e-03j,
        -3.17767635e-02+4.75568878e-02j, -3.57553676e-02+3.63608792e-02j,
         2.26933575e-02-1.02389095e-01j, -4.52769632e-03-1.13495955e-02j,
        -6.19903399e-03+2.84661826e-02j, -5.33387966e-03+3.48741648e-02j,
        -1.65136565e-02+5.90755692e-03j,  1.13260056e-03+5.92686601e-05j,
         1.28891724e-03-8.64383246e-05j, -1.41302952e-02-5.59916704e-03j,
         2.31511916e-02+2.47614973e-02j, -2.23642881e-02-5.72138038e-03j,
        -2.74206712e-02-5.48074977e-03j,  9.55728663e-03-9.00553786e-03j,
         3.77203136e-02+5.39528118e-03j, -2.55177525e-02+7.03750967e-04j,
        -3.38331428e-02+3.53535544e-03j,  2.29318089e-02-2.30276637e-02j,
         4.92708807e-02-1.60896418e-02j, -1.42989396e-02+5.83813934e-03j,
        -2.65312770e-02+1.21258104e-02j,  3.73940442e-02-1.94139346e-02j,
         3.45037296e-02-3.52450049e-02j, -2.03384230e-02+2.87744541e-02j,
        -2.25423114e-02+4.46408305e-02j, -1.65654812e-02-4.58846424e-02j,
         4.62008095e-02-7.59562991e-02j, -1.49838193e-02+3.28655995e-02j,
        -2.20795432e-02+5.72087525e-02j,  6.52422514e-03-7.00598105e-02j,
         2.80933563e-02-7.44985345e-02j, -6.59275344e-03+1.72124614e-02j,
        -1.30992862e-02+4.33833185e-02j,  1.36816803e-02-7.17101868e-02j,
        -8.47639463e-03-5.72571248e-02j,  2.24925128e-02+4.91946941e-03j,
         1.67808937e-02+2.55790713e-02j,  1.89363635e-03-3.73836595e-02j,
        -1.71272996e-02+5.21633568e-03j,  6.44440398e-03-5.80667963e-03j,
        -2.17360172e-02-1.10294001e-03j,  1.02374118e-02-8.77516660e-03j,
        -6.93813661e-03+8.94460712e-03j, -7.74720037e-03+1.23282190e-02j,
         1.74545600e-02-3.08813792e-02j,  1.06262406e-04+1.18912582e-02j,
        -1.05902790e-03-6.88880253e-03j, -6.04297540e-03+2.78366275e-02j,
         2.48977621e-02-5.64282945e-02j,  4.64693031e-03+2.54974118e-02j,
         1.93188241e-02-1.99450017e-02j, -1.06722055e-02+3.47677251e-02j,
         3.52656665e-02-4.88981667e-02j, -1.01874773e-03+2.80503159e-02j,
        -1.37048092e-02+3.46313488e-03j,  3.04440984e-02+2.71338440e-02j,
        -5.72673126e-02-7.04571044e-02j,  3.48870063e-02+7.42332260e-03j,
        -5.29968504e-03-3.15213943e-02j,  3.60120965e-02+5.14573278e-02j,
        -4.27915432e-02-1.04898169e-01j,  4.11993711e-02+2.71465270e-02j,
        -1.17874497e-02-4.48654321e-02j,  3.44260316e-02+5.16858276e-02j,
        -2.28547908e-02-9.89553936e-02j,  3.47804030e-02+2.97060040e-02j,
        -8.42162050e-03-3.48117494e-02j,  2.55575467e-02+2.26514647e-02j,
        -2.20533110e-02-2.94225273e-02j,  1.91958309e-02+3.59651495e-03j,
        -1.15103069e-02+3.83503196e-03j, -1.55713112e-02+9.26421832e-03j,
        -1.07558069e-02-6.28809177e-03j, -6.69435882e-03+5.44387970e-03j,
        -6.49526735e-03+1.41214746e-02j, -1.09974503e-02-1.64699186e-02j,
         1.00843679e-02-1.34661564e-02j,  2.76910735e-03-9.60876790e-03j,
         2.57652485e-06+7.51663950e-03j, -1.45827067e-02-3.64725622e-02j,
         1.82637992e-02-2.38006759e-02j, -2.53869040e-04-1.99089608e-02j,
         1.58441186e-02-1.06529386e-03j,  5.31564720e-03-4.43626893e-02j,
         2.29793799e-02-1.72574369e-02j,  2.17159955e-03-2.05653020e-02j,
         6.98137823e-03+1.11234413e-02j, -6.03972645e-02-5.21775152e-03j,
        -2.10886281e-02-4.05791251e-02j, -2.39230261e-02-1.04122406e-02j,
         1.77950249e-02-9.17442726e-03j, -6.18994599e-02-4.26750417e-02j,
        -7.12280744e-03-5.38312846e-02j, -2.87865075e-02-2.32274015e-02j,
         1.18743809e-02-2.09422765e-02j, -5.48057723e-02-5.79579016e-02j,
         2.25360142e-03-4.90175504e-02j, -2.42893462e-02-2.26024095e-02j,
         9.34125909e-03-2.40970112e-02j, -2.13685568e-02-2.74567269e-02j,
        -6.83878771e-03-1.73330910e-02j, -1.70029392e-02-9.65806708e-04j,
        -1.08031815e-02+4.04551128e-03j,  6.62894513e-03+3.39979437e-03j,
         5.22842152e-03-1.01159495e-03j, -8.86093286e-03-1.23056784e-02j,
         1.77839949e-02+2.33332804e-02j, -1.87279581e-02-2.93867805e-02j,
        -1.82340530e-02-1.06112009e-02j,  1.66105362e-02+5.05864655e-03j,
         2.73207399e-02+1.24632625e-02j, -3.32093833e-02-2.42433787e-02j,
        -2.61357500e-02-7.15589715e-04j,  3.89354685e-02-1.01176468e-04j,
         3.13205923e-02-2.21500813e-03j, -3.19585205e-02-1.25188322e-02j,
        -2.70868321e-02+9.96646880e-03j,  5.13594110e-02+6.80020755e-03j,
         3.74118624e-02-1.74943265e-02j, -5.40533669e-02+1.60922096e-02j,
        -2.06750764e-02+2.96838850e-02j,  2.55918800e-02-5.16927448e-02j,
         4.37188232e-02-3.94373902e-02j, -6.37287586e-02+2.73446357e-02j,
        -2.45333573e-02+4.79017627e-02j,  6.18040369e-02-6.34124186e-02j,
         2.85082340e-02-3.43168661e-02j, -4.30691509e-02+1.91686513e-02j,
        -1.37893630e-02+4.21182708e-02j,  6.35316196e-02-6.14951571e-02j,
        -4.61250610e-03-2.76683858e-02j,  6.92860248e-03+2.69816822e-02j,
         1.14581092e-02+3.05771153e-02j,  2.62810762e-02-4.17680474e-02j,
        -7.07319681e-03-6.35480616e-05j, -1.78700231e-02-1.09863657e-02j,
        -1.79936576e-02+2.17014605e-03j, -1.48441045e-02+7.96358150e-03j,
        -1.50908348e-02+1.58614278e-02j, -4.61835699e-04+3.69061456e-02j,
        -5.07373642e-03-1.61172309e-02j, -1.45899293e-02-2.08766031e-02j,
        -6.16436642e-03+1.58284209e-02j,  3.06798008e-02+3.36444583e-02j,
        -1.49121356e-03-3.49053398e-02j, -2.40035417e-02-3.68368626e-02j,
         1.44555707e-02+9.13679365e-03j,  5.97217224e-02+3.00332223e-02j,
         1.71771390e-02-3.56339496e-02j, -1.58960045e-02-3.81700917e-02j,
         1.07687239e-02+2.02462450e-02j,  5.81905338e-02-7.84541345e-03j,
        -5.05857939e-02-2.03209279e-02j, -6.91567082e-02+1.08936419e-02j,
         2.86082379e-02+5.09833193e-03j,  1.07307214e-01-2.99367895e-02j,
        -4.07360951e-02-5.29434567e-02j, -8.14652065e-02-1.17663201e-02j,
         2.29864765e-02-1.42680630e-02j,  9.35983044e-02-4.48275707e-02j,
        -3.10219558e-02-6.29140604e-02j, -7.08031465e-02-1.98450011e-02j,
         2.63626828e-02-3.16607345e-02j,  4.52398212e-02-5.84995223e-02j,
        -1.46400424e-02-2.77149209e-02j, -3.60514472e-02+5.14543992e-03j,
        -3.10825912e-03-4.31680853e-03j, -1.51259668e-02+3.59022028e-03j,
        -9.88905583e-04-8.71481558e-03j, -1.18711659e-02+8.46143604e-03j,
        -4.91533606e-03+1.22287516e-02j, -6.17618041e-05-1.90900088e-02j,
         6.35259526e-03+2.40357865e-03j, -2.26153242e-03-3.91509034e-03j,
         2.88804669e-03+1.73890239e-02j,  3.73841046e-03-3.93165297e-02j,
         1.51751322e-02+4.17468433e-03j, -3.57555082e-03-1.76968728e-02j,
         9.70629656e-03+2.02145917e-02j,  2.38360158e-02-4.17830255e-02j,
         1.56021967e-02+8.38981931e-03j,  6.38875084e-03-2.22861120e-02j,
         2.20777528e-02+1.02301439e-02j, -5.00615516e-02-3.39469404e-02j,
         1.33895731e-02-1.84978849e-02j, -2.43106413e-02-1.07682148e-03j,
         3.72895891e-02+1.36941986e-02j, -3.94025542e-02-7.04102421e-02j,
         2.67633405e-02-1.59459293e-02j, -2.63090272e-02-2.34682975e-02j,
         3.57310074e-02+8.84832777e-03j, -2.92521109e-02-8.07467284e-02j,
         2.66973764e-02-1.22226627e-02j, -2.44500798e-02-2.95164792e-02j,
         2.43741547e-02-4.13859289e-03j, -1.07608331e-02-3.90915298e-02j,
         8.91193499e-03-1.09539981e-02j, -1.53893482e-02-9.95732912e-03j,
        -1.77119218e-02+1.77131350e-02j, -1.81866655e-02+5.99936724e-03j,
        -7.66619073e-03+2.24887947e-03j,  7.72960765e-04-1.81339337e-02j,
        -1.99274509e-02-9.77974095e-03j, -1.07590144e-02-9.84529707e-03j,
         6.68302903e-03-2.29934008e-02j,  3.13653122e-02-3.53610442e-02j,
        -3.01676596e-02-3.22612600e-02j, -1.25044861e-02-2.42504132e-02j,
         3.12408508e-03-3.51134085e-02j,  3.81652232e-02-3.77094493e-02j,
        -8.31018207e-03-4.95995626e-02j, -7.53280540e-04-2.31808791e-02j,
         2.46189077e-03-2.89363800e-02j,  1.62690531e-02-1.42622579e-02j,
        -6.59634790e-02+2.26063064e-02j, -4.36665473e-02+8.39275693e-03j,
        -4.18273655e-02-2.79910296e-02j, -2.44356764e-02-8.36017857e-02j,
        -7.98661715e-02-2.19898889e-02j, -4.34039743e-02-1.30609702e-02j,
        -4.56011700e-02-3.87733164e-02j, -1.57053039e-02-6.84667176e-02j,
        -7.88936782e-02-4.33991448e-02j, -3.49442148e-02-2.07689966e-02j,
        -3.25279423e-02-3.29932331e-02j,  5.93589917e-03-3.81784207e-02j,
        -3.28814759e-02-2.29219780e-02j, -1.88811910e-02+1.42010678e-03j,
        -2.22183343e-02+4.28328372e-03j, -1.75654945e-02+9.19622146e-03j,
        -2.65982702e-03+3.29249741e-03j,  7.49780845e-03+4.76425667e-04j,
        -2.59180295e-02-1.64452359e-02j,  1.39395298e-02-9.31578036e-03j,
        -1.72991193e-02+7.02865283e-03j, -1.25365493e-02-1.16990683e-02j,
         2.42357293e-02-1.25953128e-02j,  5.43180964e-03+4.10360952e-03j,
        -2.11730124e-02+8.53069891e-03j, -2.34226776e-02-2.31568372e-03j,
         5.30501366e-02-2.99406214e-02j,  7.14121492e-03+1.72379669e-02j,
        -1.40512582e-02+5.64090833e-03j, -3.10108116e-02+5.99008184e-03j,
         7.03981896e-02-1.14418660e-02j, -4.84246455e-03+2.07574688e-02j,
        -5.27609137e-03+3.67888314e-02j, -1.96583222e-02+2.50100702e-02j,
        -6.41745308e-03-8.71170574e-02j,  2.68433162e-02-4.27888605e-03j,
        -8.09461275e-03+3.60722683e-02j, -3.12954218e-02+4.47391135e-02j,
         4.41157852e-02-1.11869219e-01j,  2.69956169e-02+1.81394516e-02j,
        -1.09826060e-02+2.63327415e-02j, -2.22259671e-02+4.44088246e-02j,
         6.24923254e-02-1.04045053e-01j,  2.25411364e-02+2.59231167e-02j,
         2.45522264e-03+1.16649979e-02j,  1.44126898e-03+3.46225280e-02j,
         2.06130679e-02-4.44191981e-02j,  9.17482249e-03+6.20320184e-03j,
        -1.77747658e-03-1.16187306e-03j, -1.44879732e-02-2.01943276e-03j,
        -8.79637101e-03-1.54959206e-02j,  1.65659294e-03+8.62020007e-03j,
        -2.29508959e-02+1.25205871e-03j,  5.48056147e-03-9.61462656e-03j,
         1.83892459e-02-5.78333099e-03j,  1.74570742e-03+1.20569751e-02j,
        -2.41905024e-02+8.11459320e-03j,  1.52546123e-02-2.52364075e-02j,
         3.59353895e-02-1.07453281e-02j, -3.16995369e-03+9.71291855e-03j,
        -1.40902757e-02+1.39313011e-02j,  3.09884964e-02-2.51595849e-02j,
         3.72887798e-02+3.47492118e-04j, -6.33027596e-03-2.52178496e-03j,
        -1.04244234e-02+3.70374560e-02j, -2.47992149e-02-3.69826213e-02j,
         6.55436207e-03-5.52195924e-02j,  1.34684858e-02+1.57068079e-02j,
        -3.77051210e-03+4.37102532e-02j, -7.41087033e-03-6.49738217e-02j,
         3.31128319e-02-5.95427778e-02j, -6.49174837e-04+1.00237070e-02j,
         1.40069563e-03+3.00531030e-02j, -1.20464830e-03-6.96881175e-02j,
         3.97037855e-02-4.86863790e-02j, -1.22992862e-02+9.69620199e-03j,
         1.99161236e-02+1.28567910e-02j, -3.72882152e-03-3.67316800e-02j,
         5.80507676e-03-2.35375908e-02j, -1.37163105e-02-7.44074749e-04j,
        -2.09420284e-02+3.09240533e-03j,  9.08258248e-03-9.13675453e-03j,
         2.24007234e-02-2.06513815e-03j, -2.57590602e-03+1.75525134e-02j,
         1.49610398e-02-3.50426105e-02j,  2.00017636e-04+1.83402985e-02j,
         3.62258560e-02-1.96881535e-02j, -1.46764057e-02+4.31545594e-02j,
         1.68088894e-02-6.30732300e-02j,  7.49511798e-03+3.26743657e-02j,
         2.35760412e-02-1.79937958e-02j, -1.42503944e-02+4.29753961e-02j,
         2.59049560e-02-5.94019592e-02j,  3.96950542e-03+3.40156842e-02j,
        -1.63033468e-02-2.30414576e-02j,  5.72037535e-03+1.86032870e-02j,
        -7.11574410e-02-6.48292790e-02j,  4.60592253e-02+1.01619845e-02j,
        -1.34877446e-03-5.39190633e-02j,  5.17550445e-02+5.85183218e-02j,
        -6.64290034e-02-1.03027568e-01j,  5.64057809e-02+2.90934441e-02j,
        -3.74485506e-02-3.63673058e-02j,  5.10488185e-02+4.02111228e-02j,
        -4.68033330e-02-9.83440609e-02j,  4.72226621e-02+3.04689357e-02j,
        -4.17898852e-02-3.41548144e-03j,  2.59318102e-02+1.78526669e-02j,
        -3.41617976e-02-2.71886436e-02j,  2.53822234e-02-1.02096136e-04j,
        -5.18148980e-02+1.07590774e-02j,  2.47551265e-02-2.00874833e-02j,
        -1.17154303e-02-2.67791665e-03j, -9.61225176e-03+7.19236209e-03j,
         1.01779799e-02+9.82795631e-03j, -1.91339905e-02-6.81367098e-03j,
         9.29287282e-03-1.27740789e-02j, -1.91074495e-03-1.69537302e-02j,
         1.98749779e-02+6.69485420e-03j, -8.68592012e-03-4.57932310e-02j,
         1.53347296e-02-2.55868959e-02j, -7.31547089e-03-3.04058532e-02j,
         1.28490252e-02+2.99483597e-03j, -7.25576108e-03-5.92674276e-02j,
         2.13492707e-02-2.28944767e-02j, -1.33149782e-03-2.95903135e-02j,
         1.03966263e-03-1.31684196e-02j,  3.20847415e-03-3.23070900e-02j,
        -2.46946884e-02-3.70929865e-02j, -4.29759899e-02-8.80266943e-03j,
         2.18014979e-02-1.64336244e-02j, -8.80624143e-02-3.23916675e-02j,
        -1.47365578e-02-5.54958890e-02j, -4.88506751e-02-2.61464911e-02j,
         9.75339899e-04-2.18803256e-02j, -7.20519456e-02-4.19804777e-02j,
        -6.92541623e-03-5.24483882e-02j, -3.94912701e-02-2.86980024e-02j,
        -1.25530620e-02-1.20382701e-02j, -3.60117567e-02-4.32640555e-02j,
        -1.13276505e-02-1.96474745e-02j, -2.06168186e-02+7.42216066e-04j,
        -1.93843054e-02-9.68699031e-03j, -9.41894474e-03+1.31858588e-02j,
         3.81485970e-03-2.84895840e-03j, -1.09510196e-02-8.53627340e-03j,
         1.65956603e-03-1.28378698e-02j, -8.52145480e-03+1.36703979e-02j,
        -1.65459737e-02-4.72954373e-03j,  1.31193841e-02-1.66361003e-04j,
         8.46363095e-03+3.32184952e-04j, -1.49386736e-02+7.46670674e-03j,
        -2.03375241e-02+5.47264433e-03j,  3.16760835e-02-9.51395643e-03j,
         1.86965193e-02+4.84470138e-03j, -2.15928528e-02-2.14319467e-03j,
        -1.93265829e-02+1.52952817e-02j,  4.66613741e-02-5.32083960e-03j,
         1.57511987e-02+1.22064959e-02j, -9.42508861e-03-1.60104460e-02j,
        -9.34843719e-03+2.74510961e-02j,  8.17467761e-03-4.88453204e-02j,
         1.57243052e-02-2.47004164e-02j, -1.79128555e-02+3.42437430e-02j,
        -7.55654506e-03+4.42758814e-02j,  3.91841653e-02-6.78632878e-02j,
         3.08979556e-02-1.62792576e-02j, -2.91919420e-02+1.21146157e-02j,
         4.62356350e-04+3.81957954e-02j,  4.25948074e-02-6.90897712e-02j,
         3.18780319e-02-9.52517821e-03j, -3.59638840e-02-2.69347188e-03j,
         1.69491559e-02+2.36718897e-02j,  1.77442900e-02-4.34251218e-02j,
         9.97376080e-03-9.66192577e-03j, -1.46077371e-02-7.35294700e-03j,
        -1.76937430e-02+5.34266502e-03j, -1.42097522e-02+7.28817259e-03j,
         3.87043405e-03-1.76690910e-04j,  1.15865121e-02-1.71216729e-02j,
        -6.86941685e-03-1.23076190e-02j, -1.19597765e-02-1.36042841e-02j,
         2.15463481e-02+7.59877524e-03j,  4.94852874e-02+4.99612716e-03j,
        -5.41218342e-03-3.16701349e-02j, -1.86940774e-02-2.75136779e-02j,
         2.37239820e-02+6.58299355e-03j,  6.42454427e-02+1.34207376e-02j,
         1.35397013e-02-3.70308052e-02j, -1.12494880e-02-2.94676410e-02j,
         1.02113701e-02+2.49628825e-03j,  3.20497333e-02+2.36629238e-02j,
        -4.87792045e-02-1.18079312e-02j, -5.25798098e-02+1.19288329e-02j,
         2.93923931e-02-2.36590704e-02j,  6.62855767e-02-7.68160278e-02j,
        -4.36391520e-02-4.71451064e-02j, -6.19061040e-02-8.21930654e-03j,
         2.34195801e-02-2.02503504e-02j,  7.56060580e-02-4.98283631e-02j,
        -3.75205773e-02-5.90238876e-02j, -5.46962081e-02-1.51163404e-02j,
         1.50257521e-02-5.06666784e-03j,  7.12468446e-02-1.10837259e-02j,
        -1.80867784e-02-2.86629762e-02j, -2.98416888e-02+4.19483689e-03j,
        -1.25751720e-02-1.60492743e-03j,  7.81673016e-04-2.69514931e-04j,
        -2.31030674e-03-7.45024418e-03j, -1.40569444e-02+9.17814692e-03j,
         4.20766693e-03+1.26153330e-02j, -1.71515243e-02-1.73707857e-02j,
         7.73363360e-03+5.78543286e-03j, -1.92659983e-03-1.14740384e-02j,
         1.04547929e-02+2.75652203e-02j,  1.47544603e-02-4.88835098e-02j,
         1.75771882e-02+6.17808263e-03j, -4.40945239e-03-2.86983420e-02j,
         9.73583233e-03+2.49371136e-02j,  2.47630048e-02-6.10654080e-02j,
         1.94778474e-02+8.05368898e-03j,  6.76210155e-03-3.13790874e-02j,
         1.08620410e-02+3.85771584e-03j,  2.05931563e-02-2.60106839e-02j,
         1.81548537e-02-1.90395285e-02j, -3.89571962e-02-8.20627848e-03j,
         4.75851720e-02+9.36517653e-03j, -6.82799921e-02-7.57379307e-02j,
         3.23514282e-02-1.99646902e-02j, -4.13860287e-02-3.43621591e-02j,
         3.81722777e-02-2.70436838e-03j, -4.53277854e-02-7.49248429e-02j,
         3.01988659e-02-1.68024986e-02j, -3.50359448e-02-4.02675338e-02j,
         1.65653761e-02-4.36958461e-03j, -7.81981073e-03-5.70579960e-02j,
         9.57381741e-03-1.53761195e-02j, -2.01925805e-02-9.96163067e-03j,
         1.52536752e-03-1.95421873e-02j, -1.50837108e-02+1.17172237e-02j,
        -1.06893731e-02+6.13044828e-03j, -3.03418477e-03-1.73697658e-02j,
        -1.46248004e-02+1.43687704e-03j,  1.28490658e-02-1.19020417e-03j,
        -3.05758961e-03-2.96509231e-02j,  2.17073660e-02-4.42515471e-02j,
        -2.30717927e-02-4.44683312e-02j, -1.08123798e-02-2.55420945e-02j,
        -1.12943542e-02-4.47540361e-02j,  2.57365287e-02-4.88380228e-02j,
        -3.19899957e-02-5.66049951e-02j, -2.74752384e-02-2.19900869e-02j,
        -6.66050747e-03-3.89211784e-02j,  8.95625125e-03-2.23473908e-02j,
        -1.77046396e-02-3.91637209e-02j, -3.37667849e-02-2.67021181e-02j,
        -6.52801704e-02-1.58495275e-02j, -4.98323534e-02-7.56101464e-02j,
        -1.01268853e-01-8.83110321e-04j, -5.15791230e-02+3.00996887e-03j,
        -7.29204273e-02-3.23349687e-02j, -4.11983462e-02-6.39936171e-02j,
        -9.95394935e-02-1.39139231e-02j, -7.32203828e-02+7.66215766e-03j,
        -5.55633826e-02-3.31516314e-02j, -1.29070645e-02-3.92449709e-02j,
        -6.76268745e-02-2.56380361e-02j, -6.69950935e-02+6.27618442e-03j,
        -2.65187752e-02+7.94176905e-03j, -2.00767827e-02+1.36036135e-02j,
        -1.33518859e-02+1.68188627e-02j, -2.01494687e-02+7.41660765e-03j]),
 'job_id': '992165ff-296e-4548-9a04-5d46d3fac7f4',
 'eval_number': 28}

Qiskit shot simulator

Changing the backend again from a statevector_simulator backend to a shot-based backend, we can observe that the measurement outcome field is now populated by the counts_dictionary for n_shots executions.

[16]:
q_qiskit_shot = QAOA()
qiskit_shot_dev = create_device(location='local',name='qiskit.shot_simulator')
q_qiskit_shot.set_device(qiskit_shot_dev)
[17]:
q_qiskit_shot.compile(kp_qubo)
[18]:
q_qiskit_shot.optimize()
[19]:
q_qiskit_shot.result.most_probable_states
[19]:
{'solutions_bitstrings': ['001010101'], 'bitstring_energy': -1.0}
[20]:
q_qiskit_shot.result.evals
[20]:
{'number_of_evals': 32, 'jac_evals': 0, 'qfim_evals': 0}
[21]:
q_qiskit_shot.result.intermediate
[21]:
{'angles': [[0.35, 0.35],
  [1.35, 0.35],
  [1.35, 1.35],
  [2.324458067551, 0.125430468262],
  [1.837229033775, 0.237715234131],
  [1.101931527088, 0.318983347263],
  [1.383636915456, 0.597726780786],
  [1.440801226771, 0.264092274987],
  [1.287975879197, 0.342302049713],
  [1.253262993197, 0.394275750231],
  [1.291178419716, 0.279884153768],
  [1.264218964736, 0.362604057379],
  [1.250153929013, 0.390509921819],
  [1.267486781435, 0.416512512592],
  [1.219002511228, 0.38802966579],
  [1.256235030568, 0.404903004493],
  [1.242598810677, 0.388521117358],
  [1.254186882112, 0.383818849741],
  [1.24986035388, 0.394405124343],
  [1.248402501753, 0.389645514613],
  [1.251078496133, 0.388789493702],
  [1.252052813741, 0.388723315794],
  [1.250302532733, 0.388196572866],
  [1.249600564869, 0.387517665336],
  [1.250073715081, 0.388627920825],
  [1.249906622095, 0.389086721994],
  [1.250289389061, 0.388742329651],
  [1.249621135127, 0.388444645175],
  [1.250237260217, 0.388809187572],
  [1.249978733621, 0.388596639486],
  [1.250089355751, 0.388580430095],
  [1.250074486964, 0.388727917846]],
 'cost': [240.6,
  201.33,
  210.38,
  279.79,
  235.58,
  249.37,
  245.42,
  256.21,
  188.7,
  339.05,
  201.58,
  171.4,
  99.62,
  217.22,
  150.74,
  205.06,
  124.83,
  223.86,
  376.61,
  104.87,
  96.39,
  104.04,
  85.05,
  99.54,
  67.43,
  82.27,
  152.7,
  113.78,
  112.77,
  91.99,
  103.77,
  119.62],
 'measurement_outcomes': [],
 'job_id': ['d4a3a48f-5f58-4fff-952e-693a2b836e0a',
  'f828fafc-3bb5-40b3-9d5f-587d8ab81dc1',
  '2374aec7-4fad-4de6-b8ff-faf11d086d9d',
  'e9c50303-0355-44c5-ab08-944cc863087e',
  'd903af21-d7cc-4c6c-9cf6-bd90466f2cc9',
  '1a9d0a50-6c47-4f98-a92f-172d04fd0105',
  '8f2f8197-7cda-426c-86aa-71524e4a8b6a',
  'f62e655e-4bd3-427c-8fd8-e8541dd801b1',
  '740e4314-7835-4bab-a1f6-2cb2dba734be',
  '82ad593a-ade4-4a2b-9c07-ed2aa8fc3b37',
  '1c2654c3-8861-40f9-9076-fa999aaeffc3',
  'f1bced46-d81a-42fd-974f-c5347aa396de',
  '4b3afb7f-998a-4886-b69a-ed08227abd27',
  '56575baf-c1ba-4177-be8a-04fd3d8678bc',
  'bcc5f5fa-a88e-4430-ac86-1c89e76527b3',
  '1bbf7f7d-3215-4b3c-bd9e-e01dccbc2134',
  'f41aabd3-b49b-45b0-b626-d7ad3327a170',
  '0d473cbf-a863-4cfb-b3b6-e881a1e66a73',
  '1c894d75-9d56-4972-9101-2a2ce66d8f9a',
  '69998628-448f-4935-b266-6162eb12173c',
  '962630ed-bceb-4a11-9c91-89d229d96d9a',
  '7fd11bda-d777-4891-ba8a-36e69dd50897',
  '59723079-acb4-4042-a940-b221f565188a',
  'b3b70c20-a1d3-43e1-bb4a-b15b1694b0be',
  'f34039f5-da2f-484e-8865-feb9a34eafe2',
  '6821e37a-c4d1-41a0-9a7f-dcc634c91aee',
  'faf48107-9bcf-4b10-b24b-61b871dd96e0',
  '2945a017-b154-48b6-84ff-359ad45c6933',
  '5db56541-e674-4d8f-9a10-f3bff80dd67f',
  '9831ed3b-2308-44e6-a0b8-a4b496c60dd6',
  '80fc2ec8-b23f-4eae-a9c8-743445744b62',
  '89418050-bf68-437b-906c-d1ce779c604d']}
[22]:
q_qiskit_shot.result.optimized
[22]:
{'angles': [1.250073715081, 0.388627920825],
 'cost': 67.43,
 'measurement_outcomes': {'000110110': 1,
  '110011101': 1,
  '010110010': 1,
  '101000101': 1,
  '100011101': 1,
  '100111100': 1,
  '011011001': 1,
  '100101110': 1,
  '001110000': 1,
  '101000111': 1,
  '101110110': 1,
  '110100101': 1,
  '111000101': 2,
  '100110100': 3,
  '101011111': 1,
  '010110001': 3,
  '110010001': 2,
  '100110000': 3,
  '101100100': 2,
  '111010011': 1,
  '000111000': 1,
  '101010101': 1,
  '001100110': 1,
  '100101101': 1,
  '100010111': 1,
  '001010111': 1,
  '110110000': 1,
  '000111100': 1,
  '011000110': 1,
  '001010100': 2,
  '010010111': 1,
  '001010110': 2,
  '010101001': 1,
  '010110000': 1,
  '000110111': 2,
  '011000001': 1,
  '111010111': 1,
  '011010000': 1,
  '110101110': 1,
  '000010110': 1,
  '001010101': 4,
  '011001001': 1,
  '010010101': 3,
  '100111110': 1,
  '110010110': 1,
  '101110111': 1,
  '010100101': 2,
  '100010101': 1,
  '000010101': 1,
  '001100101': 3,
  '010010100': 1,
  '000110101': 2,
  '000111101': 1,
  '000111110': 1,
  '001101100': 1,
  '111010100': 1,
  '110010101': 2,
  '010100100': 1,
  '000000011': 1,
  '101001101': 1,
  '111100001': 1,
  '011100100': 2,
  '111100000': 1,
  '011100001': 1,
  '011010101': 1,
  '110111100': 1,
  '010011111': 2,
  '000110100': 1,
  '111010110': 1,
  '100110101': 1,
  '101011001': 1,
  '100010011': 1,
  '011010100': 2,
  '110010100': 1,
  '101011101': 1},
 'job_id': 'f34039f5-da2f-484e-8865-feb9a34eafe2',
 'eval_number': 25}
[23]:
fig, ax = q_qiskit_shot.result.plot_cost()
../_images/notebooks_08_results_example_28_0.png
[ ]: