Skip to content

Commit

Permalink
updated code for distribution plot
Browse files Browse the repository at this point in the history
  • Loading branch information
bluest93 committed Oct 15, 2024
1 parent 575ea79 commit a987cdd
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions docs/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"$$\\begin{array}{cccc}\\text{Problem:} & \\text{qubo} & & \\\\& & \\min \\quad \\displaystyle \\sum_{i = 0}^{n - 1} \\sum_{j = 0}^{n - 1} Q_{i, j} \\cdot x_{i} \\cdot x_{j} & \\\\\\text{{where}} & & & \\\\& x & 1\\text{-dim binary variable}\\\\\\end{array}$$"
],
"text/plain": [
"<jijmodeling.Problem at 0x10961b6b0>"
"<jijmodeling.Problem at 0x1186dfb60>"
]
},
"execution_count": 2,
Expand Down Expand Up @@ -282,7 +282,7 @@
{
"data": {
"text/plain": [
"{'001': 241, '000': 613, '100': 105, '101': 34, '111': 1, '010': 6}"
"{'000': 622, '100': 107, '010': 8, '001': 226, '101': 35, '011': 1, '111': 1}"
]
},
"execution_count": 9,
Expand Down Expand Up @@ -332,22 +332,15 @@
"sampleset = qaoa_converter.decode(qk_transpiler, job_result.data[\"meas\"])\n",
"\n",
"# Initialize a dictionary to accumulate occurrences for each energy value\n",
"energy_dict = defaultdict(int)\n",
"frequencies = defaultdict(int)\n",
"\n",
"# Define the precision to which you want to round the energy values\n",
"precision = 3 # You can adjust this value as needed\n",
"\n",
"for sample in sampleset:\n",
" energy = round(sample.eval.objective, precision) \n",
" occurrences = sample.num_occurrences\n",
" energy_dict[energy] += occurrences\n",
"\n",
"# Unpack the dictionary into lists of energies and their corresponding total occurrences\n",
"energies = list(energy_dict.keys())\n",
"total_occurrences = list(energy_dict.values())\n",
" energy = round(sample.eval.objective, ndigits = 3) \n",
" frequencies[energy] += sample.num_occurrences\n",
"\n",
"plt.bar(energies, total_occurrences, width=0.05)\n",
"plt.xlabel('Energy')\n",
"plt.bar(frequencies.keys(), frequencies.values(), width=0.05)\n",
"plt.xlabel('Objective')\n",
"plt.ylabel('Frequency')\n",
"plt.show()\n"
]
Expand Down

0 comments on commit a987cdd

Please sign in to comment.