Skip to content

Commit

Permalink
Merge branch 'qiskit_patterns' of github.com:eggerdj/qopt-best-practi…
Browse files Browse the repository at this point in the history
…ces into qiskit_patterns
  • Loading branch information
eggerdj committed Feb 26, 2024
2 parents 57c6a6f + d9bce4f commit 125de0e
Show file tree
Hide file tree
Showing 19 changed files with 1,297 additions and 3 deletions.
16 changes: 16 additions & 0 deletions demos/qiskit_patterns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Qiskit Patterns Lab Prep Work

## Requirements

- Laptop (Windows, MacOS or Linux), access to a terminal

## Instructions

1. Follow the instructions on https://docs.quantum.ibm.com/start/install#install-and-set-up-qiskit-with-the-qiskit-runtime-client
to install and set up a Python environment with Qiskit. Activate your environment.
2. Download the lab material, unzip the folder
3. Navigate to the `demo` directory using the terminal
4. run `pip install -r requirements.txt`
5. Activate your jupyter environment running `jupyter notebook`, this should open a browser window that shows the contents of
the `demo` directory
6. Open `test_installation.ipynb` and follow the instructions to test that the installation was successful
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ def plot_result(G, x):
def plot_distribution(final_distribution):
matplotlib.rcParams.update({'font.size': 10})
final_bits = final_distribution.binary_probabilities()
position = np.argmax(np.abs(list(final_bits.values())))

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')
ax.get_children()[position].set_color('tab:purple')
for p in positions:
ax.get_children()[int(p)].set_color('tab:purple')
plt.show()


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
1,200 changes: 1,200 additions & 0 deletions demos/qiskit_patterns/qiskit_patterns.ipynb

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions demos/qiskit_patterns/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
qiskit>=1.0.0
qiskit_ibm_runtime>=0.18.0
qiskit_optimization>=0.6.0
qiskit_aer
matplotlib
notebook
ipykernel
pylatexenc
66 changes: 66 additions & 0 deletions demos/qiskit_patterns/test_installation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"# Installation Test\n",
"\n",
"Run the cell below (press `Shift` + `Enter`) to check that all the imports work correctly. If you see the 🎉 emoji as the cell output, your installation was successful."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Your installation works 🎉!\n"
]
}
],
"source": [
"import matplotlib.pyplot\n",
"import networkx as nx\n",
"from demo_src.map import map_qubo_to_ising\n",
"from qiskit_ibm_runtime.fake_provider import FakeVigoV2\n",
"from qiskit import qpy\n",
"from qiskit_aer import Aer\n",
"from qiskit_optimization.applications import Maxcut\n",
"print(\"Your installation works 🎉!\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ibm_tech_clean",
"language": "python",
"name": "ibm_tech_clean"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

0 comments on commit 125de0e

Please sign in to comment.