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': 31, '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.8223704518158457, -0.5314001113292951],
  [1.586185225907923, -0.09070005566464756],
  [1.107374603993278, 0.2897263140949446],
  [0.8749867235178582, 0.19755325399524926],
  [1.0612880739434303, 0.40592025433265444],
  [1.3567495671193386, 0.27205917607329955],
  [1.2320620855563083, 0.2808927450841221],
  [1.0670972174373083, 0.24193528844973589],
  [1.094743897709029, 0.3183100115247915],
  [1.1340179855767438, 0.2733955848461378],
  [1.0969830083996708, 0.2780577509435139],
  [1.1151566208339982, 0.28903684318131206],
  [1.1040770285944774, 0.29680876795919425],
  [1.1067063950141847, 0.2858776408400736],
  [1.1072837668023456, 0.2916773255942363],
  [1.107303895808643, 0.2936303468661969],
  [1.1063072561663654, 0.291687390097385],
  [1.1072737374315564, 0.28972422634500533],
  [1.107278752116951, 0.29070077596962085],
  [1.1072900891144928, 0.2921655659115706],
  [1.1072980214083288, 0.2926537827259227],
  [1.10753420927316, 0.2921624047554971],
  [1.107547161195139, 0.2926505141969327],
  [1.1075422487867816, 0.2919183965363812],
  [1.1075373890194045, 0.2922623541887812],
  [1.1075437128127112, 0.29236215403666793],
  [1.1075873637360465, 0.29226076431565895],
  [1.1075956565986818, 0.2923604198645728]],
 'cost': [215.55245864841038,
  208.58887473577212,
  221.58228618277568,
  212.621735274073,
  215.21601846002002,
  179.81557052506525,
  313.3676827397906,
  211.93459524673585,
  218.21766505793317,
  219.78139454870873,
  198.5654003201057,
  231.28104089599907,
  201.77570799470453,
  211.57693552439068,
  199.8703295858099,
  377.13363259548,
  252.60576185800642,
  115.62625500572997,
  145.23626272919353,
  115.70281492829896,
  179.91722619304323,
  144.60097149086704,
  109.18161756329715,
  111.13693352016483,
  109.13785517037095,
  111.04266421496965,
  111.4542049344235,
  108.78174236033547,
  108.79507968918912,
  108.77261412200815,
  108.77970264336773],
 'measurement_outcomes': [],
 'job_id': ['9e9b7797-0545-4f6a-95dc-ddd0ba63bac6',
  'b62aac97-1405-4caa-8ad2-e02061475738',
  'e234b6e1-a936-4c34-abec-810f2c63ac16',
  'a4bd9283-8b6a-485d-a8e0-b749b3a951e0',
  '4343deb6-4a62-48b6-b141-2f5f15574c25',
  '843a2a9a-6126-442e-a7c1-e9b349223bb9',
  'bbec03d7-e020-4eed-b973-933c218a3c38',
  '4855056b-4c8d-4e86-9e3a-578df4304ef7',
  '79d713fc-6d70-43fd-be6d-456cea8d8f8e',
  'b766ee83-19c1-49b1-ab82-a3b2c1ac7b73',
  '27eb87d1-8e7e-46f4-b3b7-26b25165ec58',
  '422840f1-afa2-4caa-8757-5abed0657617',
  '97c0fc33-e9a1-466b-bf2d-aaf60021c259',
  '5badae0e-8f5b-4cb9-9480-5692f4d3f308',
  'bb8a1c97-cdf3-448a-aef9-5c3a37af0731',
  '4954b214-5e45-41f7-9747-84f2e7d458e2',
  '6febeb98-6ec2-4f6f-862b-e86a1c16496c',
  'ca263e8c-d168-473e-80e9-99d460607650',
  '1074ec66-fb92-4227-bbfa-d50bd8a7cb70',
  '342c0eba-f2c5-4f2c-9bb9-68c791dccdfe',
  '1d1ab943-06f7-4ca9-b33c-c952c40ac811',
  '686a041a-a144-44fe-a839-46041c5c99bd',
  'e6736002-0d3f-424a-8439-e5ce8c35d514',
  'e7fb2436-81d2-492e-927c-30e5badcdfa0',
  'd700329a-1cec-4a6c-9234-625ee32ded97',
  '332af79f-1c44-409a-92c7-b93f6c1f484f',
  'f61d7bd8-aff7-47e1-b72f-fcc9d6e578b9',
  '47822b62-5eb1-48eb-8cfe-244894889059',
  'd2f368b1-5e08-4114-88f7-c5257c26591f',
  'e1c755ec-f35d-48b7-9f78-757e52973edf',
  '14424dfa-e7af-484a-8682-36d11c13e10c']}
[15]:
qiskit_results.optimized
[15]:
{'angles': [1.1075873637360465, 0.29226076431565895],
 'cost': 108.77261412200815,
 'measurement_outcomes': array([-2.50571450e-02-1.40855054e-02j, -8.23577368e-03+1.89951876e-03j,
         2.88991779e-03+7.46081945e-03j,  6.75836257e-03+3.33613746e-03j,
        -7.62827839e-04+2.10353704e-02j,  1.19093708e-02+3.14523060e-02j,
        -2.10462377e-02+2.93320612e-03j, -1.11473586e-02-1.79174407e-02j,
         3.49117787e-02+3.59889631e-03j,  1.97877607e-02+2.64052630e-02j,
        -3.32961275e-02+6.91531940e-03j, -2.47370526e-02-1.17521748e-02j,
         7.46686813e-02-6.02820501e-03j,  2.00817207e-02+1.15348778e-02j,
        -3.18309488e-02+3.29982304e-03j, -3.28051639e-02-3.65410373e-03j,
         1.53831349e-02-3.95105715e-02j,  4.91063290e-02+4.15883539e-03j,
        -1.40408618e-02+5.06808580e-02j, -3.19958171e-02+1.99498227e-02j,
         6.94621966e-02-8.93889365e-02j,  5.17979602e-02-7.65128534e-03j,
        -2.99306186e-02+5.64407895e-02j, -4.76986293e-02+3.58338775e-02j,
         5.74205053e-02-1.11249027e-01j,  3.17373920e-02-1.81476848e-03j,
        -3.21485505e-02+4.74187237e-02j, -3.55383557e-02+3.59741735e-02j,
         2.06000112e-02-1.03266657e-01j, -5.05658654e-03-1.27068320e-02j,
        -5.41276520e-03+2.84173472e-02j, -4.71432409e-03+3.53164929e-02j,
        -1.77137476e-02+5.32449413e-03j,  1.71148871e-03+1.06255175e-03j,
         1.99630498e-03+7.85682908e-04j, -1.49894198e-02-5.70434447e-03j,
         2.25359613e-02+2.56400701e-02j, -2.20456140e-02-6.14192742e-03j,
        -2.72138601e-02-5.77134098e-03j,  8.47222679e-03-8.79501440e-03j,
         3.73134367e-02+5.61640671e-03j, -2.58403517e-02+4.80892877e-06j,
        -3.41331334e-02+3.15081897e-03j,  2.19960207e-02-2.29751847e-02j,
         4.96999358e-02-1.68973613e-02j, -1.46473902e-02+4.71013292e-03j,
        -2.68120712e-02+1.17131375e-02j,  3.71053256e-02-1.90433581e-02j,
         3.40164048e-02-3.46765849e-02j, -2.09798717e-02+2.85498014e-02j,
        -2.27851869e-02+4.48605907e-02j, -1.72435120e-02-4.47489234e-02j,
         4.62068566e-02-7.68589170e-02j, -1.65333865e-02+3.21926686e-02j,
        -2.29946271e-02+5.73641290e-02j,  6.60622311e-03-6.88556045e-02j,
         2.71049236e-02-7.53965041e-02j, -8.16364193e-03+1.63580929e-02j,
        -1.38420573e-02+4.32161927e-02j,  1.36631530e-02-7.08310141e-02j,
        -1.06814243e-02-5.84977443e-02j,  2.22675553e-02+4.87563881e-03j,
         1.73800927e-02+2.58581098e-02j,  1.21652941e-03-3.67813494e-02j,
        -1.76966533e-02+5.59091457e-03j,  7.12581779e-03-6.08184810e-03j,
        -2.36676627e-02-5.74837935e-04j,  1.09934825e-02-9.27167096e-03j,
        -7.79069715e-03+9.28166389e-03j, -7.06667245e-03+1.20754116e-02j,
         1.66439997e-02-3.07011161e-02j,  1.94541339e-04+1.15624970e-02j,
        -2.18734486e-03-7.22038826e-03j, -5.41822305e-03+2.77212340e-02j,
         2.41273739e-02-5.69831727e-02j,  4.73502948e-03+2.55598470e-02j,
         1.92223641e-02-2.08056078e-02j, -1.06016005e-02+3.45116568e-02j,
         3.49989535e-02-4.90158992e-02j, -1.29224696e-03+2.80013813e-02j,
        -1.50403467e-02+4.57623329e-03j,  3.09389364e-02+2.62999066e-02j,
        -5.87912349e-02-6.94992080e-02j,  3.51186157e-02+7.05163884e-03j,
        -6.42095607e-03-3.16409460e-02j,  3.58881669e-02+5.09096405e-02j,
        -4.36520022e-02-1.04439670e-01j,  4.10429748e-02+2.72773765e-02j,
        -1.33043219e-02-4.54012004e-02j,  3.41507805e-02+5.13146937e-02j,
        -2.33121408e-02-9.83753971e-02j,  3.44208025e-02+2.97728350e-02j,
        -9.55715808e-03-3.48299649e-02j,  2.55333543e-02+2.17384344e-02j,
        -2.36165640e-02-2.75478807e-02j,  1.93691791e-02+2.68087487e-03j,
        -1.15214374e-02+4.15359815e-03j, -1.61064182e-02+1.04560508e-02j,
        -1.15522496e-02-6.11449720e-03j, -7.39342793e-03+6.12350928e-03j,
        -6.98027026e-03+1.42451491e-02j, -1.18224866e-02-1.57343352e-02j,
         9.34786664e-03-1.34921822e-02j,  2.10991333e-03-9.49387642e-03j,
        -1.00480267e-03+7.34503004e-03j, -1.58170546e-02-3.61261051e-02j,
         1.74280885e-02-2.40890651e-02j, -1.23674793e-03-2.02234077e-02j,
         1.52331673e-02-1.80811626e-03j,  5.04473642e-03-4.43754694e-02j,
         2.23425847e-02-1.73640986e-02j,  1.68921521e-03-2.09291324e-02j,
         6.14274876e-03+1.21745755e-02j, -6.07445086e-02-3.41748965e-03j,
        -2.21838861e-02-3.96197004e-02j, -2.50661765e-02-9.01233754e-03j,
         1.64789571e-02-8.69722623e-03j, -6.19886054e-02-4.16963222e-02j,
        -8.15052722e-03-5.29231718e-02j, -3.00768582e-02-2.24618648e-02j,
         1.01486326e-02-2.07031490e-02j, -5.50714440e-02-5.74603802e-02j,
         1.33287073e-03-4.82156372e-02j, -2.53818964e-02-2.21944511e-02j,
         8.30701647e-03-2.39941823e-02j, -2.13136522e-02-2.61990559e-02j,
        -7.87137244e-03-1.64454910e-02j, -1.75382868e-02+2.93629037e-05j,
        -1.16560363e-02+3.34385744e-03j,  6.89848271e-03+5.14386147e-03j,
         5.73366781e-03-2.91192496e-04j, -9.43773075e-03-1.31544333e-02j,
         1.74298380e-02+2.40453901e-02j, -1.79865241e-02-2.97832317e-02j,
        -1.76911756e-02-1.08477904e-02j,  1.54552366e-02+4.78874544e-03j,
         2.72666355e-02+1.27348803e-02j, -3.32289097e-02-2.50749590e-02j,
        -2.58909157e-02-1.00966483e-03j,  3.80880977e-02-2.96280557e-04j,
         3.18985546e-02-2.62887438e-03j, -3.22346910e-02-1.37977589e-02j,
        -2.71049752e-02+9.67634432e-03j,  5.10032024e-02+7.10359994e-03j,
         3.73235423e-02-1.72006943e-02j, -5.45680174e-02+1.56543047e-02j,
        -2.05171681e-02+2.93496396e-02j,  2.47184276e-02-5.10600983e-02j,
         4.41213929e-02-4.01778221e-02j, -6.54382843e-02+2.62385905e-02j,
        -2.49778610e-02+4.75741890e-02j,  6.17164135e-02-6.22402603e-02j,
         2.81912466e-02-3.50644012e-02j, -4.44528079e-02+1.80501759e-02j,
        -1.40043158e-02+4.17328925e-02j,  6.32843712e-02-6.07031631e-02j,
        -5.95349633e-03-2.89031962e-02j,  6.93589360e-03+2.76614154e-02j,
         1.20297537e-02+3.07229541e-02j,  2.54021631e-02-4.20172982e-02j,
        -6.63951948e-03+2.51913233e-04j, -1.79912577e-02-1.23973159e-02j,
        -1.87986713e-02+2.82411949e-03j, -1.56682533e-02+9.28198674e-03j,
        -1.53419121e-02+1.56233063e-02j, -1.79093582e-03+3.67518447e-02j,
        -6.05494009e-03-1.55694326e-02j, -1.48726661e-02-2.05754297e-02j,
        -6.93320146e-03+1.53313599e-02j,  2.97654331e-02+3.34750070e-02j,
        -2.57775773e-03-3.47194561e-02j, -2.46764553e-02-3.73845338e-02j,
         1.40078368e-02+8.02111871e-03j,  5.98615328e-02+3.01814641e-02j,
         1.69771776e-02-3.53440752e-02j, -1.60007960e-02-3.88434762e-02j,
         9.84733628e-03+2.04614796e-02j,  5.73147780e-02-7.31338319e-03j,
        -5.11473582e-02-1.87338876e-02j, -7.04628983e-02+1.19038430e-02j,
         2.71457188e-02+4.76599504e-03j,  1.07609064e-01-2.91872256e-02j,
        -4.06722320e-02-5.17865839e-02j, -8.29073139e-02-1.19999224e-02j,
         2.10605575e-02-1.48742346e-02j,  9.32728868e-02-4.47541788e-02j,
        -3.10052341e-02-6.21752275e-02j, -7.19191401e-02-2.02621433e-02j,
         2.54153302e-02-3.22647287e-02j,  4.43469451e-02-6.00770338e-02j,
        -1.48578667e-02-2.65440684e-02j, -3.66246911e-02+6.45126493e-03j,
        -2.87573216e-03-4.43472601e-03j, -1.59805838e-02+4.45000226e-03j,
        -1.06877509e-03-9.02967301e-03j, -1.27272266e-02+9.03803152e-03j,
        -4.87403032e-03+1.19609598e-02j, -1.15415720e-03-1.87293762e-02j,
         5.96406805e-03+2.11880035e-03j, -2.93828783e-03-3.93142815e-03j,
         2.71411128e-03+1.70048397e-02j,  2.38970841e-03-3.93622950e-02j,
         1.47917238e-02+3.90643920e-03j, -4.45916381e-03-1.83639310e-02j,
         9.45841161e-03+1.96337253e-02j,  2.34891146e-02-4.19048550e-02j,
         1.52003369e-02+8.19378427e-03j,  6.36906503e-03-2.28793846e-02j,
         2.16343733e-02+1.01057861e-02j, -5.09953934e-02-3.23973873e-02j,
         1.27166029e-02-1.83396191e-02j, -2.58583988e-02-1.16949998e-04j,
         3.64085009e-02+1.35208398e-02j, -3.98271151e-02-6.94725359e-02j,
         2.60220408e-02-1.56100389e-02j, -2.75605069e-02-2.34639249e-02j,
         3.46353001e-02+8.64066242e-03j, -2.97301580e-02-8.03221410e-02j,
         2.59107759e-02-1.19936237e-02j, -2.54250900e-02-2.99273982e-02j,
         2.36372341e-02-4.65602770e-03j, -1.11607521e-02-3.79534195e-02j,
         8.31103236e-03-1.11802159e-02j, -1.59689177e-02-9.27821938e-03j,
        -1.80346023e-02+1.92953990e-02j, -1.88489311e-02+6.94131857e-03j,
        -8.53601757e-03+3.21091573e-03j, -2.11420782e-04-1.79628599e-02j,
        -2.06560281e-02-8.69266950e-03j, -1.13893429e-02-9.37451523e-03j,
         5.96898449e-03-2.26929203e-02j,  3.08795619e-02-3.53094853e-02j,
        -3.15689680e-02-3.16536737e-02j, -1.35522690e-02-2.43564629e-02j,
         1.99734585e-03-3.51925012e-02j,  3.76548402e-02-3.75699308e-02j,
        -8.60883241e-03-4.97812553e-02j, -1.24797457e-03-2.33431284e-02j,
         1.58357736e-03-2.90263034e-02j,  1.47533501e-02-1.38389027e-02j,
        -6.61032732e-02+2.48952150e-02j, -4.45583072e-02+1.02190090e-02j,
        -4.27503533e-02-2.60811766e-02j, -2.49656497e-02-8.22954048e-02j,
        -8.00557642e-02-2.09873030e-02j, -4.44902227e-02-1.19380095e-02j,
        -4.69185035e-02-3.72527597e-02j, -1.69967767e-02-6.64186306e-02j,
        -7.94298313e-02-4.29394196e-02j, -3.59753369e-02-1.99898186e-02j,
        -3.36251897e-02-3.17390051e-02j,  4.92164617e-03-3.57998555e-02j,
        -3.26476621e-02-2.15618623e-02j, -1.95392974e-02+2.72722172e-03j,
        -2.29008065e-02+5.98908517e-03j, -1.89441338e-02+1.08368463e-02j,
        -2.37090483e-03+3.71437525e-03j,  7.90324377e-03+1.12122254e-03j,
        -2.80493407e-02-1.73641490e-02j,  1.46165561e-02-9.70693538e-03j,
        -1.75064620e-02+7.26221528e-03j, -1.16971572e-02-1.17401332e-02j,
         2.31855053e-02-1.32121494e-02j,  5.70195756e-03+3.88159406e-03j,
        -2.16234973e-02+8.51652626e-03j, -2.27832731e-02-2.39244230e-03j,
         5.26944819e-02-3.12558892e-02j,  7.44454362e-03+1.74341712e-02j,
        -1.39644517e-02+5.28633329e-03j, -3.08643344e-02+5.77560799e-03j,
         7.07205910e-02-1.14985551e-02j, -5.18137593e-03+2.07652529e-02j,
        -5.45422727e-03+3.74623017e-02j, -1.90822322e-02+2.43951075e-02j,
        -8.63681702e-03-8.74770453e-02j,  2.73218680e-02-4.75862421e-03j,
        -8.44955359e-03+3.61256912e-02j, -3.13730273e-02+4.40642704e-02j,
         4.35454980e-02-1.12099249e-01j,  2.69140115e-02+1.81861089e-02j,
        -1.15588540e-02+2.59306895e-02j, -2.21218665e-02+4.39284707e-02j,
         6.24509419e-02-1.04210234e-01j,  2.22477413e-02+2.60911034e-02j,
         2.71559878e-03+1.13333298e-02j,  1.96432885e-03+3.47066013e-02j,
         1.86123771e-02-4.39505828e-02j,  9.20258708e-03+5.45732357e-03j,
        -1.21228239e-03-5.62421825e-04j, -1.52815066e-02-1.86983999e-03j,
        -9.72258669e-03-1.61924390e-02j,  1.49720270e-03+8.78074904e-03j,
        -2.28832955e-02+9.50122094e-04j,  4.46681529e-03-9.25455825e-03j,
         1.78904120e-02-6.15845652e-03j,  1.56705940e-03+1.19584660e-02j,
        -2.45701396e-02+7.66339150e-03j,  1.42850544e-02-2.50863801e-02j,
         3.58333741e-02-1.13737192e-02j, -3.58016421e-03+9.31350455e-03j,
        -1.43699974e-02+1.33924228e-02j,  3.07440329e-02-2.48748394e-02j,
         3.71769818e-02+2.25937654e-04j, -6.41596437e-03-3.28962235e-03j,
        -1.08895743e-02+3.72226006e-02j, -2.53556749e-02-3.57323958e-02j,
         5.40496657e-03-5.55380939e-02j,  1.25090210e-02+1.60704675e-02j,
        -4.79596089e-03+4.37581410e-02j, -7.29481760e-03-6.38807699e-02j,
         3.24763824e-02-5.96543397e-02j, -1.87200035e-03+9.56919640e-03j,
         4.14152557e-04+2.98061705e-02j, -1.23980719e-03-6.89389049e-02j,
         3.91863294e-02-4.86595993e-02j, -1.34718774e-02+9.05678485e-03j,
         2.00607956e-02+1.28801278e-02j, -4.26025887e-03-3.60463666e-02j,
         4.35690016e-03-2.36652407e-02j, -1.40920449e-02-9.16267253e-04j,
        -2.28243644e-02+4.01400110e-03j,  9.88884012e-03-9.82522033e-03j,
         2.22794403e-02-1.52488248e-03j, -2.16489684e-03+1.70678249e-02j,
         1.42543182e-02-3.46549604e-02j,  1.93049765e-04+1.79900164e-02j,
         3.65883936e-02-1.96677851e-02j, -1.51509252e-02+4.28408934e-02j,
         1.59708587e-02-6.34764761e-02j,  7.51162835e-03+3.27495588e-02j,
         2.33781446e-02-1.78350893e-02j, -1.47965389e-02+4.25832254e-02j,
         2.55359618e-02-5.96356074e-02j,  3.70944456e-03+3.39778492e-02j,
        -1.80071215e-02-2.39630943e-02j,  6.53966538e-03+1.80963191e-02j,
        -7.25458921e-02-6.36299632e-02j,  4.62615751e-02+9.83204510e-03j,
        -1.82584503e-03-5.33787169e-02j,  5.10749803e-02+5.84764948e-02j,
        -6.74195187e-02-1.02588744e-01j,  5.62971899e-02+2.93075850e-02j,
        -4.00149783e-02-3.60847166e-02j,  5.12353564e-02+3.94829830e-02j,
        -4.74479009e-02-9.77491128e-02j,  4.68375163e-02+3.05597251e-02j,
        -4.44540628e-02-2.44333390e-03j,  2.60420433e-02+1.64279887e-02j,
        -3.56895661e-02-2.50396199e-02j,  2.55285934e-02-1.23183383e-03j,
        -5.35340070e-02+1.15857872e-02j,  2.57244319e-02-2.12561657e-02j,
        -1.24898444e-02-2.30969946e-03j, -1.03638252e-02+8.23947520e-03j,
         9.88287305e-03+1.01174045e-02j, -1.99298155e-02-5.81554595e-03j,
         8.47672080e-03-1.26069844e-02j, -2.63902101e-03-1.66732485e-02j,
         1.91869025e-02+6.67070579e-03j, -8.87569119e-03-4.56780158e-02j,
         1.42830271e-02-2.56820964e-02j, -8.48008609e-03-3.06103877e-02j,
         1.16727448e-02+2.94322728e-03j, -7.54628972e-03-5.94499015e-02j,
         2.05785041e-02-2.30097912e-02j, -1.88675511e-03-2.98480133e-02j,
         1.10368959e-04-1.39228202e-02j,  2.71694007e-03-3.15711843e-02j,
        -2.56890484e-02-3.57192899e-02j, -4.40229950e-02-7.02543385e-03j,
         2.06757725e-02-1.49968141e-02j, -8.83120644e-02-3.16082064e-02j,
        -1.57882078e-02-5.43160623e-02j, -5.00644346e-02-2.50611772e-02j,
        -8.12220831e-04-2.11273155e-02j, -7.21708521e-02-4.06101580e-02j,
        -7.97265055e-03-5.14280283e-02j, -4.04887162e-02-2.80435576e-02j,
        -1.43633450e-02-1.15867028e-02j, -3.55683429e-02-4.17422977e-02j,
        -1.23273953e-02-1.85697842e-02j, -2.09973197e-02+2.18191155e-03j,
        -1.98676001e-02-9.23617153e-03j, -9.74486142e-03+1.55381975e-02j,
         4.31217407e-03-2.36116368e-03j, -1.16264667e-02-9.01325843e-03j,
         1.56819870e-03-1.33876062e-02j, -8.84355389e-03+1.42233916e-02j,
        -1.60677457e-02-5.03890286e-03j,  1.19440599e-02-2.65186688e-04j,
         8.30389541e-03-4.33277563e-05j, -1.52525248e-02+7.41881069e-03j,
        -2.01143725e-02+5.08678313e-03j,  3.06943728e-02-9.65548038e-03j,
         1.87626099e-02+4.50947723e-03j, -2.21301177e-02-2.78417494e-03j,
        -1.93440106e-02+1.48943692e-02j,  4.63266543e-02-5.10235508e-03j,
         1.55972380e-02+1.20744614e-02j, -9.01321875e-03-1.68051839e-02j,
        -9.35201045e-03+2.70042487e-02j,  7.28531680e-03-4.79800948e-02j,
         1.52222350e-02-2.51747590e-02j, -1.91734666e-02+3.45681976e-02j,
        -8.12047873e-03+4.38377992e-02j,  3.90694334e-02-6.67414935e-02j,
         3.04588068e-02-1.64455102e-02j, -3.01166812e-02+1.12347440e-02j,
         3.37524721e-05+3.77088066e-02j,  4.23256943e-02-6.83838639e-02j,
         3.14227957e-02-9.63188291e-03j, -3.66748018e-02-3.97316340e-03j,
         1.72227369e-02+2.35338343e-02j,  1.69574325e-02-4.33648647e-02j,
         9.31970144e-03-1.02149478e-02j, -1.45507577e-02-7.28607829e-03j,
        -1.83990249e-02+6.09264197e-03j, -1.49209612e-02+8.35797163e-03j,
         3.33616244e-03-4.23260061e-04j,  1.10880491e-02-1.84394117e-02j,
        -7.75539015e-03-1.16309608e-02j, -1.22348632e-02-1.33003992e-02j,
         2.13280291e-02+7.47159954e-03j,  4.96619735e-02+4.70808476e-03j,
        -6.48042703e-03-3.13795592e-02j, -1.93305611e-02-2.79616285e-02j,
         2.34308044e-02+6.24710919e-03j,  6.47665744e-02+1.35411101e-02j,
         1.33888482e-02-3.68620732e-02j, -1.13927363e-02-3.00663328e-02j,
         9.74994950e-03+1.89415647e-03j,  3.10775187e-02+2.38294662e-02j,
        -4.91960681e-02-1.01908590e-02j, -5.37158239e-02+1.29442671e-02j,
         2.84691823e-02-2.32526870e-02j,  6.63421685e-02-7.71488163e-02j,
        -4.35466529e-02-4.61618984e-02j, -6.32295793e-02-8.29693821e-03j,
         2.20213695e-02-2.02435837e-02j,  7.48751184e-02-4.91456207e-02j,
        -3.75885632e-02-5.84474983e-02j, -5.58110269e-02-1.53651514e-02j,
         1.36226930e-02-4.98462684e-03j,  7.03932737e-02-9.60095055e-03j,
        -1.82774562e-02-2.76098200e-02j, -3.05045435e-02+5.25863083e-03j,
        -1.37874430e-02-1.68963757e-03j, -1.13258632e-03-4.97721921e-04j,
        -2.41537805e-03-7.79691217e-03j, -1.50867592e-02+1.00335610e-02j,
         4.07447742e-03+1.22936047e-02j, -1.84020549e-02-1.68880112e-02j,
         7.23445488e-03+5.57594194e-03j, -2.68812509e-03-1.13728194e-02j,
         9.88896083e-03+2.73369879e-02j,  1.47793748e-02-4.87397486e-02j,
         1.70417546e-02+5.98896116e-03j, -5.45862543e-03-2.93257017e-02j,
         8.97293399e-03+2.46125084e-02j,  2.49488806e-02-6.12496342e-02j,
         1.90041563e-02+7.84592801e-03j,  6.62300569e-03-3.19353560e-02j,
         1.08170396e-02+3.11026190e-03j,  1.98552751e-02-2.52965796e-02j,
         1.74660782e-02-1.86565358e-02j, -4.05341452e-02-6.92146168e-03j,
         4.65275011e-02+9.87926913e-03j, -6.84398154e-02-7.53170856e-02j,
         3.15862479e-02-1.94543549e-02j, -4.27138517e-02-3.40944333e-02j,
         3.72260035e-02-2.90700545e-03j, -4.57077667e-02-7.36743362e-02j,
         2.93015427e-02-1.64413558e-02j, -3.60619300e-02-4.04381008e-02j,
         1.55467949e-02-4.95530026e-03j, -7.79771845e-03-5.52039887e-02j,
         8.88341107e-03-1.56075841e-02j, -2.08562049e-02-8.86797749e-03j,
         1.35479225e-03-2.00510987e-02j, -1.67399330e-02+1.37705577e-02j,
        -1.14640395e-02+7.59843400e-03j, -3.98419397e-03-1.67561178e-02j,
        -1.49713982e-02+2.96499924e-03j,  1.28724011e-02+1.61864877e-04j,
        -3.80696352e-03-2.91313492e-02j,  2.10841099e-02-4.40279709e-02j,
        -2.34868044e-02-4.44006447e-02j, -1.22466176e-02-2.56765982e-02j,
        -1.26427557e-02-4.46519473e-02j,  2.49616388e-02-4.85634919e-02j,
        -3.28589150e-02-5.67372749e-02j, -2.96042815e-02-2.20254462e-02j,
        -7.59728402e-03-3.88985024e-02j,  7.33549870e-03-2.17415282e-02j,
        -1.83790950e-02-3.86373953e-02j, -3.50594380e-02-2.72213903e-02j,
        -6.60049475e-02-1.34829332e-02j, -5.02863458e-02-7.37981247e-02j,
        -1.01801461e-01+4.56884460e-04j, -5.33485488e-02+5.45397418e-03j,
        -7.40996431e-02-3.04704101e-02j, -4.24076604e-02-6.14649222e-02j,
        -1.00061290e-01-1.23016549e-02j, -7.53792819e-02+9.40291046e-03j,
        -5.65156630e-02-3.16738286e-02j, -1.37856610e-02-3.65503124e-02j,
        -6.74611206e-02-2.42359526e-02j, -6.86491933e-02+6.95179729e-03j,
        -2.68094692e-02+1.01372573e-02j, -2.10915245e-02+1.57215973e-02j,
        -1.26874754e-02+1.94647308e-02j, -1.86658344e-02+8.70478829e-03j]),
 'job_id': 'e1c755ec-f35d-48b7-9f78-757e52973edf',
 'eval_number': 30}

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': ['011001101'], 'bitstring_energy': 23.0}
[20]:
q_qiskit_shot.result.evals
[20]:
{'number_of_evals': 28, '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.0387758875345465, 2.074974328339285],
  [0.9294310275785582, 1.6204103168083135],
  [1.5134137273840207, 1.1608018136914073],
  [1.4964298111208172, 1.5526285034616845],
  [1.4002805179806976, 1.6325053676255672],
  [1.6097578198123654, 1.4998860874570268],
  [1.4690393423116757, 1.49645010709426],
  [1.509357538752874, 1.5810790985041674],
  [1.4822045135995756, 1.5590923672777128],
  [1.5168116906549434, 1.5289400782996698],
  [1.48120940007154, 1.5490958398078623],
  [1.4992311993584597, 1.5599214713206564],
  [1.5027443183949776, 1.5480282693225806],
  [1.4926908725025503, 1.5537594884621744],
  [1.4970780013051206, 1.5544709330398767],
  [1.4960225433283174, 1.5507183123165849],
  [1.4962261772245673, 1.5516734078891345],
  [1.496907358907092, 1.5525266865135594],
  [1.4959181251868805, 1.5534602797665993],
  [1.4969081118689704, 1.5527267224690993],
  [1.4962710016218808, 1.5524430737234467],
  [1.4963498603092575, 1.5528591818362807],
  [1.4965282904502333, 1.5526458764774775],
  [1.4964211246129207, 1.5526777431263925],
  [1.4963784083425806, 1.5525427261080906]],
 'cost': [229.97000000000003,
  209.42000000000004,
  187.78999999999996,
  195.28000000000003,
  224.27999999999997,
  265.21000000000004,
  182.50000000000003,
  196.03000000000003,
  183.53000000000003,
  239.17999999999995,
  214.2299999999999,
  216.74999999999994,
  206.68,
  196.79999999999998,
  185.34,
  219.26000000000002,
  185.35000000000002,
  199.41000000000003,
  200.01999999999995,
  211.48999999999995,
  196.32,
  207.22000000000006,
  214.40000000000003,
  244.06999999999996,
  195.12,
  246.9799999999999,
  219.67,
  210.09],
 'measurement_outcomes': [],
 'job_id': ['7b2840d5-4c5a-4a9b-a31d-57e7533c5a6d',
  'f2a0d3cb-62ba-4f6b-ace7-a4fb7aa3341b',
  '0d8f133d-01d5-459c-a6d4-fd21d1e3dad5',
  '8bd0b767-6ad4-4524-a0b2-9a8575292ad1',
  '511b21ee-4593-48b4-8f62-eb42bca7e3c1',
  '4b11fc5e-cf9f-453d-8968-0b01e33d35c1',
  'ce5f297f-0253-49e3-8e48-da9f11b1939f',
  '3c66b891-4b22-4752-96f9-322e5bb7c107',
  '2e4da25f-0060-40dc-ae1e-985e39375c0f',
  'f3c2c37d-1af2-4441-b66b-54be92466179',
  'b2fe95fe-8e8a-48c4-834b-dad4a5d24eb6',
  '33bd71ae-934c-422f-b649-ebdd7b63f293',
  'f1152398-4bc8-4709-9d29-6b834b4c23ae',
  '8a64df2f-833e-4bd1-aab5-a4735749324d',
  'af2b51e0-6af6-43ee-bc97-fa8442a1caaa',
  '4f912d6a-b3f9-4340-a8e0-5ee4f5542bda',
  '8b631c66-9b07-46bb-aa42-5de5048225e1',
  '3a0fc1cc-f089-4c99-a45b-a91500110d00',
  '13bffc93-04b2-4b2b-a4e7-7764eb376efb',
  '57ef23af-b004-444e-82fc-a4fcec96b3bc',
  'ef2f97f3-43ed-4f66-876e-259938d93480',
  'a648ceca-53e0-47e5-a548-33bffefad228',
  'a180e8f5-5af8-4bad-aa82-0a9eb7195d33',
  '8226a5b4-2481-4295-9034-f5b01ab95621',
  'b73b32f8-7071-45ee-806a-66ba4c538d53',
  'f4fe0aec-67b5-41c4-bae6-c35602039d50',
  'cdccd4c5-fc10-49c3-a55d-d15b95954e48',
  'b9265ce0-01fd-450f-a7e0-a315faafebdf']}
[22]:
q_qiskit_shot.result.optimized
[22]:
{'angles': [1.4964298111208172, 1.5526285034616845],
 'cost': 182.50000000000003,
 'measurement_outcomes': {'100101000': 1,
  '010001110': 1,
  '001001010': 1,
  '110001101': 1,
  '000110011': 1,
  '101001100': 1,
  '100101011': 1,
  '111101111': 2,
  '101001000': 1,
  '101100011': 1,
  '000100110': 1,
  '010010100': 2,
  '010100011': 1,
  '001011001': 1,
  '110010111': 1,
  '000100011': 1,
  '100100000': 1,
  '011101001': 1,
  '110010110': 1,
  '000111000': 2,
  '010010011': 1,
  '000011101': 1,
  '101001011': 1,
  '011111101': 1,
  '111111001': 1,
  '111011000': 1,
  '100110101': 1,
  '101110000': 1,
  '111001100': 1,
  '100111000': 1,
  '110101101': 1,
  '101011011': 1,
  '110011000': 2,
  '111110001': 2,
  '010011100': 1,
  '111110100': 1,
  '011001101': 3,
  '100100100': 1,
  '110111001': 1,
  '010011101': 1,
  '101010100': 1,
  '110110110': 1,
  '100010010': 2,
  '101110111': 1,
  '110001011': 1,
  '010110110': 1,
  '001100111': 2,
  '011011001': 2,
  '101000010': 1,
  '101001001': 1,
  '001111110': 1,
  '000101101': 1,
  '011101000': 1,
  '000011110': 1,
  '111100110': 1,
  '000110111': 1,
  '111001110': 1,
  '111111000': 1,
  '011011110': 1,
  '011111111': 1,
  '101001110': 2,
  '001000000': 1,
  '110110101': 1,
  '110100100': 1,
  '011010100': 1,
  '111111101': 1,
  '001101001': 1,
  '110011110': 2,
  '101000110': 1,
  '000111001': 1,
  '111000101': 1,
  '111010001': 1,
  '110000011': 2,
  '001010101': 1,
  '011010010': 1,
  '001010000': 1,
  '100100001': 1,
  '101110100': 1,
  '110111010': 1,
  '111011111': 1,
  '000011100': 1,
  '011101110': 1,
  '000110000': 1,
  '110011111': 1,
  '101100100': 1,
  '100111010': 1,
  '000000110': 1},
 'job_id': 'ce5f297f-0253-49e3-8e48-da9f11b1939f',
 'eval_number': 7}
[23]:
q_qiskit_shot.result.plot_cost()
../_images/notebooks_08_results_example_28_0.png