From 49b903a32c8e8e78b93a1bf2315820bc7a31007a Mon Sep 17 00:00:00 2001 From: Shraddha Aangiras <63237790+shraddha-aangiras@users.noreply.github.com> Date: Sun, 29 Jan 2023 11:46:43 +0530 Subject: [PATCH 01/10] Adding Part1 --- part1.ipynb | 345 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 345 insertions(+) create mode 100644 part1.ipynb diff --git a/part1.ipynb b/part1.ipynb new file mode 100644 index 0000000..c4ac8af --- /dev/null +++ b/part1.ipynb @@ -0,0 +1,345 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "import qiskit\n", + "from qiskit import quantum_info\n", + "from qiskit.execute_function import execute\n", + "from qiskit import BasicAer\n", + "import numpy as np\n", + "import pickle\n", + "import json\n", + "import os\n", + "from collections import Counter\n", + "from sklearn.metrics import mean_squared_error\n", + "from typing import Dict, List\n", + "import matplotlib.pyplot as plt\n", + "import math\n", + "\n", + "# Utility functions (given to us)\n", + "\n", + "def simulate(circuit: qiskit.QuantumCircuit) -> dict:\n", + " \"\"\"Simulate the circuit, give the state vector as the result.\"\"\"\n", + " backend = BasicAer.get_backend('statevector_simulator')\n", + " job = execute(circuit, backend)\n", + " result = job.result()\n", + " state_vector = result.get_statevector()\n", + " histogram = dict()\n", + " for i in range(len(state_vector)):\n", + " population = abs(state_vector[i]) ** 2\n", + " if population > 1e-9:\n", + " histogram[i] = population\n", + " \n", + " return histogram\n", + "\n", + "\n", + "def histogram_to_category(histogram):\n", + " \"\"\"This function take a histogram representations of circuit execution results, and process into labels as described in \n", + " the problem description.\"\"\"\n", + " assert abs(sum(histogram.values())-1)<1e-8\n", + " positive=0\n", + " for key in histogram.keys():\n", + " digits = bin(int(key))[2:].zfill(20)\n", + " if digits[-1]=='0':\n", + " positive+=histogram[key]\n", + " \n", + " return positive\n", + "\n", + "\n", + "def count_gates(circuit: qiskit.QuantumCircuit) -> Dict[int, int]:\n", + " \"\"\"Returns the number of gate operations with each number of qubits.\"\"\"\n", + " counter = Counter([len(gate[1]) for gate in circuit.data])\n", + " #feel free to comment out the following two lines. But make sure you don't have k-qubit gates in your circuit\n", + " #for k>2\n", + " # for i in range(2,20):\n", + " # assert counter[i]==0\n", + " \n", + " return counter\n", + "\n", + "\n", + "def image_mse(image1,image2):\n", + " # Using sklearns mean squared error:\n", + " # https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html\n", + " return mean_squared_error(image1, image2)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "# #load the mock data (for testing only)\n", + "# files=os.listdir(\"mock_data\")\n", + "# dataset=list()\n", + "# for file in files:\n", + "# with open('mock_data/'+file, \"r\") as infile:\n", + "# loaded = json.load(infile)\n", + "# dataset.append(loaded)\n", + "\n", + "# Irrelevant data" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0. 0. 0. 0. 0. 0.\n", + " 0. 0. 0.00059977 0.00138408 0.00207612 0.00307574\n", + " 0.00202999 0.00092272 0.00098424 0.00127643 0.0028143 0.00299885\n", + " 0.00149173 0.00044598 0. 0. 0. 0.\n", + " 0. 0. 0. 0. ]\n", + "T-shirt?: False\n" + ] + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAAsTAAALEwEAmpwYAAAQiElEQVR4nO3dXYyc9XXH8d/Z2Rd712vjxcY2xuUtkBZFwjRb2iqkJUJBhBuDFNFQKSIq7eYiSEHKRRGVGm4qoaokygWK5AQUp6KkqRKE06AG6iZCpK1jg1wwuAXXsbFdv2Js/MLuzu6eXuw4Wpt9zrOel52xz/cjrWb2OfPMHI/98zMz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VdLmmTpHck/aukoQ7q7e8lvSHpdU0Ha1WbertN0y/RX5e0rfZzd7ufu6CveXne+LoskAQf0AFJEHYgCcIOJEHYgSQIO5AEYQeSIOxAEv8PE4DsMh8Hn6sAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "# Load Fashion-MNIST data (only t-shirts, label=0)\n", + "images = np.load('data/images.npy')\n", + "labels = np.load('data/labels.npy')\n", + "\n", + "# Visualizing the dataset\n", + "print(images[0][0])\n", + "plt.imshow(images[1100])\n", + "print('T-shirt?: ', labels[1100])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "def encode(image):\n", + " print(\"Encoding...\")\n", + " number_of_qubits = math.ceil(math.log(28*28, 2))\n", + " amplitude_vector = [0] * (2**number_of_qubits)\n", + " sum_squares = 0\n", + " amplitude_counter = 0\n", + " for i in image:\n", + " for j in i:\n", + " sum_squares+=j**2\n", + " amplitude_vector[amplitude_counter] = j\n", + " amplitude_counter+=1\n", + " global norm\n", + " norm = 1/np.sqrt(sum_squares)\n", + " amplitude_vector_new = [i*norm for i in amplitude_vector]\n", + " \n", + " # Some previous tests we were running -- ignore\n", + " \n", + " # global imtest\n", + " # imtest=[[0]*28 for z in range(28)]\n", + " # a_counter=0\n", + " # for i in range(28):\n", + " # for j in range(28):\n", + " # imtest[i][j]=amplitude_vector[a_counter]#/norm\n", + " # a_counter+=1\n", + " \n", + " \n", + " # print(amplitude_vector)\n", + " qr = qiskit.QuantumRegister(number_of_qubits)\n", + " qc = qiskit.QuantumCircuit(qr)\n", + " qc.initialize(amplitude_vector_new, qr)\n", + " # qc.draw\n", + " print(\"Encoded!\")\n", + " return qc\n", + "\n", + "def decode(histogram):\n", + " print(\"Decoding...\") \n", + " image = [[0] * 28 for z in range(28)]\n", + " amplitude_counter=1\n", + " for i in range(28):\n", + " for j in range(28):\n", + " image[i][j] = histogram.get(amplitude_counter, 0)#/norm\n", + " amplitude_counter+=1\n", + " print(\"Decoded!\")\n", + " return image\n", + "\n", + "def run_part1(image):\n", + " #encode image into a circuit\n", + " circuit = encode(image)\n", + "\n", + " #simulate circuit\n", + " histogram = simulate(circuit)\n", + "\n", + " #reconstruct the image\n", + " image_re = decode(histogram)\n", + "\n", + " return circuit, image_re" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Encoding...\n", + "Encoded!\n" + ] + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAAsTAAALEwEAmpwYAAAUAklEQVR4nO3da4xd1XUH8P+aO/fO02/j8RuwMS6PgqGDoQFFNLQOuI0glUqxVORWqEZtqBKVD0VUKv7QD6hqoFRqo0wCjdMGUCRCsVLUBBwqBDQug+XgF9gGTGwzHtsM9njG87iP1Q9zHE1g9trDPfdlr/9PGs3MXXPuWffMrDn33nX23qKqIKILX1O9EyCi2mCxEznBYidygsVO5ASLnciJ5lruLCct2oqOWu6yMbS3muFCR8aMF9vsjsnsjrPB2Kkh+3jnBu37VhEzXor8BeXmjQVj2aaiue3QQLt936cLZlxHw/u+UI1iGOM6NuUvLVWxi8jtAJ4AkAHwXVV91Pr5VnTgRrktzS7PS3LV1Wa8/8aZZvzUVfYf9R/e2BuMPf/GDea2y35iF3spaxf7yDz7yeHiez8Ixha1nTa3/d9nrzPjS//ruBkvvnvQjF+Ituu2YKzsp/EikgHwLwDuAHAlgA0icmW590dE1ZXmNftaAAdV9X1VHQfwLIA7K5MWEVVammJfAuDwpO+PJLf9GhHZJCK9ItKbh7/XUESNourvxqtqj6p2q2p3Fi3V3h0RBaQp9qMAlk36fmlyGxE1oDT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Vq6a5FbX1+xEVDv1PrMTUY2w2ImcqEuxi8jtIvKuiBwUkYfqkUOIiBwSkV0islNEeuucy1MiclxEdk+6ba6IvCQiB5LPU66xV6fcNovI0eTY7RSR9XXKbZmIvCIie0Vkj4h8Pbm9rsfOyKsmx63mr9lFJANgP4DfA3AEwJsANqjq3pomEiAihwB0q2rdL8AQkS8CGALwfVW9OrntHwAMqOqjyT/KOar6Nw2S22YAQ/VexjtZrWjR5GXGAdwF4E9Rx2Nn5HU3anDc6nFmXwvgoKq+r6rjAJ4FcGcd8mh4qvoqgIFP3XwngC3J11sw8cdSc4HcGoKq9qnqjuTrMwDOLTNe12Nn5FUT9Sj2JQAOT/r+CBprvXcF8FMReUtENtU7mSl0qWpf8vUxAF31TGYK0WW8a+lTy4w3zLErZ/nztPgG3WfdoqrXA7gDwNeSp6sNSSdegzVS73Ray3jXyhTLjP9KPY9ducufp1WPYj8KYNmk75cmtzUEVT2afD4O4Hk03lLU/edW0E0+H69zPr/SSMt4T7XMOBrg2NVz+fN6FPubAFaJyKUikgNwD4CtdcjjM0SkI3njBCLSAWAdGm8p6q0ANiZfbwTwQh1z+TWNsox3aJlx1PnY1X35c1Wt+QeA9Zh4R/49AH9bjxwCea0A8IvkY0+9cwPwDCae1uUx8d7GfQDmAdgG4ACAlwHMbaDc/h3ALgBvY6KwFtUpt1sw8RT9bQA7k4/19T52Rl41OW68XJbICb5BR+QEi53ICRY7kRMsdiInWOxETrDYiZxgsRM58f9ZgRxkql37RQAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "test_image = images[0]\n", + "plt.imshow(test_image)\n", + "\n", + "encoded = encode(test_image)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Decoding...\n", + "Decoded!\n", + "6.190224439177201e-07\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAAsTAAALEwEAmpwYAAAS8UlEQVR4nO3dbYxc1XkH8P9/ZmfXXq/Xr7BsbPPmWE0NaUyzMWmIKiqU1EGNIChCWFVElKhOpVARKR+KyIf4Qz+gKiGK1CqtAwinSYioEopVaBNwaRFNamGQY5t3xzYBs/Ya/Lb22vsy8/TDXtAa73nOeO7M3MHn/5NWO3ufufeeuTvP3Jl57jmHZgYRufCVim6AiLSHkl0kEUp2kUQo2UUSoWQXSURXO3fWzR6bg3nt3GV7kH64p9uNV3v9f8PUwpob7zoafs0uj55x1wX8tqPsnw/OXFzx1+8Kt73nUKQSdDrSdhWSznEGpzBh47P+U3MlO8l1AL4PoAzgPjO7x7v/HMzDtbwhzy47Ent63Hhp5WVu/NgfLXbjR2455caX/GtvMLbgqT3uuiiX/Xh/nxt++W8ucuNcNBGMrbo3HAMA7HrFDdvUlL9+grbZ1mCs4bfxJMsA/hHA5wCsBrCe5OpGtycirZXnM/taAHvMbK+ZTQD4GYCbmtMsEWm2PMm+DMAbM/5+M1t2FpIbSG4nuX0S4zl2JyJ5tPzbeDPbZGZDZjZUgf/ZVkRaJ0+yHwCwYsbfy7NlItKB8iT7swBWkbyCZDeA2wBsaU6zRKTZGi69mdkUyTsA/BLTpbcHzOyFprWsyVjxa92n161x42+sC9ejuy8ac9cdH/U/vvS95L/mVvf65a/bNj4ejF30dyf8decfdeOPjc1x49/Z9+dufOS/zvka5z37vuhvu/ytj7jx08f99Zf/e7is2PvINnfdC1GuOruZPQ4g/EwTkY6hy2VFEqFkF0mEkl0kEUp2kUQo2UUSoWQXSQTbObpsPxdbq7q4ssuvIu7b+Al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4LDpvKuotAG7Pbt8O4NEC23KWTpnGOzTNOAo+doVPf25mbf8BcCOmv5H/HYBvFdGGQLuuBPDb7OeFotsG4CFMv62bxPR3G18FsATAVgCvAXgSwOIOatu/ANgFYCemE2uwoLZ9GtNv0XcC2JH93Fj0sXPa1ZbjpstlRRKhL+hEEqFkF0mEkl0kEUp2kUQo2UUSoWQXSYSSXSQR/w8gZIpBFdJ+/AAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "decoded = decode(simulate(encoded))\n", + "print(image_mse(images[0], decoded))\n", + "plt.imshow(decoded)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Encoding...\n", + "Encoded!\n" + ] + } + ], + "source": [ + "# Submission grade\n", + "\n", + "n = 1 # for one image\n", + "mse = 0\n", + "gatecount = 0\n", + "test_image = images[0] # same image that is shown above\n", + "\n", + "\n", + " \n", + "#encode image into circuit\n", + "circuit, image_re = run_part1(test_image)\n", + "\n", + "#count the number of qubit gates used\n", + "gatecount += count_gates(circuit)[2]\n", + "\n", + "# calculate mean square error\n", + "mse += image_mse(test_image, image_re)\n", + " \n", + "#fidelity of reconstruction\n", + "fidelity = 1 - mse\n", + "gatecount = gatecount / n\n", + "print('gatecount', gatecount)\n", + "print('fidelity' , fidelity)\n", + "\n", + "#score for part1 \n", + "print(fidelity * (0.999 ** gatecount))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 [Default]", + "language": "python", + "name": "python3" + }, + "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.9.10" + }, + "vscode": { + "interpreter": { + "hash": "397704579725e15f5c7cb49fe5f0341eb7531c82d19f2c29d197e8b64ab5776b" + } + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 724f184a3e3308afd917c293916a7896712d251a Mon Sep 17 00:00:00 2001 From: areebruh <90187451+areebruh@users.noreply.github.com> Date: Sun, 29 Jan 2023 13:17:29 +0500 Subject: [PATCH 02/10] Create our code --- our code | 1 + 1 file changed, 1 insertion(+) create mode 100644 our code diff --git a/our code b/our code new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/our code @@ -0,0 +1 @@ + From 033f3cb6dbd08f11431f7888784a0ba325f585d8 Mon Sep 17 00:00:00 2001 From: Shraddha Aangiras <63237790+shraddha-aangiras@users.noreply.github.com> Date: Sun, 29 Jan 2023 20:08:04 +0530 Subject: [PATCH 03/10] Add files via upload --- part_1.py | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 part_1.py diff --git a/part_1.py b/part_1.py new file mode 100644 index 0000000..e3493f6 --- /dev/null +++ b/part_1.py @@ -0,0 +1,204 @@ +#!/usr/bin/env python +# coding: utf-8 + +# In[6]: + + +import qiskit +from qiskit import quantum_info +from qiskit.execute_function import execute +from qiskit import BasicAer +import numpy as np +import pickle +import json +import os +from collections import Counter +from sklearn.metrics import mean_squared_error +from typing import Dict, List +import matplotlib.pyplot as plt +import math + +# Utility functions (given to us) + +def simulate(circuit: qiskit.QuantumCircuit) -> dict: + """Simulate the circuit, give the state vector as the result.""" + backend = BasicAer.get_backend('statevector_simulator') + job = execute(circuit, backend) + result = job.result() + state_vector = result.get_statevector() + histogram = dict() + for i in range(len(state_vector)): + population = abs(state_vector[i]) ** 2 + if population > 1e-9: + histogram[i] = population + + return histogram + + +def histogram_to_category(histogram): + """This function take a histogram representations of circuit execution results, and process into labels as described in + the problem description.""" + assert abs(sum(histogram.values())-1)<1e-8 + positive=0 + for key in histogram.keys(): + digits = bin(int(key))[2:].zfill(20) + if digits[-1]=='0': + positive+=histogram[key] + + return positive + + +def count_gates(circuit: qiskit.QuantumCircuit) -> Dict[int, int]: + """Returns the number of gate operations with each number of qubits.""" + counter = Counter([len(gate[1]) for gate in circuit.data]) + #feel free to comment out the following two lines. But make sure you don't have k-qubit gates in your circuit + #for k>2 + # for i in range(2,20): + # assert counter[i]==0 + + return counter + + +def image_mse(image1,image2): + # Using sklearns mean squared error: + # https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html + return mean_squared_error(image1, image2) + + +# In[17]: + + +#load the mock data (for testing only) +files=os.listdir("mock_data") +dataset=list() +for file in files: + with open('mock_data/'+file, "r") as infile: + loaded = json.load(infile) + dataset.append(loaded) + +# Irrelevant data + + +# In[52]: + + +# Load Fashion-MNIST data (only t-shirts, label=0) +images = np.load('data/images.npy') +labels = np.load('data/labels.npy') +images *= 255 + +# Visualizing the dataset +print(images[0][0]) +plt.imshow(images[1100]) +print('T-shirt?: ', labels[1100]) + + +# In[53]: + + +def encode(image): + print("Encoding...") + number_of_qubits = math.ceil(math.log(28*28, 2)) + amplitude_vector = [0] * (2**number_of_qubits) + sum_squares = 0 + amplitude_counter = 0 + for i in image: + for j in i: + sum_squares+=j**2 + amplitude_vector[amplitude_counter] = j + amplitude_counter+=1 + global norm + norm = 1/np.sqrt(sum_squares) + amplitude_vector_new = [i*norm for i in amplitude_vector] + + # Some previous tests we were running -- ignore + + # global imtest + # imtest=[[0]*28 for z in range(28)] + # a_counter=0 + # for i in range(28): + # for j in range(28): + # imtest[i][j]=amplitude_vector[a_counter]#/norm + # a_counter+=1 + + + # print(amplitude_vector) + qr = qiskit.QuantumRegister(number_of_qubits) + qc = qiskit.QuantumCircuit(qr) + qc.initialize(amplitude_vector_new, qr) + + print("Encoded!") + return qc + +def decode(histogram): + print("Decoding...") + image = [[0] * 28 for z in range(28)] + amplitude_counter=1 + for i in range(28): + for j in range(28): + image[i][j] = histogram.get(amplitude_counter, 0)#/norm + amplitude_counter+=1 + print("Decoded!") + return image + +def run_part1(image): + #encode image into a circuit + circuit = encode(image) + + #simulate circuit + histogram = simulate(circuit) + + #reconstruct the image + image_re = decode(histogram) + + return circuit, image_re + + +# In[54]: + + +test_image = images[0] +plt.imshow(test_image) + +encoded = encode(test_image) +encoded.draw(output='mpl') + + +# In[55]: + + +decoded = decode(simulate(encoded)) +print(image_mse(images[0], decoded)) +plt.imshow(decoded) + + +# In[13]: + + +# Submission grade + +n = 1 # for one image +mse = 0 +gatecount = 0 +test_image = images[1200] # same image that is shown above + + + +#encode image into circuit +circuit, image_re = run_part1(test_image) + +#count the number of qubit gates used +gatecount += count_gates(circuit)[2] + +# calculate mean square error +mse += image_mse(test_image, image_re) + +#fidelity of reconstruction +fidelity = 1 - mse +gatecount = gatecount / n +print('gatecount', gatecount) +print('fidelity' , fidelity) + +#score for part1 +print(fidelity * (0.999 ** gatecount)) + From 581806d8121c9d4a72ffcb16049d02c6d02c470b Mon Sep 17 00:00:00 2001 From: Shraddha Aangiras <63237790+shraddha-aangiras@users.noreply.github.com> Date: Sun, 29 Jan 2023 20:10:41 +0530 Subject: [PATCH 04/10] Update test.py --- test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test.py b/test.py index 658a3b2..c6966b4 100644 --- a/test.py +++ b/test.py @@ -7,6 +7,9 @@ from collections import Counter from sklearn.metrics import mean_squared_error +teamname="Feynman's Fashion Rescue" + + if len(sys.argv) > 1: data_path = sys.argv[1] else: From 2001cb3a7f5dacdfcdf7363029bfced659902b8a Mon Sep 17 00:00:00 2001 From: Shraddha Aangiras <63237790+shraddha-aangiras@users.noreply.github.com> Date: Sun, 29 Jan 2023 20:15:21 +0530 Subject: [PATCH 05/10] Update and rename part_1.py to part1.py --- part_1.py => part1.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename part_1.py => part1.py (98%) diff --git a/part_1.py b/part1.py similarity index 98% rename from part_1.py rename to part1.py index e3493f6..ab49778 100644 --- a/part_1.py +++ b/part1.py @@ -1,8 +1,9 @@ #!/usr/bin/env python # coding: utf-8 -# In[6]: +teamname="Feynman's Fashion Rescue" +task="part 2" import qiskit from qiskit import quantum_info @@ -20,6 +21,7 @@ # Utility functions (given to us) + def simulate(circuit: qiskit.QuantumCircuit) -> dict: """Simulate the circuit, give the state vector as the result.""" backend = BasicAer.get_backend('statevector_simulator') From 4da1a6d4a0af4d846e984264a9382427b2ed80a7 Mon Sep 17 00:00:00 2001 From: Shraddha Aangiras <63237790+shraddha-aangiras@users.noreply.github.com> Date: Sun, 29 Jan 2023 20:34:35 +0530 Subject: [PATCH 06/10] Add files via upload --- part2_example_qiskit (2).ipynb | 485 +++++++++++++++++++++++++++++++++ quantum_classifier_2.pickle | Bin 0 -> 47381 bytes 2 files changed, 485 insertions(+) create mode 100644 part2_example_qiskit (2).ipynb create mode 100644 quantum_classifier_2.pickle diff --git a/part2_example_qiskit (2).ipynb b/part2_example_qiskit (2).ipynb new file mode 100644 index 0000000..dd09070 --- /dev/null +++ b/part2_example_qiskit (2).ipynb @@ -0,0 +1,485 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import gzip\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from pylab import cm\n", + "import warnings\n", + "\n", + "from sklearn import datasets\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.preprocessing import StandardScaler, MinMaxScaler\n", + "from sklearn.decomposition import PCA\n", + "from sklearn.svm import SVC\n", + "from sklearn.metrics import accuracy_score\n", + "\n", + "import qiskit\n", + "from qiskit import *\n", + "from qiskit import quantum_info\n", + "from qiskit.execute_function import execute\n", + "from qiskit import BasicAer\n", + "\n", + "from qiskit import Aer, execute\n", + "from qiskit.circuit import QuantumCircuit, Parameter, ParameterVector\n", + "from qiskit.circuit.library import PauliFeatureMap, ZFeatureMap, ZZFeatureMap\n", + "from qiskit.circuit.library import TwoLocal, NLocal, RealAmplitudes, EfficientSU2\n", + "from qiskit.circuit.library import HGate, RXGate, RYGate, RZGate, CXGate, CRXGate, CRZGate\n", + "from qiskit_machine_learning.kernels import QuantumKernel\n", + "\n", + "import numpy as np\n", + "import pickle\n", + "import json\n", + "import os\n", + "from collections import Counter\n", + "from sklearn.metrics import mean_squared_error\n", + "from typing import Dict, List\n", + "\n", + "#define utility functions\n", + "\n", + "def simulate(circuit: qiskit.QuantumCircuit) -> dict:\n", + " \"\"\"Simulate the circuit, give the state vector as the result.\"\"\"\n", + " backend = BasicAer.get_backend('statevector_simulator')\n", + " job = execute(circuit, backend)\n", + " result = job.result()\n", + " state_vector = result.get_statevector()\n", + " \n", + " histogram = dict()\n", + " for i in range(len(state_vector)):\n", + " population = abs(state_vector[i]) ** 2\n", + " if population > 1e-9:\n", + " histogram[i] = population\n", + " \n", + " return histogram\n", + "\n", + "\n", + "def histogram_to_category(histogram):\n", + " \"\"\"This function take a histogram representations of circuit execution results, and process into labels as described in \n", + " the problem description.\"\"\"\n", + " assert abs(sum(histogram.values())-1)<1e-8\n", + " positive=0\n", + " for key in histogram.keys():\n", + " digits = bin(int(key))[2:].zfill(20)\n", + " if digits[-1]=='0':\n", + " positive+=histogram[key]\n", + " \n", + " return positive\n", + "\n", + "\n", + "def count_gates(circuit: qiskit.QuantumCircuit) -> Dict[int, int]:\n", + " \"\"\"Returns the number of gate operations with each number of qubits.\"\"\"\n", + " counter = Counter([len(gate[1]) for gate in circuit.data])\n", + " #feel free to comment out the following two lines. But make sure you don't have k-qubit gates in your circuit\n", + " #for k>2\n", + " for i in range(2,20):\n", + " assert counter[i]==0\n", + " \n", + " return counter" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# #load the mock data (for testing only)\n", + "# files=os.listdir(\"mock_data\")\n", + "# dataset=list()\n", + "# for file in files:\n", + "# with open('mock_data/'+file, \"r\") as infile:\n", + "# loaded = json.load(infile)\n", + "# dataset.append(loaded)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAAsTAAALEwEAmpwYAAAQiElEQVR4nO3dXYyc9XXH8d/Z2Rd712vjxcY2xuUtkBZFwjRb2iqkJUJBhBuDFNFQKSIq7eYiSEHKRRGVGm4qoaokygWK5AQUp6KkqRKE06AG6iZCpK1jg1wwuAXXsbFdv2Js/MLuzu6eXuw4Wpt9zrOel52xz/cjrWb2OfPMHI/98zMz//k/f3N3Abj0dbW7AQDzg7ADSRB2IAnCDiRB2IEkuufzwXqtzxdoYD4f8qJgvb1hfWx5T1jv7q8W1qpj8b42EZZlU3F9qi8ezVk6cKaw9sH4gnDf7gMWP/jpD+N6QqM6rXEfm/WJayjsZnaXpG9Jqkj6rrs/Ht1+gQb0+3ZHIw95Sepe/Vth/Z2R1WF95ScPFtb27bwi3LfvSCWsd42HZZ25tvg/Gkm6b3hLYe3Fd3873PeKv4n/o9Kv3ojrCW32TYW1ul/Gm1lF0pOSPifpJkn3m9lN9d4fgNZq5D37rZJ2uvsudx+X9ANJ65rTFoBmayTsqyXtnfH7vtq2c5jZiJltNbOtVY018HAAGtHyT+Pdfb27D7v7cI/6Wv1wAAo0Evb9ktbM+P2q2jYAHaiRsG+RdIOZXWtmvZK+IGljc9oC0Gx1D725+4SZPSTpZ5oeenva3d9sWmeJ7PzzeGjt+T99Iqz/+4fXFdbWXP9euO+dwRj9XGw83R/Wd46tLKz95Jbvhvt+euThsH7jr8IyztPQOLu7vyDphSb1AqCF+LoskARhB5Ig7EAShB1IgrADSRB2IIl5nc+O2a38z8mwvuXz8RTYd8cvL6wdqi4J9335VDyXvlIyob2vZEJ81Yun0G4evTLct39X3BsuDEd2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7uOSfiBpXRv66Hju/rKkY+dtXidpQ+36Bk3/Y5l3Bb11BHc/4O6v1a6flHR2mfG2PndBX/OiHWFfLWnvjN/3qbPWe3dJL5rZq2Y20u5mZrHC3c+uqXRQ0op2NjOL0mW859N5y4x3zHNXz/LnjeIDuo+6zd1/V9LnJH2l9nK1I/n0e7BOGjud0zLe82WWZcZ/o53PXb3LnzeqHWHfL2nmGRSvqm3rCO6+v3Z5WNJz6rylqA+dXUG3dnm4zf38Rict4z3bMuPqgOeuncuftyPsWyTdYGbXmlmvpC9I2tiGPj7CzAZqH5zIzAYk3anOW4p6o6QHatcfkPR8G3s5R6cs4120zLja/Ny1fflzd5/3H0l3a/oT+f+V9Fft6KGgr+sk/Vft58129ybpWU2/rKtq+rONByVdLmmTpHck/aukoQ7q7e8lvSHpdU0Ha1WbertN0y/RX5e0rfZzd7ufu6CveXne+LoskAQf0AFJEHYgCcIOJEHYgSQIO5AEYQeSIOxAEv8PE4DsMh8Hn6sAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "#load the actual hackthon data (fashion-mnist)\n", + "images=np.load('data/images.npy')\n", + "labels=np.load('data/labels.npy')\n", + "#you can visualize it\n", + "import matplotlib.pyplot as plt\n", + "plt.imshow(images[1100])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "#your submission\n", + "\n", + "# Functions 'encode' and 'decode' are dummy.\n", + "def encode(image):\n", + " print(\"Encoding...\")\n", + " number_of_qubits = math.ceil(math.log(28*28, 2))\n", + " amplitude_vector = [0] * (2**number_of_qubits)\n", + " sum_squares = 0\n", + " amplitude_counter = 0\n", + " for i in image:\n", + " for j in i:\n", + " sum_squares+=j**2\n", + " amplitude_vector[amplitude_counter] = j\n", + " amplitude_counter+=1\n", + " global norm\n", + " norm = 1/np.sqrt(sum_squares)\n", + " amplitude_vector_new = [i*norm for i in amplitude_vector]\n", + " \n", + " # Some previous tests we were running -- ignore\n", + " \n", + " # global imtest\n", + " # imtest=[[0]*28 for z in range(28)]\n", + " # a_counter=0\n", + " # for i in range(28):\n", + " # for j in range(28):\n", + " # imtest[i][j]=amplitude_vector[a_counter]#/norm\n", + " # a_counter+=1\n", + " \n", + " \n", + " # print(amplitude_vector)\n", + " qr = qiskit.QuantumRegister(number_of_qubits)\n", + " qc = qiskit.QuantumCircuit(qr)\n", + " qc.initialize(amplitude_vector_new, qr)\n", + "\n", + " print(\"Encoded!\")\n", + " return qc\n", + "\n", + "def decode(histogram):\n", + " print(\"Decoding...\") \n", + " image = [[0] * 28 for z in range(28)]\n", + " amplitude_counter=1\n", + " for i in range(28):\n", + " for j in range(28):\n", + " image[i][j] = histogram.get(amplitude_counter, 0)#/norm\n", + " amplitude_counter+=1\n", + " print(\"Decoded!\")\n", + " return image\n", + "\n", + "def run_part1(image):\n", + " #encode image into a circuit\n", + " circuit=encode(image)\n", + "\n", + " #simulate circuit\n", + " histogram=simulate(circuit)\n", + "\n", + " #reconstruct the image\n", + " image_re=decode(histogram)\n", + "\n", + " return circuit,image_re\n", + "\n", + "\n", + "def run_part2(image):\n", + " # load the quantum classifier circuit\n", + " classifier=qiskit.QuantumCircuit.from_qasm_file('quantum_classifier.qasm')\n", + " \n", + " #encode image into circuit\n", + " circuit=encode(image)\n", + " \n", + " #append with classifier circuit\n", + " nq1 = circuit.width()\n", + " nq2 = classifier.width()\n", + " nq = max(nq1, nq2)\n", + " qc = qiskit.QuantumCircuit(nq)\n", + " qc.append(circuit.to_instruction(), list(range(nq1)))\n", + " qc.append(classifier.to_instruction(), list(range(nq2)))\n", + " \n", + " #simulate circuit\n", + " histogram=simulate(qc)\n", + " \n", + " #convert histogram to category\n", + " label=histogram_to_category(histogram)\n", + " \n", + " #thresholding the label, any way you want\n", + " if label>0.5:\n", + " label=1\n", + " else:\n", + " label=0\n", + " \n", + " return circuit,label\n", + " \n", + " return circuit,label\n", + "\n", + "\n", + "#score" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.0\n" + ] + } + ], + "source": [ + "#how we grade your submission\n", + "\n", + "score=0\n", + "gatecount=0\n", + "n=len(dataset)\n", + "\n", + "for data in dataset:\n", + " #run part 2\n", + " circuit,label=run_part2(data['image'])\n", + " \n", + " #count the gate used in the circuit for score calculation\n", + " gatecount+=count_gates(circuit)[2]\n", + " \n", + " #check label\n", + " if label==data['category']:\n", + " score+=1\n", + "#score\n", + "score=score/n\n", + "gatecount=gatecount/n\n", + "\n", + "print(score*(0.999**gatecount))" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(2000, 764)\n", + "(2000, 764)\n" + ] + } + ], + "source": [ + "images_v2 = np.zeros((2000, 764))\n", + "print(images_v2.shape)\n", + "\n", + "img_counter = 0\n", + "for image in images:\n", + " for pixel in image:\n", + " np.append(images_v2[img_counter], pixel)\n", + " img_counter += 1\n", + "\n", + "print(images_v2.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "# training quantum classifier\n", + "train_images, test_images, train_labels, test_labels = train_test_split(\n", + " images_v2, labels, test_size=0.1, random_state=420)" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "cannot reshape array of size 764 into shape (28,28)", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[53], line 6\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(num_labels):\n\u001b[1;32m 5\u001b[0m ax \u001b[38;5;241m=\u001b[39m fig\u001b[38;5;241m.\u001b[39madd_subplot(\u001b[38;5;241m1\u001b[39m, num_labels, i\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m1\u001b[39m)\n\u001b[0;32m----> 6\u001b[0m img \u001b[38;5;241m=\u001b[39m \u001b[43mtrain_images\u001b[49m\u001b[43m[\u001b[49m\u001b[43mtrain_labels\u001b[49m\u001b[38;5;241;43m==\u001b[39;49m\u001b[43mLABELS\u001b[49m\u001b[43m[\u001b[49m\u001b[43mi\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mreshape\u001b[49m\u001b[43m(\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m28\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m28\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 7\u001b[0m ax\u001b[38;5;241m.\u001b[39mimshow(img, cmap\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mGreys\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "\u001b[0;31mValueError\u001b[0m: cannot reshape array of size 764 into shape (28,28)" + ] + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMUAAAD8CAYAAADHTWCVAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAAsTAAALEwEAmpwYAAALt0lEQVR4nO3df6jd9X3H8edLM1fmrI56CyVJq2VxNnMD3cU5CqujbkQHyR8dJQHZHGJoV8ugZeBwuJL+1ZV1UMjWZUxsC9Wm/WNcaERYpwjSWK9orVEst6lbkpaZWuc/Un+w9/44x/X4NvF+m3zvuaY+H3DhfL/n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ZBJq+/jGHIcwb4NJP3iP10jvPeBOytqucAquqZOc5dwNunt88Hfni6k1bV/Uz+2nkyO4Av1cRB4IIk71rtcdc6ihO9RWTjycZU1SvAq28RWet5Z93I5DfKGFade3oY31xV3xhpzkHzApcAlyR5IMnBJNvmOPengOuTHAUOAB8fae7TXdfrzPVtHm9GSa4HFoEPzGm+s4DPATfMY75mA5NTqKuZHBnvT/JbVfU/c5h7F3BHVf19kt9j8rrWZVX1v3OY++ey1keK9XqLyJB5SXINcCuwvapePM05h859HnAZcF+Sp5mc6y6NcLE95DkfBZaq6uWq+gHwPSaRnK4hc98I7Aeoqm8Bb2PyZsG1NOj/weuMcaH1BhdCG4DDwMX87ALsN9uYj/HaC+39c5r3ciYXh1vm/Zzb+PsY50J7yHPeBnxxevtCJqcW75jT3HcDN0xvv4/JNUVGmPsiTn6h/ce89kL724Mec8z/ECdZ2HVMfiN9H7h1um8Pk9/OMPmN8TVgBfg28N45zfvvwH8Dj06/lub1nNvYUaIY+JzD5NTtCeC7wM45/jtvBR6YBvMo8EcjzHkn8CPgZSZHwRuBjwAfmXm+e6dr+u7Qn7Nv85AaX9GWGqOQGqOQGqOQGqOQGqOQGqOQmv8DGGoLAGAHCycAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "fig = plt.figure()\n", + "LABELS = [0, 1]\n", + "num_labels = len(LABELS)\n", + "for i in range(num_labels):\n", + " ax = fig.add_subplot(1, num_labels, i+1)\n", + " img = train_images[train_labels==LABELS[i]][0].reshape((28, 28))\n", + " ax.imshow(img, cmap=\"Greys\")" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "print(type(train_images))" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "# sample_train = train_images\n", + "# sample_val = test_images\n", + "# labels_train = train_labels\n", + "# labels_val = test_labels\n", + "\n", + "# Standardize\n", + "standard_scaler = StandardScaler()\n", + "for image in train_images:\n", + " image = standard_scaler.fit_transform(image)\n", + "\n", + "for image in test_images:\n", + " image = standard_scaler.transform(image)\n", + " \n", + "# train_images = standard_scaler.fit_transform(train_images)\n", + "# test_images = standard_scaler.transform(test_images)\n", + "\n", + "# # Reduce dimensions\n", + "N_DIM = 5\n", + "pca = PCA(n_components=N_DIM)\n", + "for image in train_images:\n", + " image = pca.fit_transform(image)\n", + "\n", + "for image in test_images:\n", + " image = pca.transform(image)\n", + "# train_images = pca.fit_transform(train_images)\n", + "# test_images = pca.transform(test_images)\n", + "\n", + "# # Normalize\n", + "min_max_scaler = MinMaxScaler((-1, 1))\n", + "for image in train_images:\n", + " image = min_max_scaler.fit_transform(image)\n", + "\n", + "for image in test_images:\n", + " image = min_max_scaler.transform(image)\n", + "# train_images = min_max_scaler.fit_transform(train_images)\n", + "# test_images = min_max_scaler.transform(test_images)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1800, 28, 28)\n" + ] + } + ], + "source": [ + "print(train_images.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], + "source": [ + "print(train_labels[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 [Default]", + "language": "python", + "name": "python3" + }, + "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.9.10" + }, + "vscode": { + "interpreter": { + "hash": "397704579725e15f5c7cb49fe5f0341eb7531c82d19f2c29d197e8b64ab5776b" + } + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/quantum_classifier_2.pickle b/quantum_classifier_2.pickle new file mode 100644 index 0000000000000000000000000000000000000000..59690ea047e24788e903bedf853a678047346ede GIT binary patch literal 47381 zcmeHQ36vbgdEQgn)vi_tmjEM#?U)rvt6fPX3XX$d0SOkZ1qKJ~r`PV8>D`*r?96WW zw20wi6N?=dhn|-nNRp?Tk3XW@-r!HB4L54kJf?Cx>7)@VXc! z)Vd3khBr3XIin2PxL!0|r(+X+1cU0)GR9aopA~SN3(6juJ^`azPC8@HDbzyMP!_(<@A)1b4Q)-bRnPdaKjfZWBarr*fx-MowiKTwNuVK zAF{K&Y`{JROk+H26%7;PyphHbBKbTmo6i_K-H{dmWxB=O16@D)&YS-D)6d;-9{LQP zWS2RMeDd8Sp$RthJFQa?!UJ6oemr&gvv+>u-<)&G+Vx+yYQ@D<7q0|z{cHpKElJU<{B?jPoKf&i)ukt5yuHbnUy`R2Wzr0lV-A>%aCu z=fi^pj9pU^%-We?+6m0g*X-N$_=CUPk`Ts*+r@S9q!fQp#4cOW37g#Hx`N zwtAb(){L^jQ8qNn*0ObWimhkE`&@SGN_JaKKsMI{$PM)Xvb7#SHpBo)sxY9WySHMp z8RbfYt#n!^-7rI(mzGUwp(qSYW@9IGxn+?CbVrzJDV2)pDfH@6PrXpRX6>3t z6>=7qk{Q|}0KLOV7Ymq$X9r+kD@v}(852gH)Cc<`2TO(Dr&n20r$Az-OVZTO4zfeg zEFHF;%|LnIa?5pB%Vth{7LX1s{=;WS-7TNxA1aKz^Rb6-d%Vj^z10;99b4#h?0o$o zWbz&C-OfCJOze=;DK!@4li;_qcL{lB_a0bWc=+pUw=R3%p|@?$te<-A4_{FRZAd_S zFMAI=#QtKW)d$d401E@Gf4%(vH(Ytx-T1yc-_=qEVXc7hejh@c523vTVewlx z{P4TaA3XQimTQmx>e1y7EGq-BP5^ko2hi>V=qLeLa`a2*Y<<<5AHDOb>%YJX&+k53 z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Z5sPF=P!+UCDWbl3au5c($AuW3 zC)YWwnnlAL(-9s;>L|#_Lf~dukm0;Ojwws=W4uTwWyL+3Y3KdXxX$^$K;ltj0&-*y zgloHRvh&_DwNTz8?p&r|YWl>7t<+sA)O`TwSbR2lyn<$g}dFDUsXB`;9&Ka~70CBLHN z*Oat?0KAowHcHwl>7b;Ol6jQOr=$xBJIuQ&zkre_>FJMC@(D^lNy*<+@(+|eMae%> z@=ug}ijq%L@-!u%L1OST0A|z%<*|@YW^;z*BCYs+GImc8@eXSsrWJzYoX!O?O%RWd6|f2}%mF?Yb(kN}T990dl1cJT)&q3) z80j*N)DK#ZEO%ZK15c`1yLKzKQJi-vp2+xv!qPC`iabnyfYcZ7(N(^1tw76tw?MVwG R!s#uHjUiN#zx=~s`#-g4_1FLa literal 0 HcmV?d00001 From 22fb120784302b3def889649c1e0277053a4cbe9 Mon Sep 17 00:00:00 2001 From: Shraddha Aangiras <63237790+shraddha-aangiras@users.noreply.github.com> Date: Sun, 29 Jan 2023 20:36:54 +0530 Subject: [PATCH 07/10] Final doc --- part2_example_qiskit_1 (1).ipynb | 666 +++++++++++++++++++++++++++++++ 1 file changed, 666 insertions(+) create mode 100644 part2_example_qiskit_1 (1).ipynb diff --git a/part2_example_qiskit_1 (1).ipynb b/part2_example_qiskit_1 (1).ipynb new file mode 100644 index 0000000..b3845ed --- /dev/null +++ b/part2_example_qiskit_1 (1).ipynb @@ -0,0 +1,666 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import gzip\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from pylab import cm\n", + "import warnings\n", + "\n", + "from sklearn import datasets\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.preprocessing import StandardScaler, MinMaxScaler\n", + "from sklearn.decomposition import PCA\n", + "from sklearn.svm import SVC\n", + "from sklearn.metrics import accuracy_score\n", + "\n", + "import qiskit\n", + "from qiskit import *\n", + "from qiskit import quantum_info\n", + "from qiskit.execute_function import execute\n", + "from qiskit import BasicAer\n", + "\n", + "from qiskit import Aer, execute\n", + "from qiskit.circuit import QuantumCircuit, Parameter, ParameterVector\n", + "from qiskit.circuit.library import PauliFeatureMap, ZFeatureMap, ZZFeatureMap\n", + "from qiskit.circuit.library import TwoLocal, NLocal, RealAmplitudes, EfficientSU2\n", + "from qiskit.circuit.library import HGate, RXGate, RYGate, RZGate, CXGate, CRXGate, CRZGate\n", + "from qiskit_machine_learning.kernels import QuantumKernel\n", + "\n", + "import numpy as np\n", + "import pickle\n", + "import json\n", + "import os\n", + "from collections import Counter\n", + "from sklearn.metrics import mean_squared_error\n", + "from typing import Dict, List\n", + "\n", + "#define utility functions\n", + "\n", + "def simulate(circuit: qiskit.QuantumCircuit) -> dict:\n", + " \"\"\"Simulate the circuit, give the state vector as the result.\"\"\"\n", + " backend = BasicAer.get_backend('statevector_simulator')\n", + " job = execute(circuit, backend)\n", + " result = job.result()\n", + " state_vector = result.get_statevector()\n", + " \n", + " histogram = dict()\n", + " for i in range(len(state_vector)):\n", + " population = abs(state_vector[i]) ** 2\n", + " if population > 1e-9:\n", + " histogram[i] = population\n", + " \n", + " return histogram\n", + "\n", + "\n", + "def histogram_to_category(histogram):\n", + " \"\"\"This function take a histogram representations of circuit execution results, and process into labels as described in \n", + " the problem description.\"\"\"\n", + " assert abs(sum(histogram.values())-1)<1e-8\n", + " positive=0\n", + " for key in histogram.keys():\n", + " digits = bin(int(key))[2:].zfill(20)\n", + " if digits[-1]=='0':\n", + " positive+=histogram[key]\n", + " \n", + " return positive\n", + "\n", + "\n", + "def count_gates(circuit: qiskit.QuantumCircuit) -> Dict[int, int]:\n", + " \"\"\"Returns the number of gate operations with each number of qubits.\"\"\"\n", + " counter = Counter([len(gate[1]) for gate in circuit.data])\n", + " #feel free to comment out the following two lines. But make sure you don't have k-qubit gates in your circuit\n", + " #for k>2\n", + " for i in range(2,20):\n", + " assert counter[i]==0\n", + " \n", + " return counter" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# #load the mock data (for testing only)\n", + "# files=os.listdir(\"mock_data\")\n", + "# dataset=list()\n", + "# for file in files:\n", + "# with open('mock_data/'+file, \"r\") as infile:\n", + "# loaded = json.load(infile)\n", + "# dataset.append(loaded)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAAsTAAALEwEAmpwYAAAQiElEQVR4nO3dXYyc9XXH8d/Z2Rd712vjxcY2xuUtkBZFwjRb2iqkJUJBhBuDFNFQKSIq7eYiSEHKRRGVGm4qoaokygWK5AQUp6KkqRKE06AG6iZCpK1jg1wwuAXXsbFdv2Js/MLuzu6eXuw4Wpt9zrOel52xz/cjrWb2OfPMHI/98zMz//k/f3N3Abj0dbW7AQDzg7ADSRB2IAnCDiRB2IEkuufzwXqtzxdoYD4f8qJgvb1hfWx5T1jv7q8W1qpj8b42EZZlU3F9qi8ezVk6cKaw9sH4gnDf7gMWP/jpD+N6QqM6rXEfm/WJayjsZnaXpG9Jqkj6rrs/Ht1+gQb0+3ZHIw95Sepe/Vth/Z2R1WF95ScPFtb27bwi3LfvSCWsd42HZZ25tvg/Gkm6b3hLYe3Fd3873PeKv4n/o9Kv3ojrCW32TYW1ul/Gm1lF0pOSPifpJkn3m9lN9d4fgNZq5D37rZJ2uvsudx+X9ANJ65rTFoBmayTsqyXtnfH7vtq2c5jZiJltNbOtVY018HAAGtHyT+Pdfb27D7v7cI/6Wv1wAAo0Evb9ktbM+P2q2jYAHaiRsG+RdI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/5jZTjN7pB09FDGz3Wb2hpltM7Otbe7laTM7bGbbZ2wbMrOXzOyd2uWsa+y1qbfHzGx/7bnbZmZ3t6m3NWb2czN7y8zeNLOv1ra39bkL+pqX523e37ObWUXS25I+K2mfpC2S7nf3t+a1kQJmtlvSsLu3/QsYZvZHkk5J+r67f6K27W8lHXP3x2v/US5197/skN4ek3Sq3ct411YrWjVzmXFJ90j6ktr43AV93ad5eN7acWS/VdJOd9/l7uOSfiBpXRv66Hju/rKkY+dtXidpQ+36Bk3/Y5l3Bb11BHc/4O6v1a6flHR2mfG2PndBX/OiHWFfLWnvjN/3qbPWe3dJL5rZq2Y20u5mZrHC3c+uqXRQ0op2NjOL0mW859N5y4x3zHNXz/LnjeIDuo+6zd1/V9LnJH2l9nK1I/n0e7BOGjud0zLe82WWZcZ/o53PXb3LnzeqHWHfL2nmGRSvqm3rCO6+v3Z5WNJz6rylqA+dXUG3dnm4zf38Rict4z3bMuPqgOeuncuftyPsWyTdYGbXmlmvpC9I2tiGPj7CzAZqH5zIzAYk3anOW4p6o6QHatcfkPR8G3s5R6cs4120zLja/Ny1fflzd5/3H0l3a/oT+f+V9Fft6KGgr+sk/Vft58129ybpWU2/rKtq+rONByVdLmmTpHck/aukoQ7q7e8lvSHpdU0Ha1WbertN0y/RX5e0rfZzd7ufu6CveXne+LoskAQf0AFJEHYgCcIOJEHYgSQIO5AEYQeSIOxAEv8PE4DsMh8Hn6sAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "#load the actual hackthon data (fashion-mnist)\n", + "images=np.load('data/images.npy')\n", + "labels=np.load('data/labels.npy')\n", + "#you can visualize it\n", + "import matplotlib.pyplot as plt\n", + "plt.imshow(images[1100])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "#your submission\n", + "\n", + "# Functions 'encode' and 'decode' are dummy.\n", + "def encode(image):\n", + " print(\"Encoding...\")\n", + " number_of_qubits = math.ceil(math.log(28*28, 2))\n", + " amplitude_vector = [0] * (2**number_of_qubits)\n", + " sum_squares = 0\n", + " amplitude_counter = 0\n", + " for i in image:\n", + " for j in i:\n", + " sum_squares+=j**2\n", + " amplitude_vector[amplitude_counter] = j\n", + " amplitude_counter+=1\n", + " global norm\n", + " norm = 1/np.sqrt(sum_squares)\n", + " amplitude_vector_new = [i*norm for i in amplitude_vector]\n", + " \n", + " # Some previous tests we were running -- ignore\n", + " \n", + " # global imtest\n", + " # imtest=[[0]*28 for z in range(28)]\n", + " # a_counter=0\n", + " # for i in range(28):\n", + " # for j in range(28):\n", + " # imtest[i][j]=amplitude_vector[a_counter]#/norm\n", + " # a_counter+=1\n", + " \n", + " \n", + " # print(amplitude_vector)\n", + " qr = qiskit.QuantumRegister(number_of_qubits)\n", + " qc = qiskit.QuantumCircuit(qr)\n", + " qc.initialize(amplitude_vector_new, qr)\n", + "\n", + " print(\"Encoded!\")\n", + " return qc\n", + "\n", + "def decode(histogram):\n", + " print(\"Decoding...\") \n", + " image = [[0] * 28 for z in range(28)]\n", + " amplitude_counter=1\n", + " for i in range(28):\n", + " for j in range(28):\n", + " image[i][j] = histogram.get(amplitude_counter, 0)#/norm\n", + " amplitude_counter+=1\n", + " print(\"Decoded!\")\n", + " return image\n", + "\n", + "def run_part1(image):\n", + " #encode image into a circuit\n", + " circuit=encode(image)\n", + "\n", + " #simulate circuit\n", + " histogram=simulate(circuit)\n", + "\n", + " #reconstruct the image\n", + " image_re=decode(histogram)\n", + "\n", + " return circuit,image_re\n", + "\n", + "\n", + "def run_part2(image):\n", + " # load the quantum classifier circuit\n", + " # classifier=qiskit.QuantumCircuit.from_qasm_file('quantum_classifier.qasm')\n", + " \n", + " #encode image into circuit\n", + " circuit = encode(image)\n", + " image = decode(simulate(circuit))\n", + " \n", + " nsamples, nx, ny = image.shape\n", + " images_reshaped = image.reshape((nsamples,nx*ny))\n", + " \n", + " \n", + " \n", + " \n", + " #append with classifier circuit\n", + " # nq1 = circuit.width()\n", + " # nq2 = classifier.width()\n", + " # nq = max(nq1, nq2)\n", + " # qc = qiskit.QuantumCircuit(nq)\n", + " # qc.append(circuit.to_instruction(), list(range(nq1)))\n", + " # qc.append(classifier.to_instruction(), list(range(nq2)))\n", + " \n", + " \n", + " \n", + " #simulate circuit\n", + " histogram=simulate(qc)\n", + " \n", + " #convert histogram to category\n", + " label=histogram_to_category(histogram)\n", + " \n", + " #thresholding the label, any way you want\n", + " if label>0.5:\n", + " label=1\n", + " else:\n", + " label=0\n", + " \n", + " return circuit,label\n", + " \n", + " return circuit,label\n", + "\n", + "\n", + "#score" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.0\n" + ] + } + ], + "source": [ + "#how we grade your submission\n", + "\n", + "score=0\n", + "gatecount=0\n", + "n=len(dataset)\n", + "\n", + "for data in dataset:\n", + " #run part 2\n", + " circuit,label=run_part2(data['image'])\n", + " \n", + " #count the gate used in the circuit for score calculation\n", + " gatecount+=count_gates(circuit)[2]\n", + " \n", + " #check label\n", + " if label==data['category']:\n", + " score+=1\n", + "#score\n", + "score=score/n\n", + "gatecount=gatecount/n\n", + "\n", + "print(score*(0.999**gatecount))" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "not enough values to unpack (expected 3, got 2)", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[106], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m plt\u001b[38;5;241m.\u001b[39mimshow(images[\u001b[38;5;241m1100\u001b[39m])\n\u001b[0;32m----> 3\u001b[0m nsamples, nx, ny \u001b[38;5;241m=\u001b[39m image\u001b[38;5;241m.\u001b[39mshape\n\u001b[1;32m 4\u001b[0m images_reshaped \u001b[38;5;241m=\u001b[39m image\u001b[38;5;241m.\u001b[39mreshape((nsamples,nx\u001b[38;5;241m*\u001b[39mny))\n", + "\u001b[0;31mValueError\u001b[0m: not enough values to unpack (expected 3, got 2)" + ] + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAAsTAAALEwEAmpwYAAAQiElEQVR4nO3dXYyc9XXH8d/Z2Rd712vjxcY2xuUtkBZFwjRb2iqkJUJBhBuDFNFQKSIq7eYiSEHKRRGVGm4qoaokygWK5AQUp6KkqRKE06AG6iZCpK1jg1wwuAXXsbFdv2Js/MLuzu6eXuw4Wpt9zrOel52xz/cjrWb2OfPMHI/98zMz//k/f3N3Abj0dbW7AQDzg7ADSRB2IAnCDiRB2IEkuufzwXqtzxdoYD4f8qJgvb1hfWx5T1jv7q8W1qpj8b42EZZlU3F9qi8ezVk6cKaw9sH4gnDf7gMWP/jpD+N6QqM6rXEfm/WJayjsZnaXpG9Jqkj6rrs/Ht1+gQb0+3ZHIw95Sepe/Vth/Z2R1WF95ScPFtb27bwi3LfvSCWsd42HZZ25tvg/Gkm6b3hLYe3Fd3873PeKv4n/o9Kv3ojrCW32TYW1ul/Gm1lF0pOSPifpJkn3m9lN9d4fgNZq5D37rZJ2uvsudx+X9ANJ65rTFoBmayTsqyXtnfH7vtq2c5jZiJltNbOtVY018HAAGtHyT+Pdfb27D7v7cI/6Wv1wAAo0Evb9ktbM+P2q2jYAHaiRsG+RdIOZXWtmvZK+IGljc9oC0Gx1D725+4SZPSTpZ5oeenva3d9sWmeJ7PzzeGjt+T99Iqz/+4fXFdbWXP9euO+dwRj9XGw83R/Wd46tLKz95Jbvhvt+euThsH7jr8IyztPQOLu7vyDphSb1AqCF+LoskARhB5Ig7EAShB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ZvZHkk5J+r67f6K27W8lHXP3x2v/US5197/skN4ek3Sq3ct411YrWjVzmXFJ90j6ktr43AV93ad5eN7acWS/VdJOd9/l7uOSfiBpXRv66Hju/rKkY+dtXidpQ+36Bk3/Y5l3Bb11BHc/4O6v1a6flHR2mfG2PndBX/OiHWFfLWnvjN/3qbPWe3dJL5rZq2Y20u5mZrHC3c+uqXRQ0op2NjOL0mW859N5y4x3zHNXz/LnjeIDuo+6zd1/V9LnJH2l9nK1I/n0e7BOGjud0zLe82WWZcZ/o53PXb3LnzeqHWHfL2nmGRSvqm3rCO6+v3Z5WNJz6rylqA+dXUG3dnm4zf38Rict4z3bMuPqgOeuncuftyPsWyTdYGbXmlmvpC9I2tiGPj7CzAZqH5zIzAYk3anOW4p6o6QHatcfkPR8G3s5R6cs4120zLja/Ny1fflzd5/3H0l3a/oT+f+V9Fft6KGgr+sk/Vft58129ybpWU2/rKtq+rONByVdLmmTpHck/aukoQ7q7e8lvSHpdU0Ha1WbertN0y/RX5e0rfZzd7ufu6CveXne+LoskAQf0AFJEHYgCcIOJEHYgSQIO5AEYQeSIOxAEv8PE4DsMh8Hn6sAAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": {}, + "outputs": [], + "source": [ + "new_array=np.zeros((2000, 764))\n", + "img_counter = 0\n", + "pxl_counter = 0\n", + "for image in images:\n", + " image_array = np.zeros((764))\n", + " for i in image:\n", + " for j in i:\n", + " image_array[pxl_counter] = j\n", + " pxl_counter += 1\n", + " pxl_counter = 0\n", + " new_array[img_counter] = image_array\n", + " img_counter += 1" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "metadata": {}, + "outputs": [], + "source": [ + "nsamples, nx, ny = images.shape\n", + "images_reshaped = images.reshape((nsamples,nx*ny))" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "metadata": {}, + "outputs": [], + "source": [ + "# training quantum classifier\n", + "train_images, test_images, train_labels, test_labels = train_test_split(\n", + " images_reshaped, labels, test_size=0.2, random_state=420)\n", + "\n", + "sample_train, sample_val, labels_train, labels_val = train_test_split(\n", + " train_images, train_labels, test_size=0.2, random_state=42)" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAC4CAYAAAD61bdSAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAAsTAAALEwEAmpwYAAAWK0lEQVR4nO3de2zVZZoH8O9D5SqXUinQVrBQQGMARasxOAobdzZoTMA/IGPiBM24jGaUIRqN8Z8ZNprMHzvMbowYmUhgE4eZiTiL2RAVUWQ1K9ohSBWQSymX0pZWuVSuVp79o4ek+j7v9Jye6/Pj+0kM7cN7znl/7Xsef5znvYiqgoiI/BlQ7A4QEVH/MIETETnFBE5E5BQTOBGRU0zgREROMYETETmVVQIXkXki8pWI7BeR53LVKaJi49gmD6S/88BFpAzAXgA/BXAUwGcAHlTVXbHHjBkzRmtra/v1ekR9aW5uRmdnp2T7PFfC2P7mm2+CWEVFRRF6kltff/21GS8vLw9iZWVlee5N7sTG9lVZPOftAParahMAiMifAcwHEB3ktbW1aGhoyOIlieLq6+tz9VSJH9vr1q0LYosWLTLbWokuduMnkvX/PwOXLl0y4wMGhB8grF271mz7wAMPBLGRI0dm17ECio3tbD5CqQFwpNf3R1OxHxCRJSLSICINHR0dWbwcUcFwbJMLeS9iquoqVa1X1frKysp8vxxRwXBsU7Fl8xFKC4AJvb6/NhVzJ5M6QCb/RHzjjTfM+AsvvBDEhg4dGsTOnTtnPr61tTWItbW1mW2t/mbyT9IrVGLGdkxXV1cQO3jwoNl2ypQpQSyTj1Cstpm8jzIZl3v27Mn6OTzJ5qo+AzBVRCaJyCAAPwPwVm66RVRUHNvkQr/vwFW1W0SeAPAOgDIAq1X1y5z1jKhIOLbJi2w+QoGqbgSwMUd9ISoZHNvkQTI/GCIiugIwgRMROZXVRyhJkYvFB1b1+/HHHzfbWrNLBg8enHa/rNVmd9xxh9l227ZtQSyTiny+ZuhQcd17771B7NixY2ZbaxZKvmZ1ZDJjxZpNZV1X7HmTgHfgREROMYETETnFBE5E5BQTOBGRUyxi/gNNTU1B7KmnnjLbfv7550Fs7NixZltrK8/u7u4gFiu8WM9rLa8H7F3MVqxYYba9++67gxgLk8k0fPjwIPbKK6+Yba1tHmbOnJn2a2UyhjJp+9BDDwWx+fPnm22tsZ0EvAMnInKKCZyIyCkmcCIip5jAiYicYgInInIqEbNQMll+e+HChSC2ePFis+27774bxGJLiK2ZIbEz906cOBHErEr/oEGDzMd3dnYGserq6rRf67777jPb3nTTTUFswYIFZttnnnnGjJMPb7/9dloxAPj000+D2PLly822CxcuzK5jhkceecSMb968OYjFZmNZZ2LG3l+e8A6ciMgpJnAiIqeYwImInGICJyJyKqsipog0A+gC8D2AblUN120XQCbLb5999tkg9t5775ltx48fH8SsfbsBoLKyMohZxUYA+P7774OYtbR5yJAh5uOt6y0rKzPbWtcQW+JvFYBefPFFs621//hdd91lts32VPJiKJWxnS/r169Pu+1VV4VpYunSpWZba3m7VUC0JhMAwIYNG4JYrEBfW1sbxBobG8221l7n1uO9ycUslH9SVTtTEfnGsU0ljR+hEBE5lW0CVwDvisjfRWRJLjpEVCI4tqnkZfsRyk9UtUVExgLYJCJ7VHVr7wapwb8EACZOnJjlyxEVDMc2lbys7sBVtSX153EAfwNwu9FmlarWq2q9VegjKkUc2+RBv+/AReRqAANUtSv19b8A+Lec9SxPOjo6gticOXPMtnv37g1iVkUeAA4cOBDErNPjAaCmpiaInTp1KohZBz8AwHXXXRfErJktgH291owXAKioqAhiscS0cuXKIBabhVLqM05+zOvYzsRXX30VxGJLy61ZRLFxMWLEiCD20Ucfpd2v66+/PojF3nPnzp0LYgMHDjTbHj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YLeqruj1V+6vLY+SPrbd/+6TOK4LvhJTRO4D8B8AygCsVtUXC9qBHBKRdQDmomc7ynYAvwHw3wD+CmAierYXXaSq9gGdJUpEfgLgfwE0Arh8COjz6Pm80PW15VNSxjbHtZ9r41J6IiKnWMQkInKKCZyIyCkmcCIip5jAiYicYgInInKKCZyIyCkmcCIip/4ff7kwClYau78AAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "fig = plt.figure()\n", + "LABELS = [0, 1]\n", + "num_labels = len(LABELS)\n", + "for i in range(num_labels):\n", + " ax = fig.add_subplot(1, num_labels, i+1)\n", + " img = train_images[train_labels==LABELS[i]][0].reshape((28, 28))\n", + " ax.imshow(img, cmap=\"Greys\")" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1600, 784)\n" + ] + } + ], + "source": [ + "print(train_images.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "metadata": {}, + "outputs": [], + "source": [ + "# # sample_train = train_images\n", + "# # sample_val = test_images\n", + "# # labels_train = train_labels\n", + "# # labels_val = test_labels" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [], + "source": [ + "# Standardize\n", + "standard_scaler = StandardScaler()\n", + "sample_train = standard_scaler.fit_transform(sample_train)\n", + "sample_val = standard_scaler.transform(sample_val)\n", + "test_images = standard_scaler.transform(test_images)\n", + "\n", + "# Reduce dimensions\n", + "N_DIM = 5\n", + "pca = PCA(n_components=N_DIM)\n", + "sample_train = pca.fit_transform(sample_train)\n", + "sample_val = pca.transform(sample_val)\n", + "test_images = pca.transform(test_images)\n", + "\n", + "# Normalize\n", + "min_max_scaler = MinMaxScaler((-1, 1))\n", + "sample_train = min_max_scaler.fit_transform(sample_train)\n", + "sample_val = min_max_scaler.transform(sample_val)\n", + "test_images = min_max_scaler.transform(test_images)" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1280, 5)\n" + ] + } + ], + "source": [ + "print(sample_train.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original validation labels: [False False True False False False True False False True False False\n", + " False True False False True False False False False False True False\n", + " False False False False False False False False True False False False\n", + " True True False True False False False False True False False False\n", + " False False False False False True False False False False True True\n", + " False False False False False True False True True False True False\n", + " False False False False False False False True False True False True\n", + " False False False False False False True False False False False True\n", + " False False True False False False False False False False True False\n", + " False False False False False False False False False True False False\n", + " False True False False False False False False False True False False\n", + " False True False False False False False True False False False True\n", + " False True False True False False False False False False False False\n", + " True False False False False False False True False False True False\n", + " False False False False False False False False False False False False\n", + " True False True False False False False True False False False False\n", + " False True True False False True False True False False False False\n", + " False False True False False False False False False True False False\n", + " True False False False False False False False True True False False\n", + " False False False True False True False True True False False False\n", + " False True False False False False False False False False False False\n", + " True False False True False False False True True False True True\n", + " False True False True False False False False False False False False\n", + " False True True False True False False False True True False False\n", + " False True False False False False True True True False True False\n", + " True False False False False False False False False True True False\n", + " False False True False False False False False]\n", + "Validation labels for 0 vs Rest: [1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0\n", + " 0 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 1 1 0 1 0 0 1 0 1 1 1\n", + " 1 1 1 1 1 0 1 0 1 0 1 1 1 1 1 1 0 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1\n", + " 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 1 0 1 0 1 0\n", + " 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1\n", + " 1 1 0 1 1 1 1 1 0 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1\n", + " 1 1 0 0 1 1 1 1 1 0 1 0 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1\n", + " 0 0 1 0 0 1 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 1 1 1 0 1 1 1 1 0 0\n", + " 0 1 0 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1]\n" + ] + } + ], + "source": [ + "labels_train_0 = np.where(labels_train==0, 1, 0)\n", + "labels_val_0 = np.where(labels_val==0, 1, 0)\n", + "\n", + "print(f'Original validation labels: {labels_val}')\n", + "print(f'Validation labels for 0 vs Rest: {labels_val_0}')" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of discriminating between label 0 and others: 88.75%\n" + ] + } + ], + "source": [ + "pauli_map_0 = PauliFeatureMap(feature_dimension=N_DIM, reps=2, paulis = ['X', 'Y', 'ZZ'])\n", + "pauli_kernel_0 = QuantumKernel(feature_map=pauli_map_0, quantum_instance=Aer.get_backend('statevector_simulator'))\n", + "\n", + "pauli_svc_0 = SVC(kernel='precomputed', probability=True)\n", + "\n", + "matrix_train_0 = pauli_kernel_0.evaluate(x_vec=sample_train)\n", + "pauli_svc_0.fit(matrix_train_0, labels_train_0)\n", + "\n", + "matrix_val_0 = pauli_kernel_0.evaluate(x_vec=sample_val, y_vec=sample_train)\n", + "pauli_score_0 = pauli_svc_0.score(matrix_val_0, labels_val_0)\n", + "print(f'Accuracy of discriminating between label 0 and others: {pauli_score_0*100}%')" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Probability of label 0: [0.97 0.99 0.9 0.82 0.11 0.4 0.29 0.89 0.88 0.96 0.01 0.09 0.03 0.96\n", + " 0.92 0.21 0.9 0.98 0.43 0.38 0.9 0.69 0.99 0.07 0.94 0.98 0.03 0.91\n", + " 0.96 0.94 0.64 0.59 0.76 0.83 0.01 0.91 0.06 0.84 0.88 0.14 0.75 0.48\n", + " 0.88 0.96 0.84 0.96 0.97 0.84 0.76 0.39 0.01 0.23 0.87 0.83 0.87 0.9\n", + " 0.62 0.99 0.98 0.24 1. 0.03 0.96 0.69 0.89 0.96 0.83 0.96 0.96 0.91\n", + " 0.97 0.98 0.94 0.11 0.87 0.93 0.86 0.9 0.9 0.72 0.44 0.99 0.49 0.51\n", + " 0.51 0.96 0.04 0.65 0.9 0.76 0.14 0.92 0.86 0.98 0.97 0.99 0.98 0.9\n", + " 0.06 0.12 0.72 0.99 0.99 0.78 0.71 0.99 0.9 0.85 0.71 0.64 0.9 0.99\n", + " 0.98 0.24 0.83 0.97 0.98 0.81 0.78 0.14 0.99 0.39 0.5 0.86 0.92 0.21\n", + " 0.63 0.46 0.98 0.98 0.98 0.85 0.16 0.52 0.95 0.95 0.88 0.02 0.91 0.07\n", + " 0.86 0.96 0.91 0.98 0.99 0.92 0.78 0.85 0.99 0.92 0.85 0.63 0.96 0.92\n", + " 0.95 0.78 0.02 0.98 0.94 0.51 0.12 0.84 0.19 0.98 0.98 0.82 0.12 0.98\n", + " 0.9 0.02 0.98 0.97 0.99 0.97 0.94 0.03 0.97 0.31 0.96 0.62 0.95 0.99\n", + " 0.99 0.02 0.94 0.95 0.91 0.02 0.92 0.91 0.87 0.99 0.96 0.88 0.13 0.39\n", + " 0.05 0.89 0.1 0.99 0.89 0.95 0.96 0.85 0.88 0.99 0.35 0.89 0.58 0.95\n", + " 0.83 0.02 0.06 0.87 0.02 0.86 0.66 0.95 0.65 0.86 0.64 0.97 0.89 0.83\n", + " 0.8 0.04 0.89 0.97 0.96 0.99 0.87 0.04 0.85 0.94 0.95 0.99 0.07 0.9\n", + " 0.94 0.92 0.97 0.85 0.75 0.59 0.96 0.97 0.88 0.88 0.95 0.98 0.91 0.96\n", + " 0.9 0.98 0.91 0.07 0.58 0.93 0.79 0.88 1. 0.89 0.76 0.97 0.87 0.98\n", + " 0.95 0.06 0.96 1. 0.96 0.77 0.91 0.92 0.9 0.84 0.78 0.89 0.92 0.87\n", + " 0.04 0.92 0.96 0.01 0.98 0.96 0.97 0.99 0.91 0.94 0.19 0.84 0.69 0.43\n", + " 0.66 0.89 0.97 0.96 0.66 0.12 0.95 0.92 0.74 0.79 0.97 0.97 0.88 0.89\n", + " 0.12 0.13 0.95 0.6 0.73 0.97 0.9 0.95 0.97 0.97 0.94 0.98 0.63 0.73\n", + " 0.15 0.94 0.92 0.93 0.93 0.68 0.99 0.76 0.8 0.9 0.98 0.57 0.84 0.97\n", + " 0.76 0.88 1. 0.93 0.78 0.72 0.97 0.1 0.18 0.98 0.18 0.96 0.93 0.11\n", + " 0.65 0.86 0.18 0.84 0.87 0.93 0.88 0.9 0.96 0.96 0.38 0.97 0.97 0.98\n", + " 0.2 0.94 0.92 0.83 0.99 0.97 0.98 0.97 0.69 0.96 0.93 0.79 1. 0.77\n", + " 0.99 0.93 0.99 0.06 0.9 0.43 0.91 0.86 0.81 0.9 0.94 0.97 0.98 0.84\n", + " 0.77 1. 0.98 0.99 0.52 0.91 0.96 1. ]\n" + ] + } + ], + "source": [ + "matrix_test_0 = pauli_kernel_0.evaluate(x_vec=test_images, y_vec=sample_train)\n", + "pred_0 = pauli_svc_0.predict_proba(matrix_test_0)[:, 1]\n", + "print(f'Probability of label 0: {np.round(pred_0, 2)}')" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.88862201 0.11137799]\n" + ] + } + ], + "source": [ + "pred = pauli_svc_0.predict_proba(matrix_test_0)[4]" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": {}, + "outputs": [], + "source": [ + "classifier_file = open('quantum_classifier.pickle', 'wb')\n", + "pickle.dump(pauli_kernel_0, classifier_file)\n", + "classifier_file.close()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "matrix_test_0 = pauli_kernel_0.evaluate(x_vec=images_reshaped)\n", + "pred = pauli_svc_0.predict_proba(images)[0]\n", + "print(pred)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 [Default]", + "language": "python", + "name": "python3" + }, + "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.9.10" + }, + "vscode": { + "interpreter": { + "hash": "397704579725e15f5c7cb49fe5f0341eb7531c82d19f2c29d197e8b64ab5776b" + } + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From f1ca3d770c1554c3321953129a460e26ffffce54 Mon Sep 17 00:00:00 2001 From: Shraddha Aangiras <63237790+shraddha-aangiras@users.noreply.github.com> Date: Sun, 29 Jan 2023 20:39:41 +0530 Subject: [PATCH 08/10] Update part1.py --- part1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/part1.py b/part1.py index ab49778..8a56a8c 100644 --- a/part1.py +++ b/part1.py @@ -3,7 +3,7 @@ teamname="Feynman's Fashion Rescue" -task="part 2" +task="part 1" import qiskit from qiskit import quantum_info From f7fb984525fcbab5cb1ffacfa03b8814f28857ff Mon Sep 17 00:00:00 2001 From: Shraddha Aangiras <63237790+shraddha-aangiras@users.noreply.github.com> Date: Sun, 29 Jan 2023 20:40:20 +0530 Subject: [PATCH 09/10] Add files via upload --- part2.py | 293 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 part2.py diff --git a/part2.py b/part2.py new file mode 100644 index 0000000..03ffe05 --- /dev/null +++ b/part2.py @@ -0,0 +1,293 @@ +teamname="Feynman's Fashion Rescue" +task="part 2" + +import os +import gzip +import numpy as np +import matplotlib.pyplot as plt +from pylab import cm +import warnings + +from sklearn import datasets +from sklearn.model_selection import train_test_split +from sklearn.preprocessing import StandardScaler, MinMaxScaler +from sklearn.decomposition import PCA +from sklearn.svm import SVC +from sklearn.metrics import accuracy_score + +import qiskit +from qiskit import * +from qiskit import quantum_info +from qiskit.execute_function import execute +from qiskit import BasicAer + +from qiskit import Aer, execute +from qiskit.circuit import QuantumCircuit, Parameter, ParameterVector +from qiskit.circuit.library import PauliFeatureMap, ZFeatureMap, ZZFeatureMap +from qiskit.circuit.library import TwoLocal, NLocal, RealAmplitudes, EfficientSU2 +from qiskit.circuit.library import HGate, RXGate, RYGate, RZGate, CXGate, CRXGate, CRZGate +from qiskit_machine_learning.kernels import QuantumKernel + +import numpy as np +import pickle +import json +import os +from collections import Counter +from sklearn.metrics import mean_squared_error +from typing import Dict, List + +#define utility functions + +def simulate(circuit: qiskit.QuantumCircuit) -> dict: + """Simulate the circuit, give the state vector as the result.""" + backend = BasicAer.get_backend('statevector_simulator') + job = execute(circuit, backend) + result = job.result() + state_vector = result.get_statevector() + + histogram = dict() + for i in range(len(state_vector)): + population = abs(state_vector[i]) ** 2 + if population > 1e-9: + histogram[i] = population + + return histogram + + +def histogram_to_category(histogram): + """This function take a histogram representations of circuit execution results, and process into labels as described in + the problem description.""" + assert abs(sum(histogram.values())-1)<1e-8 + positive=0 + for key in histogram.keys(): + digits = bin(int(key))[2:].zfill(20) + if digits[-1]=='0': + positive+=histogram[key] + + return positive + + +def count_gates(circuit: qiskit.QuantumCircuit) -> Dict[int, int]: + """Returns the number of gate operations with each number of qubits.""" + counter = Counter([len(gate[1]) for gate in circuit.data]) + #feel free to comment out the following two lines. But make sure you don't have k-qubit gates in your circuit + #for k>2 + for i in range(2,20): + assert counter[i]==0 + + return counter + +#load the actual hackthon data (fashion-mnist) +images=np.load('data/images.npy') +labels=np.load('data/labels.npy') +#you can visualize it +import matplotlib.pyplot as plt +plt.imshow(images[1100]) + +#your submission + +# Functions 'encode' and 'decode' are dummy. +def encode(image): + print("Encoding...") + number_of_qubits = math.ceil(math.log(28*28, 2)) + amplitude_vector = [0] * (2**number_of_qubits) + sum_squares = 0 + amplitude_counter = 0 + for i in image: + for j in i: + sum_squares+=j**2 + amplitude_vector[amplitude_counter] = j + amplitude_counter+=1 + global norm + norm = 1/np.sqrt(sum_squares) + amplitude_vector_new = [i*norm for i in amplitude_vector] + + # Some previous tests we were running -- ignore + + # global imtest + # imtest=[[0]*28 for z in range(28)] + # a_counter=0 + # for i in range(28): + # for j in range(28): + # imtest[i][j]=amplitude_vector[a_counter]#/norm + # a_counter+=1 + + + # print(amplitude_vector) + qr = qiskit.QuantumRegister(number_of_qubits) + qc = qiskit.QuantumCircuit(qr) + qc.initialize(amplitude_vector_new, qr) + + print("Encoded!") + return qc + +def decode(histogram): + print("Decoding...") + image = [[0] * 28 for z in range(28)] + amplitude_counter=1 + for i in range(28): + for j in range(28): + image[i][j] = histogram.get(amplitude_counter, 0)#/norm + amplitude_counter+=1 + print("Decoded!") + return image + +def run_part1(image): + #encode image into a circuit + circuit=encode(image) + + #simulate circuit + histogram=simulate(circuit) + + #reconstruct the image + image_re=decode(histogram) + + return circuit,image_re + + +def run_part2(image): + # load the quantum classifier circuit + # classifier=qiskit.QuantumCircuit.from_qasm_file('quantum_classifier.qasm') + + #encode image into circuit + circuit = encode(image) + image = decode(simulate(circuit)) + + nsamples, nx, ny = image.shape + images_reshaped = image.reshape((nsamples,nx*ny)) + + + + + #append with classifier circuit + # nq1 = circuit.width() + # nq2 = classifier.width() + # nq = max(nq1, nq2) + # qc = qiskit.QuantumCircuit(nq) + # qc.append(circuit.to_instruction(), list(range(nq1))) + # qc.append(classifier.to_instruction(), list(range(nq2))) + + + + #simulate circuit + histogram=simulate(qc) + + #convert histogram to category + label=histogram_to_category(histogram) + + #thresholding the label, any way you want + if label>0.5: + label=1 + else: + label=0 + + return circuit,label + + return circuit,label + + +#score + +#how we grade your submission + +score=0 +gatecount=0 +n=len(dataset) + +for data in dataset: + #run part 2 + circuit,label=run_part2(data['image']) + + #count the gate used in the circuit for score calculation + gatecount+=count_gates(circuit)[2] + + #check label + if label==data['category']: + score+=1 +#score +score=score/n +gatecount=gatecount/n + +print(score*(0.999**gatecount)) + +new_array=np.zeros((2000, 764)) +img_counter = 0 +pxl_counter = 0 +for image in images: + image_array = np.zeros((764)) + for i in image: + for j in i: + image_array[pxl_counter] = j + pxl_counter += 1 + pxl_counter = 0 + new_array[img_counter] = image_array + img_counter += 1 + + +nsamples, nx, ny = images.shape +images_reshaped = images.reshape((nsamples,nx*ny)) +# training quantum classifier +train_images, test_images, train_labels, test_labels = train_test_split( + images_reshaped, labels, test_size=0.2, random_state=420) + +sample_train, sample_val, labels_train, labels_val = train_test_split( + train_images, train_labels, test_size=0.2, random_state=42) +fig = plt.figure() +LABELS = [0, 1] +num_labels = len(LABELS) +for i in range(num_labels): + ax = fig.add_subplot(1, num_labels, i+1) + img = train_images[train_labels==LABELS[i]][0].reshape((28, 28)) + ax.imshow(img, cmap="Greys") + + + +standard_scaler = StandardScaler() +sample_train = standard_scaler.fit_transform(sample_train) +sample_val = standard_scaler.transform(sample_val) +test_images = standard_scaler.transform(test_images) + +# Reduce dimensions +N_DIM = 5 +pca = PCA(n_components=N_DIM) +sample_train = pca.fit_transform(sample_train) +sample_val = pca.transform(sample_val) +test_images = pca.transform(test_images) + +# Normalize +min_max_scaler = MinMaxScaler((-1, 1)) +sample_train = min_max_scaler.fit_transform(sample_train) +sample_val = min_max_scaler.transform(sample_val) +test_images = min_max_scaler.transform(test_images) + + +labels_train_0 = np.where(labels_train==0, 1, 0) +labels_val_0 = np.where(labels_val==0, 1, 0) + +print(f'Original validation labels: {labels_val}') +print(f'Validation labels for 0 vs Rest: {labels_val_0}') + +pauli_map_0 = PauliFeatureMap(feature_dimension=N_DIM, reps=2, paulis = ['X', 'Y', 'ZZ']) +pauli_kernel_0 = QuantumKernel(feature_map=pauli_map_0, quantum_instance=Aer.get_backend('statevector_simulator')) + +pauli_svc_0 = SVC(kernel='precomputed', probability=True) + +matrix_train_0 = pauli_kernel_0.evaluate(x_vec=sample_train) +pauli_svc_0.fit(matrix_train_0, labels_train_0) + +matrix_val_0 = pauli_kernel_0.evaluate(x_vec=sample_val, y_vec=sample_train) +pauli_score_0 = pauli_svc_0.score(matrix_val_0, labels_val_0) +print(f'Accuracy of discriminating between label 0 and others: {pauli_score_0*100}%') + +matrix_test_0 = pauli_kernel_0.evaluate(x_vec=test_images, y_vec=sample_train) +pred_0 = pauli_svc_0.predict_proba(matrix_test_0)[:, 1] +print(f'Probability of label 0: {np.round(pred_0, 2)}') + +pred = pauli_svc_0.predict_proba(matrix_test_0)[4] + +classifier_file = open('quantum_classifier.pickle', 'wb') +pickle.dump(pauli_kernel_0, classifier_file) +classifier_file.close() +matrix_test_0 = pauli_kernel_0.evaluate(x_vec=images_reshaped) +pred = pauli_svc_0.predict_proba(images)[0] +print(pred) From 9da6c9b313916e6292a7877b5925203ae04f6e58 Mon Sep 17 00:00:00 2001 From: Shraddha-2005 <63237790+Shraddha-2005@users.noreply.github.com> Date: Wed, 1 Feb 2023 14:40:14 +0530 Subject: [PATCH 10/10] Added requirements file --- requirements.txt | 211 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1e46433 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,211 @@ +aiofile==3.8.1 +aiohttp==3.8.3 +aiosignal==1.3.1 +alembic @ file:///home/conda/feedstock_root/build_artifacts/alembic_1647367721563/work +anyio @ file:///home/conda/feedstock_root/build_artifacts/anyio_1641898043316/work/dist +argon2-cffi @ file:///home/conda/feedstock_root/build_artifacts/argon2-cffi_1640817743617/work +argon2-cffi-bindings @ file:///home/conda/feedstock_root/build_artifacts/argon2-cffi-bindings_1640855140139/work +asttokens @ file:///home/conda/feedstock_root/build_artifacts/asttokens_1618968359944/work +async-generator==1.10 +async-timeout==4.0.2 +attrs @ file:///home/conda/feedstock_root/build_artifacts/attrs_1640799537051/work +awscli==1.27.57 +azure-core==1.26.2 +azure-identity==1.12.0 +azure-quantum @ file:///home/vsts_azpcontainer/conda-bld/qsharp_1670279498240/work/src/drops/wheels/azure_quantum-0.27.244707-py3-none-any.whl +azure-storage-blob==12.14.1 +Babel @ file:///home/conda/feedstock_root/build_artifacts/babel_1619719576210/work +backcall @ file:///home/conda/feedstock_root/build_artifacts/backcall_1592338393461/work +backports.functools-lru-cache @ file:///home/conda/feedstock_root/build_artifacts/backports.functools_lru_cache_1618230623929/work +beautifulsoup4 @ file:///home/conda/feedstock_root/build_artifacts/beautifulsoup4_1631087867185/work +bleach @ file:///home/conda/feedstock_root/build_artifacts/bleach_1629908509068/work +blinker==1.4 +bokeh==3.0.3 +botocore==1.29.57 +brotlipy @ file:///home/conda/feedstock_root/build_artifacts/brotlipy_1636012194889/work +caio==0.9.11 +certifi==2022.12.7 +certipy==0.1.3 +cffi @ file:///home/conda/feedstock_root/build_artifacts/cffi_1636046055389/work +charset-normalizer @ file:///home/conda/feedstock_root/build_artifacts/charset-normalizer_1644853463426/work +cirq-core==1.1.0 +cirq-ionq==1.1.0 +code-snippets @ file:///tmp/qbraid/wheels/code_snippets-0.1.2-py3-none-any.whl +colorama @ file:///home/conda/feedstock_root/build_artifacts/colorama_1602866480661/work +comm==0.1.2 +conda==4.11.0 +conda-package-handling @ file:///home/conda/feedstock_root/build_artifacts/conda-package-handling_1636021710069/work +configobj==5.0.8 +contourpy==1.0.7 +cryptography @ file:///home/conda/feedstock_root/build_artifacts/cryptography_1639699280527/work +cycler==0.11.0 +Cython==0.29.33 +debugpy @ file:///home/conda/feedstock_root/build_artifacts/debugpy_1636043249011/work +decorator @ file:///home/conda/feedstock_root/build_artifacts/decorator_1641555617451/work +defusedxml @ file:///home/conda/feedstock_root/build_artifacts/defusedxml_1615232257335/work +Deprecated==1.2.13 +dill==0.3.6 +docopt==0.6.2 +docs-react-widget @ file:///tmp/qbraid/wheels/docs_react_widget-0.1.0-py3-none-any.whl +docutils==0.16 +duet==0.2.7 +entrypoints @ file:///home/conda/feedstock_root/build_artifacts/entrypoints_1643888246732/work +environment-manager @ file:///tmp/qbraid/wheels/environment_manager-0.1.4-py3-none-any.whl +executing @ file:///home/conda/feedstock_root/build_artifacts/executing_1646044401614/work +fastjsonschema==2.16.2 +flit_core @ file:///home/conda/feedstock_root/build_artifacts/flit-core_1645629044586/work/source/flit_core +fonttools==4.38.0 +frozenlist==1.3.3 +future==0.18.3 +gitdb==4.0.10 +GitPython==3.1.30 +greenlet @ file:///home/conda/feedstock_root/build_artifacts/greenlet_1635836790477/work +idna @ file:///home/conda/feedstock_root/build_artifacts/idna_1642433548627/work +importlib-metadata==6.0.0 +importlib-resources @ file:///home/conda/feedstock_root/build_artifacts/importlib_resources_1635615662634/work +ipykernel==6.20.2 +ipyparallel==8.4.1 +ipython==8.8.0 +ipython-genutils==0.2.0 +ipyvue==1.8.0 +ipyvuetify==1.8.4 +ipywidgets==8.0.4 +isodate==0.6.1 +jedi @ file:///home/conda/feedstock_root/build_artifacts/jedi_1637175083648/work +Jinja2 @ file:///home/conda/feedstock_root/build_artifacts/jinja2_1636510082894/work +jmespath==1.0.1 +json5 @ file:///home/conda/feedstock_root/build_artifacts/json5_1600692310011/work +jsonschema @ file:///home/conda/feedstock_root/build_artifacts/jsonschema-meta_1642000296051/work +jupyter-bokeh==3.0.5 +jupyter-client @ file:///home/conda/feedstock_root/build_artifacts/jupyter_client_1642858610849/work +jupyter-server==1.23.5 +jupyter-server-mathjax==0.2.6 +jupyter-telemetry @ file:///home/conda/feedstock_root/build_artifacts/jupyter_telemetry_1605173804246/work +jupyter_core==5.1.5 +jupyterhub @ file:///home/conda/feedstock_root/build_artifacts/jupyterhub-feedstock_1647267198467/work +jupyterlab==3.5.3 +jupyterlab-git==0.41.0 +jupyterlab-pygments @ file:///home/conda/feedstock_root/build_artifacts/jupyterlab_pygments_1601375948261/work +jupyterlab-server @ file:///home/conda/feedstock_root/build_artifacts/jupyterlab_server_1641592475363/work +jupyterlab-widgets==3.0.5 +kiwisolver==1.4.4 +lab-main-menu @ file:///tmp/qbraid/wheels/lab_main_menu-0.1.1-py3-none-any.whl +libmambapy @ file:///home/conda/feedstock_root/build_artifacts/mamba-split_1644831758535/work/libmambapy +Mako @ file:///home/conda/feedstock_root/build_artifacts/mako_1646959760357/work +mamba @ file:///home/conda/feedstock_root/build_artifacts/mamba-split_1644831758535/work/mamba +Markdown==3.4.1 +MarkupSafe @ file:///home/conda/feedstock_root/build_artifacts/markupsafe_1647364298597/work +matplotlib==3.6.3 +matplotlib-inline @ file:///home/conda/feedstock_root/build_artifacts/matplotlib-inline_1631080358261/work +mistune==2.0.4 +mpltools==0.2.0 +mpmath==1.2.1 +msal==1.20.0 +msal-extensions==1.0.0 +msrest==0.7.1 +multidict==6.0.4 +nbclassic==0.4.8 +nbclient==0.7.2 +nbconvert==7.2.9 +nbdime==3.1.1 +nbformat==5.7.3 +nest-asyncio @ file:///home/conda/feedstock_root/build_artifacts/nest-asyncio_1638419302549/work +networkx==2.8.8 +notebook==6.5.2 +notebook-shim @ file:///home/conda/feedstock_root/build_artifacts/notebook-shim_1646330736330/work +ntlm-auth==1.5.0 +numpy==1.23.5 +oauthlib @ file:///home/conda/feedstock_root/build_artifacts/oauthlib_1643507977997/work +packaging @ file:///home/conda/feedstock_root/build_artifacts/packaging_1637239678211/work +pamela==1.0.0 +pandas==1.5.3 +pandocfilters @ file:///home/conda/feedstock_root/build_artifacts/pandocfilters_1631603243851/work +parso @ file:///home/conda/feedstock_root/build_artifacts/parso_1638334955874/work +pbr==5.11.1 +pexpect @ file:///home/conda/feedstock_root/build_artifacts/pexpect_1602535608087/work +pickleshare @ file:///home/conda/feedstock_root/build_artifacts/pickleshare_1602536217715/work +Pillow==9.4.0 +platformdirs==2.6.2 +ply==3.11 +portalocker==2.7.0 +prometheus-client @ file:///home/conda/feedstock_root/build_artifacts/prometheus_client_1643395600215/work +prompt-toolkit @ file:///home/conda/feedstock_root/build_artifacts/prompt-toolkit_1644497866770/work +protobuf==3.20.3 +psutil @ file:///home/conda/feedstock_root/build_artifacts/psutil_1640887138049/work +ptyprocess @ file:///home/conda/feedstock_root/build_artifacts/ptyprocess_1609419310487/work/dist/ptyprocess-0.7.0-py2.py3-none-any.whl +pure-eval @ file:///home/conda/feedstock_root/build_artifacts/pure_eval_1642875951954/work +py==1.11.0 +pyasn1==0.4.8 +pycosat @ file:///home/conda/feedstock_root/build_artifacts/pycosat_1636020362356/work +pycparser @ file:///home/conda/feedstock_root/build_artifacts/pycparser_1636257122734/work +pycurl==7.45.1 +Pygments @ file:///home/conda/feedstock_root/build_artifacts/pygments_1641580240686/work +PyJWT @ file:///home/conda/feedstock_root/build_artifacts/pyjwt_1638819640841/work +pyOpenSSL @ file:///home/conda/feedstock_root/build_artifacts/pyopenssl_1643496850550/work +pyparsing @ file:///home/conda/feedstock_root/build_artifacts/pyparsing_1642753572664/work +pyqir-generator==0.4.2a1 +pyrsistent @ file:///home/conda/feedstock_root/build_artifacts/pyrsistent_1642534390768/work +PySocks @ file:///home/conda/feedstock_root/build_artifacts/pysocks_1635862404942/work +python-dateutil @ file:///home/conda/feedstock_root/build_artifacts/python-dateutil_1626286286081/work +python-json-logger @ file:///home/conda/feedstock_root/build_artifacts/python-json-logger_1602545356084/work +python-markdown-math==0.8 +pytz @ file:///home/conda/feedstock_root/build_artifacts/pytz_1633452062248/work +PyYAML==5.4.1 +pyzmq @ file:///home/conda/feedstock_root/build_artifacts/pyzmq_1635877397296/work +qdk @ file:///home/vsts_azpcontainer/conda-bld/qsharp_1670279498240/work/src/drops/wheels/qdk-0.27.244707-py3-none-any.whl +QInfer==1.0 +qiskit==0.39.5 +qiskit-aer==0.11.2 +qiskit-ibmq-provider==0.19.2 +qiskit-ionq==0.3.10 +qiskit-qir==0.2.0 +qiskit-terra==0.22.4 +qsharp @ file:///home/vsts_azpcontainer/conda-bld/qsharp_1670279498240/work/src/drops/wheels/qsharp-0.27.244707-py3-none-any.whl +qsharp-chemistry @ file:///home/vsts_azpcontainer/conda-bld/qsharp_1670279498240/work/src/drops/wheels/qsharp_chemistry-0.27.244707-py3-none-any.whl +qsharp-core @ file:///home/vsts_azpcontainer/conda-bld/qsharp_1670279498240/work/src/drops/wheels/qsharp_core-0.27.244707-py3-none-any.whl +quantum-jobs @ file:///tmp/qbraid/wheels/quantum_jobs-0.1.1-py3-none-any.whl +qutip==4.7.1 +requests @ file:///home/conda/feedstock_root/build_artifacts/requests_1641580202195/work +requests-ntlm==1.1.0 +requests-oauthlib==1.3.1 +retry==0.9.2 +retworkx==0.12.1 +rsa==4.7.2 +ruamel-yaml-conda @ file:///home/conda/feedstock_root/build_artifacts/ruamel_yaml_1636009144459/work +ruamel.yaml @ file:///home/conda/feedstock_root/build_artifacts/ruamel.yaml_1644759508211/work +ruamel.yaml.clib @ file:///home/conda/feedstock_root/build_artifacts/ruamel.yaml.clib_1636815619750/work +rustworkx==0.12.1 +s3transfer==0.6.0 +scipy==1.10.0 +Send2Trash @ file:///home/conda/feedstock_root/build_artifacts/send2trash_1628511208346/work +six @ file:///home/conda/feedstock_root/build_artifacts/six_1620240208055/work +smmap==5.0.0 +sniffio @ file:///home/conda/feedstock_root/build_artifacts/sniffio_1635844660462/work +sortedcontainers==2.4.0 +soupsieve @ file:///home/conda/feedstock_root/build_artifacts/soupsieve_1638550740809/work +SQLAlchemy @ file:///home/conda/feedstock_root/build_artifacts/sqlalchemy_1646615291967/work +stack-data @ file:///home/conda/feedstock_root/build_artifacts/stack_data_1644872665635/work +stevedore==4.1.1 +symengine==0.9.2 +sympy==1.11.1 +terminado @ file:///home/conda/feedstock_root/build_artifacts/terminado_1646684455438/work +testpath @ file:///home/conda/feedstock_root/build_artifacts/testpath_1645693042223/work +tinycss2==1.2.1 +tomli==2.0.1 +tornado @ file:///home/conda/feedstock_root/build_artifacts/tornado_1635819584296/work +tqdm @ file:///home/conda/feedstock_root/build_artifacts/tqdm_1632160078689/work +traitlets==5.8.1 +tweedledum==1.1.1 +typing_extensions==4.4.0 +ui-tweaks @ file:///tmp/qbraid/wheels/ui_tweaks-0.1.1-py3-none-any.whl +urllib3 @ file:///home/conda/feedstock_root/build_artifacts/urllib3_1641584929973/work +wcwidth @ file:///home/conda/feedstock_root/build_artifacts/wcwidth_1600965781394/work +webencodings==0.5.1 +websocket-client @ file:///home/conda/feedstock_root/build_artifacts/websocket-client_1645884408572/work +websockets==10.4 +widgetsnbextension==4.0.5 +wrapt==1.14.1 +xyzservices==2022.9.0 +yarl==1.8.2 +zipp @ file:///home/conda/feedstock_root/build_artifacts/zipp_1643828507773/work +