diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..87620ac --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.ipynb_checkpoints/ diff --git a/.ipynb_checkpoints/examples-checkpoint.ipynb b/.ipynb_checkpoints/examples-checkpoint.ipynb deleted file mode 100644 index 91fd780..0000000 --- a/.ipynb_checkpoints/examples-checkpoint.ipynb +++ /dev/null @@ -1,251 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 23, - "id": "4d3113ae", - "metadata": {}, - "outputs": [], - "source": [ - "import cirq\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", - "\n", - "#define utility functions\n", - "\n", - "def simulate(circuit: cirq.Circuit) -> dict:\n", - " \"\"\"This funcion simulate a cirq circuit (without measurement) and output results in the format of histogram.\n", - " \"\"\"\n", - " simulator = cirq.Simulator()\n", - " result = simulator.simulate(circuit)\n", - " \n", - " state_vector=result.final_state_vector\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", - "def count_gates(circuit: cirq.Circuit):\n", - " \"\"\"Returns the number of 1-qubit gates, number of 2-qubit gates, number of 3-qubit gates....\"\"\"\n", - " counter=Counter([len(op.qubits) for op in circuit.all_operations()])\n", - " \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", - "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)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "id": "82f90e0d", - "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": 18, - "id": "cb96a334", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAej0lEQVR4nO3dfXCU9d3v8c9uHpYEksUQ8lQCDajQCsS7VFJGpVhygHTGAeX0+HRmwOOB0QanSK2edFTUdia9cY51dFL8p4U6Iz7NCBy9O/QomDC2QG9QhmFqcxMaJdyQINgkJJBkk/2dPzhuuxK0v2WTb7K8XzPXDNm9Prm+XFzw4cpufgk455wAABhmQesBAABXJgoIAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJtKtB/iiaDSqEydOKCcnR4FAwHocAIAn55zOnj2rkpISBYOXvs8ZcQV04sQJlZaWWo8BALhMLS0tmjRp0iWfH3EFlJOTI0m6Sd9XujKMp0GypU+59MV4KUdXlnhnCq5v885I0om/TvTOZJ5O884EI94RnZ/iH7rtXz7wP5CkXcev9c5MfCaBf04O/Nk/gxGvXxG9r9/F/j2/lCEroLq6Oj3zzDNqbW1VeXm5XnjhBc2dO/cr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DggAYIICAgCYoIAAACYoIACACQoIAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJFiPFiPf+J1O9M3fk70voWH/rH+uduX7sMe9MIot9JiLiEvsrfrp/nHcmeD7inRnwTiCVcAcEADBBAQEATHgX0O7du3XrrbeqpKREgUBA27Zti3veOacnnnhCxcXFysrKUmVlpY4cOZKseQEAKcK7gLq7u1VeXq66urpBn9+wYYOef/55vfjii9q3b5/Gjh2rxYsXq6en57KHBQCkDu9XKKuqqlRVVTXoc845Pffcc3rssce0dOlSSdJLL72kwsJCbdu2TXfeeeflTQsASBlJfQ2oublZra2tqqysjD0WDodVUVGhPXv2DJrp7e1VZ2dn3AYASH1JLaDW1lZJUmFhYdzjhYWFsee+qLa2VuFwOLaVlpYmcyQAwAhl/i64mpoadXR0xLaWlhbrkQAAwyCpBVRUVCRJamtri3u8ra0t9twXhUIh5ebmxm0AgNSX1AIqKytTUVGRdu7cGXuss7NT+/bt07x585J5KADAKOf9Lriuri41NTXFPm5ubtbBgweVl5enyZMna+3atfr5z3+ua665RmVlZXr88cdVUlKiZcuWJXNuAMAo511A+/fv1y233BL7eN26dZKkFStWaPPmzXrkkUfU3d2t1atXq729XTfddJN27NihMWPGJG9qAMCo511ACxYskHPuks8HAgE9/fTTevrppy9rMOBzkR7/BTV7XGKLfUZcmndmwA3Pe3kyAv5Ld44J+i8QKkklGX/zzuzLuj6hY+HKZf4uOADAlYkCAgCYoIAAACYoIACACQoIAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYMJ/mWFgmP2Xb3zknfm0P7GfrJvIathtkbB3piTTf7XpMQH/la1bInneGUnKC3V5Z9qe8F+tu2CpdwQphDsgAIAJCggAYIICAgCYoIAAACYoIACACQoIAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJliMFCPe1KzT3pmOgeyEjnVVerd3JjvY550JKuqdSWRh0TQ578yFY03wzvyPq/d4Z/4tfaJ3xvX3e2cwM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18KFCw0nGxrV1dU6fPjwFfE66Je51HlYvXp17NezZs1ScXGxFi5cqKNHj2ratGnDPeagRvyX4PLz85WWlnbRu1ja2tpUVFRkNNXIMH78eF177bVqamqyHsXM59cA18fFpk6dqvz8/JS8PtasWaO3335b7733XtyPbykqKlJfX5/a29vj9k/V6+FS52EwFRUVkjSirocRX0CZmZmaM2eOdu7cGXssGo1q586dmjdvnuFk9rq6unT06FEVFxdbj2KmrKxMRUVFcddHZ2en9u3bd8VfH8ePH9eZM2dS6vpwzmnNmjXaunWrdu3apbKysrjn58yZo4yMjLjrobGxUceOHUup6+GrzsNgDh48KEkj63qwfhfEP+PVV191oVDIbd682f35z392q1evduPHj3etra3Wow2rH//4x66+vt41Nze7P/zhD66ystLl5+e7U6dOWY82pM6ePes+/PBD9+GHHzpJ7tlnn3Uffvih++STT5xzzv3iF79w48ePd9u3b3eHDh1yS5cudWVlZe78+fPGkyfXl52Hs2fPuocfftjt2bPHNTc3u3fffdd961vfctdcc43r6emxHj1pHnjgARcOh119fb07efJkbDt37lxsn/vvv99NnjzZ7dq1y+3fv9/NmzfPzZs3z3Dq5Puq89DU1OSefvppt3//ftfc3Oy2b9/upk6d6ubPn288ebxRUUDOOffCCy+4yZMnu8zMTDd37ly3d+9e65GG3R133OGKi4tdZmam+9rXvubuuOMO19TUZD3WkHvvvfecpIu2FStWOOcuvBX78ccfd4WFhS4UCrmFCxe6xsZG26GHwJedh3PnzrlFixa5iRMnuoyMDDdlyhS3atWqlPtP2mC/f0lu06ZNsX3Onz/vfvjDH7qrrrrKZWdnu9tuu82dPHnSbugh8FXn4dixY27+/PkuLy/PhUIhd/XVV7uf/OQnrqOjw3bwL+DHMQAATIz414AAAKmJAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYIICAgCYoIAAACYoIACAif8H8OZooPKJKDYAAAAASUVORK5CYII=\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "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": 25, - "id": "b02b160e", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.0\n" - ] - } - ], - "source": [ - "#submission part 1\n", - "\n", - "#load the definition of the encoder and decoder\n", - "from part1 import encode,decode\n", - "\n", - "n=len(dataset)\n", - "mse=0\n", - "gatecount=0\n", - "\n", - "for data in dataset:\n", - " #encode image into circuit\n", - " circuit=encode(data['image'])\n", - " \n", - " #simulate circuit\n", - " histogram=simulate(circuit)\n", - " \n", - " #count the number of 2-qubit gates\n", - " gatecount+=count_gates(circuit)[2]\n", - " \n", - " #reconstruct the image\n", - " image_re=decode(histogram)\n", - " \n", - " #calculate mse\n", - " mse+=image_mse(data['image'],image_re)\n", - " \n", - "#fidelity of reconstruction\n", - "f=1-mse\n", - "gatecount=gatecount/n\n", - "\n", - "#score for part1 \n", - "print(f*(0.999**gatecount))" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "id": "2fe52c43", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.0\n" - ] - } - ], - "source": [ - "#grade part 2\n", - "\n", - "#load classifier circuit\n", - "with open('part2.pickle', 'rb') as f:\n", - " classifier=pickle.load(f)\n", - " \n", - "score=0\n", - "\n", - "\n", - "for data in dataset:\n", - " #encode image into circuit\n", - " circuit=encode(data['image'])\n", - " \n", - " #append with classifier circuit\n", - " \n", - " circuit.append(classifier)\n", - " \n", - " #simulate circuit\n", - " histogram=simulate(circuit)\n", - " \n", - " #count the gate used in the circuit for score calculation\n", - " gatecount+=count_gates(circuit)[2]\n", - " \n", - " #convert histogram to category\n", - " cat=histogram_to_category(histogram)\n", - " \n", - " if cat==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": null, - "id": "de96fdf1", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.8.0" - }, - "vscode": { - "interpreter": { - "hash": "1a1af0ee75eeea9e2e1ee996c87e7a2b11a0bebd85af04bb136d915cefc0abce" - } - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/.ipynb_checkpoints/part1_example_cirq-checkpoint.ipynb b/.ipynb_checkpoints/part1_example_cirq-checkpoint.ipynb deleted file mode 100644 index c3d383b..0000000 --- a/.ipynb_checkpoints/part1_example_cirq-checkpoint.ipynb +++ /dev/null @@ -1,226 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 8, - "id": "9c97e0dc", - "metadata": {}, - "outputs": [], - "source": [ - "import cirq\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", - "\n", - "#define utility functions\n", - "\n", - "def simulate(circuit: cirq.Circuit) -> dict:\n", - " \"\"\"This funcion simulate a cirq circuit (without measurement) and output results in the format of histogram.\n", - " \"\"\"\n", - " simulator = cirq.Simulator()\n", - " result = simulator.simulate(circuit)\n", - " \n", - " state_vector=result.final_state_vector\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", - "def count_gates(circuit: cirq.Circuit):\n", - " \"\"\"Returns the number of 1-qubit gates, number of 2-qubit gates, number of 3-qubit gates....\"\"\"\n", - " counter=Counter([len(op.qubits) for op in circuit.all_operations()])\n", - " \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", - "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)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "7f19ddcc", - "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": 6, - "id": "a443b6a8", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAej0lEQVR4nO3dfXCU9d3v8c9uHpYEksUQ8lQCDajQCsS7VFJGpVhygHTGAeX0+HRmwOOB0QanSK2edFTUdia9cY51dFL8p4U6Iz7NCBy9O/QomDC2QG9QhmFqcxMaJdyQINgkJJBkk/2dPzhuuxK0v2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fKHU4F2X9j48meWeukf8Cpkgd3AEBAExQQAAAExQQAMAEBQQAMEEBAQBMUEAAABMUEADABAUEADBBAQEATFBAAAATFBAAwAQFBAAwQQEBAEywGjaGVX9rm3fmd+3l3pmbc//DOyNJ//aZ/7FOR3K8M1OyTntnWnvD3pmoC3hnLuT8/29aXJ/QoXAF4w4IAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYIICAgCYoIAAACYoIACACRYjxYjXHsn2zpSmf5bQsW7IbfbO/PlcSULH8jUuvdc7E4mmJXSsnmiGdybnr13eGeedQCrhDggAYIICAgCYoIAAACYoIACACQoIAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJFiPFiPf+J1O9M3fk70voWH/rH+uduX7sMe9MIot9JiLiEvsrfrp/nHcmeD7inRnwTiCVcAcEADBBAQEATHgX0O7du3XrrbeqpKREgUBA27Zti3veOacnnnhCxcXFysrKUmVlpY4cOZKseQEAKcK7gLq7u1VeXq66urpBn9+wYYOef/55vfjii9q3b5/Gjh2rxYsXq6en57KHBQCkDu9XKKuqqlRVVTXoc845Pffcc3rssce0dOlSSdJLL72kwsJCbdu2TXfeeeflTQsASBlJfQ2oublZra2tqqysjD0WDodVUVGhPXv2DJrp7e1VZ2dn3AYASH1JLaDW1lZJUmFhYdzjhYWFsee+qLa2VuFwOLaVlpYmcyQAwAhl/i64mpoadXR0xLaWlhbrkQAAwyCpBVRUVCRJamtri3u8ra0t9twXhUIh5ebmxm0AgNSX1AIqKytTUVGRdu7cGXuss7NT+/bt07x585J5KADAKOf9Lriuri41NTXFPm5ubtbBgweVl5enyZMna+3atfr5z3+ua665RmVlZXr88cdVUlKiZcuWJXNuAMAo511A+/fv1y233BL7eN26dZKkFStWaPPmzXrkkUfU3d2t1atXq729XTfddJN27NihMWPGJG9qAMCo511ACxYskHPuks8HAgE9/fTTevrppy9rMOBzkR7/BTV7XGKLfUZcmndmwA3Pe3kyAv5Ld44J+i8QKkklGX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zxPHzu5ZdfVn5+vmbOnKmamhqdO3fOYrxLGnGLkX7R6dOnNTAwoMLCwrjHCwsL9Ze//MVoKhsVFRXavHmzpk+frpMnT+qpp57SzTffrMOHDysnJ8d6PBOtra2SNOj18flzV4olS5bo9ttvV1lZmY4ePaqf/vSnqqqq0p49e5SWlmY9XtJFo1GtXbtWN954o2bOnCnpwvWQmZmp8ePHx+2bytfDYOdBku6++25NmTJFJSUlOnTokB599FE1NjbqzTffNJw23ogvIPxdVVVV7NezZ89WRUWFpkyZotdff1333Xef4WQYCe68887Yr2fNmqXZs2dr2rRpqq+v18KFCw0nGxrV1dU6fPjwFfE66Je51HlYvXp17NezZs1ScXGxFi5cqKNHj2ratGnDPeagRvyX4PLz85WWlnbRu1ja2tpUVFRkNNXIMH78eF177bVqamqyHsXM59cA18fFpk6dqvz8/JS8PtasWaO3335b7733XtyPbykqKlJfX5/a29vj9k/V6+FS52EwFRUVkjSirocRX0CZmZmaM2eOdu7cGXssGo1q586dmjdvnuFk9rq6unT06FEVFxdbj2KmrKxMRUVFcddHZ2en9u3bd8VfH8ePH9eZM2dS6vpwzmnNmjXaunWrdu3apbKysrjn58yZo4yMjLjrobGxUceOHUup6+GrzsNgDh48KEkj63qwfhfEP+PVV191oVDIbd682f35z392q1evduPHj3etra3Wow2rH//4x66+vt41Nze7P/zhD66ystLl5+e7U6dOWY82pM6ePes+/PBD9+GHHzpJ7tlnn3Uffvih++STT5xzzv3iF79w48ePd9u3b3eHDh1yS5cudWVlZe78+fPGkyfXl52Hs2fPuocfftjt2bPHNTc3u3fffdd961vfctdcc43r6emxHj1pHnjgARcOh119fb07efJkbDt37lxsn/vvv99NnjzZ7dq1y+3fv9/NmzfPzZs3z3Dq5Puq89DU1OSefvppt3//ftfc3Oy2b9/upk6d6ubPn288ebxRUUDOOffCCy+4yZMnu8zMTDd37ly3d+9e65GG3R133OGKi4tdZmam+9rXvubuuOMO19TUZD3WkHvvvfecpIu2FStWOOcuvBX78ccfd4WFhS4UCrmFCxe6xsZG26GHwJedh3PnzrlFixa5iRMnuoyMDDdlyhS3atWqlPtP2mC/f0lu06ZNsX3Onz/vfvjDH7qrrrrKZWdnu9tuu82dPHnSbugh8FXn4dixY27+/PkuLy/PhUIhd/XVV7uf/OQnrqOjw3bwL+DHMQAATIz414AAAKmJAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYIICAgCYoIAAACYoIACAif8H8OZooPKJKDYAAAAASUVORK5CYII=\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "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": 12, - "id": "cb2031cd", - "metadata": {}, - "outputs": [], - "source": [ - "#submission to part 1, you should make this into a .py file\n", - "\n", - "n=len(dataset)\n", - "mse=0\n", - "gatecount=0\n", - "\n", - "def encode(image):\n", - " circuit=cirq.Circuit()\n", - " if image[0][0]==0:\n", - " circuit.append(cirq.rx(np.pi).on(cirq.LineQubit(0)))\n", - " return circuit\n", - "\n", - "def decode(histogram):\n", - " if 1 in histogram.keys():\n", - " image=[[0,0],[0,0]]\n", - " else:\n", - " image=[[1,1],[1,1]]\n", - " return image\n", - "\n", - "def run_part1(image):\n", - " #encode image into a circuit\n", - " circuit=encode(data['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": 13, - "id": "385faa44", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.0\n" - ] - } - ], - "source": [ - "#how we grade your submission\n", - "\n", - "n=len(dataset)\n", - "mse=0\n", - "gatecount=0\n", - "\n", - "for data in dataset:\n", - " #encode image into circuit\n", - " circuit,image_re=run_part1(data['image'])\n", - " \n", - " #count the number of 2qubit gates used\n", - " gatecount+=count_gates(circuit)[2]\n", - " \n", - " #calculate mse\n", - " mse+=image_mse(data['image'],image_re)\n", - " \n", - "#fidelity of reconstruction\n", - "f=1-mse\n", - "gatecount=gatecount/n\n", - "\n", - "#score for part1 \n", - "print(f*(0.999**gatecount))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ad7e81d7", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.8.0" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/.ipynb_checkpoints/part2_example_cirq-checkpoint.ipynb b/.ipynb_checkpoints/part2_example_cirq-checkpoint.ipynb deleted file mode 100644 index 2bb7a6d..0000000 --- a/.ipynb_checkpoints/part2_example_cirq-checkpoint.ipynb +++ /dev/null @@ -1,221 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 2, - "id": "5519a2aa", - "metadata": {}, - "outputs": [], - "source": [ - "import cirq\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", - "\n", - "#define utility functions\n", - "\n", - "def simulate(circuit: cirq.Circuit) -> dict:\n", - " \"\"\"This funcion simulate a cirq circuit (without measurement) and output results in the format of histogram.\n", - " \"\"\"\n", - " simulator = cirq.Simulator()\n", - " result = simulator.simulate(circuit)\n", - " \n", - " state_vector=result.final_state_vector\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", - "def count_gates(circuit: cirq.Circuit):\n", - " \"\"\"Returns the number of 1-qubit gates, number of 2-qubit gates, number of 3-qubit gates....\"\"\"\n", - " counter=Counter([len(op.qubits) for op in circuit.all_operations()])\n", - " \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" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "11a77286", - "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": 5, - "id": "dfbb6735", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAej0lEQVR4nO3dfXCU9d3v8c9uHpYEksUQ8lQCDajQCsS7VFJGpVhygHTGAeX0+HRmwOOB0QanSK2edFTUdia9cY51dFL8p4U6Iz7NCBy9O/QomDC2QG9QhmFqcxMaJdyQINgkJJBkk/2dPzhuuxK0v2WTb7K8XzP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j48meWeukf8Cpkgd3AEBAExQQAAAExQQAMAEBQQAMEEBAQBMUEAAABMUEADABAUEADBBAQEATFBAAAATFBAAwAQFBAAwQQEBAEywGjaGVX9rm3fmd+3l3pmbc//DOyNJ//aZ/7FOR3K8M1OyTntnWnvD3pmoC3hnLuT8/29aXJ/QoXAF4w4IAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYIICAgCYoIAAACYoIACACRYjxYjXHsn2zpSmf5bQsW7IbfbO/PlcSULH8jUuvdc7E4mmJXSsnmiGdybnr13eGeedQCrhDggAYIICAgCYoIAAACYoIACACQoIAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJFiPFiPf+J1O9M3fk70voWH/rH+uduX7sMe9MIot9JiLiEvsrfrp/nHcmeD7inRnwTiCVcAcEADBBAQEATHgX0O7du3XrrbeqpKREgUBA27Zti3veOacnnnhCxcXFysrKUmVlpY4cOZKseQEAKcK7gLq7u1VeXq66urpBn9+wYYOef/55vfjii9q3b5/Gjh2rxYsXq6en57KHBQCkDu9XKKuqqlRVVTXoc845Pffcc3rssce0dOlSSdJLL72kwsJCbdu2TXfeeeflTQsASBlJfQ2oublZra2tqqysjD0WDodVUVGhPXv2DJrp7e1VZ2dn3AYASH1JLaDW1lZJUmFhYdzjhYWFsee+qLa2VuFwOLaVlpYmcyQAwAhl/i64mpoadXR0xLaWlhbrkQAAwyCpBVRUVCRJamtri3u8ra0t9twXhUIh5ebmxm0AgNSX1AIqKytTUVGRdu7cGXuss7NT+/bt07x585J5KADAKOf9Lriuri41NTXFPm5ubtbBgweVl5enyZMna+3atfr5z3+ua665RmVlZXr88cdVUlKiZcuWJXNuAMAo511A+/fv1y233BL7eN26dZKkFStWaPPmzXrkkUfU3d2t1atXq729XTfddJN27NihMWPGJG9qAMCo511ACxYskHPuks8HAgE9/fTTevrppy9rMOBzkR7/BTV7XGKLfUZcmndmwA3Pe3kyAv5Ld44J+i8QKkklGX/zzuzLuj6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dfVn5+vmbOnKmamhqdO3fOYrxLGnGLkX7R6dOnNTAwoMLCwrjHCwsL9Ze//MVoKhsVFRXavHmzpk+frpMnT+qpp57SzTffrMOHDysnJ8d6PBOtra2SNOj18flzV4olS5bo9ttvV1lZmY4ePaqf/vSnqqqq0p49e5SWlmY9XtJFo1GtXbtWN954o2bOnCnpwvWQmZmp8ePHx+2bytfDYOdBku6++25NmTJFJSUlOnTokB599FE1NjbqzTffNJw23ogvIPxdVVVV7NezZ89WRUWFpkyZotdff1333Xef4WQYCe68887Yr2fNmqXZs2dr2rRpqq+v18KFCw0nGxrV1dU6fPjwFfE66Je51HlYvXp17NezZs1ScXGxFi5cqKNHj2ratGnDPeagRvyX4PLz85WWlnbRu1ja2tpUVFRkNNXIMH78eF177bVqamqyHsXM59cA18fFpk6dqvz8/JS8PtasWaO3335b7733XtyPbykqKlJfX5/a29vj9k/V6+FS52EwFRUVkjSirocRX0CZmZmaM2eOdu7cGXssGo1q586dmjdvnuFk9rq6unT06FEVFxdbj2KmrKxMRUVFcddHZ2en9u3bd8VfH8ePH9eZM2dS6vpwzmnNmjXaunWrdu3apbKysrjn58yZo4yMjLjrobGxUceOHUup6+GrzsNgDh48KEkj63qwfhfEP+PVV191oVDIbd682f35z392q1evduPHj3etra3Wow2rH//4x66+vt41Nze7P/zhD66ystLl5+e7U6dOWY82pM6ePes+/PBD9+GHHzpJ7tlnn3Uffvih++STT5xzzv3iF79w48ePd9u3b3eHDh1yS5cudWVlZe78+fPGkyfXl52Hs2fPuocfftjt2bPHNTc3u3fffdd961vfctdcc43r6emxHj1pHnjgARcOh119fb07efJkbDt37lxsn/vvv99NnjzZ7dq1y+3fv9/NmzfPzZs3z3Dq5Puq89DU1OSefvppt3//ftfc3Oy2b9/upk6d6ubPn288ebxRUUDOOffCCy+4yZMnu8zMTDd37ly3d+9e65GG3R133OGKi4tdZmam+9rXvubuuOMO19TUZD3WkHvvvfecpIu2FStWOOcuvBX78ccfd4WFhS4UCrmFCxe6xsZG26GHwJedh3PnzrlFixa5iRMnuoyMDDdlyhS3atWqlPtP2mC/f0lu06ZNsX3Onz/vfvjDH7qrrrrKZWdnu9tuu82dPHnSbugh8FXn4dixY27+/PkuLy/PhUIhd/XVV7uf/OQnrqOjw3bwL+DHMQAATIz414AAAKmJAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYIICAgCYoIAAACYoIACAif8H8OZooPKJKDYAAAAASUVORK5CYII=\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "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": 9, - "id": "66e9a047", - "metadata": {}, - "outputs": [], - "source": [ - "#you submission\n", - "\n", - "def encode(image):\n", - " circuit=cirq.Circuit()\n", - " if image[0][0]==0:\n", - " circuit.append(cirq.rx(np.pi).on(cirq.LineQubit(0)))\n", - " return circuit\n", - "\n", - "\n", - "def run_part2(image):\n", - "\n", - " #loade the quantum classifier circuit\n", - " with open('part2.pickle', 'rb') as f:\n", - " classifier=pickle.load(f)\n", - " \n", - " #encode image into circuit\n", - " circuit=encode(image)\n", - " \n", - " #append with classifier circuit\n", - " \n", - " circuit.append(classifier)\n", - " \n", - " #simulate circuit\n", - " histogram=simulate(circuit)\n", - " \n", - " #convert histogram to category\n", - " label=histogram_to_category(histogram)\n", - " \n", - " return circuit,label\n", - "#score" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "18e6015f", - "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": null, - "id": "a73d2810", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.8.0" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/__pycache__/part1.cpython-39.pyc b/__pycache__/part1.cpython-39.pyc index 9e215d2..e7f94c0 100644 Binary files a/__pycache__/part1.cpython-39.pyc and b/__pycache__/part1.cpython-39.pyc differ diff --git a/examples.ipynb b/examples.ipynb deleted file mode 100644 index 5923d9e..0000000 --- a/examples.ipynb +++ /dev/null @@ -1,249 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 23, - "id": "4d3113ae", - "metadata": {}, - "outputs": [], - "source": [ - "import cirq\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", - "\n", - "#define utility functions\n", - "\n", - "def simulate(circuit: cirq.Circuit) -> dict:\n", - " \"\"\"This funcion simulate a cirq circuit (without measurement) and output results in the format of histogram.\n", - " \"\"\"\n", - " simulator = cirq.Simulator()\n", - " result = simulator.simulate(circuit)\n", - " \n", - " state_vector=result.final_state_vector\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", - "def count_gates(circuit: cirq.Circuit):\n", - " \"\"\"Returns the number of 1-qubit gates, number of 2-qubit gates, number of 3-qubit gates....\"\"\"\n", - " counter=Counter([len(op.qubits) for op in circuit.all_operations()])\n", - " \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", - "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)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "id": "82f90e0d", - "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": 18, - "id": "cb96a334", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAej0lEQVR4nO3dfXCU9d3v8c9uHpYEksUQ8lQCDajQCsS7VFJGpVhygHTGAeX0+HRmwOOB0QanSK2edFTUdia9cY51d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BAEwM+Q+kA/7R+JXd3pn2P2R5Z8YEI94ZSerq9//hiFOz/BdY/ai7xDuTHvRfKHU4F2X9j48meWeukf8Cpkgd3AEBAExQQAAAExQQAMAEBQQAMEEBAQBMUEAAABMUEADABAUEADBBAQEATFBAAAATFBAAwAQFBAAwQQEBAEywGjaGVX9rm3fmd+3l3pmbc//DOyNJ//aZ/7FOR3K8M1OyTntnWnvD3pmoC3hnLuT8/29aXJ/QoXAF4w4IAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYIICAgCYoIAAACYoIACACRYjxYjXHsn2zpSmf5bQsW7IbfbO/PlcSULH8jUuvdc7E4mmJXSsnmiGdybnr13eGeedQCrhDggAYIICAgCYoIAAACYoIACACQoIAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJFiPFiPf+J1O9M3fk70voWH/rH+uduX7sMe9MIot9JiLiEvsrfrp/nHcmeD7inRnwTiCVcAcEADBBAQEATHgX0O7du3XrrbeqpKREgUBA27Zti3veOacnnnhCxcXFysrKUmVlpY4cOZKseQEAKcK7gLq7u1VeXq66urpBn9+wYYOef/55vfjii9q3b5/Gjh2rxYsXq6en57KHBQCkDu9XKKuqqlRVVTXoc845Pffcc3rssce0dOlSSdJLL72kwsJCbdu2TXfeeeflTQsASBlJfQ2oublZra2tqqysjD0WDodVUVGhPXv2DJrp7e1VZ2dn3AYASH1JLaDW1lZJUmFhYdzjhYWFsee+qLa2VuFwOLaVlpYmcyQAwAhl/i64mpoadXR0xLaWlhbrkQAAwyCpBVRUVCRJamtri3u8ra0t9twXhUIh5ebmxm0AgNSX1AIqKytTUVGRdu7cGXuss7NT+/bt07x585J5KADAKOf9Lriuri41NTXFPm5ubtbBgweVl5enyZMna+3atfr5z3+ua665RmVlZXr88cdVUlKiZcuWJXNuAMAo511A+/fv1y233BL7eN26dZKkFStWaPPmzXrkkUfU3d2t1atXq729XTfddJN27NihMWPGJG9qAMCo511ACxYskHPuks8HAgE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QUKDp06frgQce0JkzZ6xHGlIdHR2SpLy8PEnSgQMHFIlE4q6HGTNmaPLkySl9PXzxPHzu5ZdfVn5+vmbOnKmamhqdO3fOYrxLGnGLkX7R6dOnNTAwoMLCwrjHCwsL9Ze//MVoKhsVFRXavHmzpk+frpMnT+qpp57SzTffrMOHDysnJ8d6PBOtra2SNOj18flzV4olS5bo9ttvV1lZmY4ePaqf/vSnqqqq0p49e5SWlmY9XtJFo1GtXbtWN954o2bOnCnpwvWQmZmp8ePHx+2bytfDYOdBku6++25NmTJFJSUlOnTokB599FE1NjbqzTffNJw23ogvIPxdVVVV7NezZ89WRUWFpkyZotdff1333Xef4WQYCe68887Yr2fNmqXZs2dr2rRpqq+v18KFCw0nGxrV1dU6fPjwFfE66Je51HlYvXp17NezZs1ScXGxFi5cqKNHj2ratGnDPeagRvyX4PLz85WWlnbRu1ja2tpUVFRkNNXIMH78eF177bVqamqyHsXM59cA18fFpk6dqvz8/JS8PtasWaO3335b7733XtyPbykqKlJfX5/a29vj9k/V6+FS52EwFRUVkjSirocRX0CZmZmaM2eOdu7cGXssGo1q586dmjdvnuFk9rq6unT06FEVFxdbj2KmrKxMRUVFcddHZ2en9u3bd8VfH8ePH9eZM2dS6vpwzmnNmjXaunWrdu3apbKysrjn58yZo4yMjLjrobGxUceOHUup6+GrzsNgDh48KEkj63qwfhfEP+PVV191oVDIbd682f35z392q1evduPHj3etra3Wow2rH//4x66+vt41Nze7P/zhD66ystLl5+e7U6dOWY82pM6ePes+/PBD9+GHHzpJ7tlnn3Uffvih++STT5xzzv3iF79w48ePd9u3b3eHDh1yS5cudWVlZe78+fPGkyfXl52Hs2fPuocfftjt2bPHNTc3u3fffdd961vfctdcc43r6emxHj1pHnjgARcOh119fb07efJkbDt37lxsn/vvv99NnjzZ7dq1y+3fv9/NmzfPzZs3z3Dq5Puq89DU1OSefvppt3//ftfc3Oy2b9/upk6d6ubPn288ebxRUUDOOffCCy+4yZMnu8zMTDd37ly3d+9e65GG3R133OGKi4tdZmam+9rXvubuuOMO19TUZD3WkHvvvfecpIu2FStWOOcuvBX78ccfd4WFhS4UCrmFCxe6xsZG26GHwJedh3PnzrlFixa5iRMnuoyMDDdlyhS3atWqlPtP2mC/f0lu06ZNsX3Onz/vfvjDH7qrrrrKZWdnu9tuu82dPHnSbugh8FXn4dixY27+/PkuLy/PhUIhd/XVV7uf/OQnrqOjw3bwL+DHMQAATIz414AAAKmJAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYIICAgCYoIAAACYoIACAif8H8OZooPKJKDYAAAAASUVORK5CYII=\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "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": 25, - "id": "b02b160e", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.0\n" - ] - } - ], - "source": [ - "#grade part1\n", - "from part1 import encode_cirq,decode\n", - "\n", - "n=len(dataset)\n", - "mse=0\n", - "gatecount=0\n", - "\n", - "for data in dataset:\n", - " #encode image into circuit\n", - " circuit=encode_cirq(data['image'])\n", - " \n", - " #simulate circuit\n", - " histogram=simulate(circuit)\n", - " \n", - " #count the number of 2-qubit gates\n", - " gatecount+=count_gates(circuit)[2]\n", - " \n", - " #reconstruct the image\n", - " image_re=decode(histogram)\n", - " \n", - " #calculate mse\n", - " mse+=image_mse(data['image'],image_re)\n", - " \n", - "#fidelity of reconstruction\n", - "f=1-mse\n", - "gatecount=gatecount/n\n", - "\n", - "#score for part1 \n", - "print(f*(0.999**gatecount))" - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "id": "2fe52c43", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.0\n" - ] - } - ], - "source": [ - "#grade part 2\n", - "\n", - "#load classifier circuit\n", - "with open('part2.pickle', 'rb') as f:\n", - " classifier=pickle.load(f)\n", - " \n", - "score=0\n", - "\n", - "\n", - "for data in dataset:\n", - " #encode image into circuit\n", - " circuit=encode_cirq(data['image'])\n", - " \n", - " #append with classifier circuit\n", - " \n", - " circuit.append(classifier)\n", - " \n", - " #simulate circuit\n", - " histogram=simulate(circuit)\n", - " \n", - " #count the gate used in the circuit for score calculation\n", - " gatecount+=count_gates(circuit)[2]\n", - " \n", - " #convert histogram to category\n", - " cat=histogram_to_category(histogram)\n", - " \n", - " if cat==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": null, - "id": "de96fdf1", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.11.0 (main, Oct 25 2022, 14:13:24) [Clang 14.0.0 (clang-1400.0.29.202)]" - }, - "vscode": { - "interpreter": { - "hash": "1a1af0ee75eeea9e2e1ee996c87e7a2b11a0bebd85af04bb136d915cefc0abce" - } - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/examples_qiskit.ipynb b/examples_qiskit.ipynb deleted file mode 100644 index bab8c57..0000000 --- a/examples_qiskit.ipynb +++ /dev/null @@ -1,204 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "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", - "\n", - "#define utility functions\n", - "\n", - "#this simulate a circuit (without measurement) and output results in the format of histogram.\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", - " 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", - "def count_gates(circuit: qiskit.QuantumCircuit) -> Dict[int, int]:\n", - " \"\"\"Returns the number of gate operations with each number of qubits.\"\"\"\n", - " return Counter([len(gate[1]) for gate in circuit.data])\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)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "#load data\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": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.0\n" - ] - } - ], - "source": [ - "#grade part1\n", - "from part1 import encode_qiskit,decode\n", - "\n", - "n=len(dataset)\n", - "mse=0\n", - "gatecount=0\n", - "\n", - "for data in dataset:\n", - " #encode image into circuit\n", - " circuit=encode_qiskit(data['image'])\n", - " \n", - " #simulate circuit\n", - " histogram=simulate(circuit)\n", - " \n", - " gatecount+=count_gates(circuit)[2]\n", - " \n", - " #reconstruct \n", - " image_re=decode(histogram)\n", - " \n", - " #calculate mse\n", - " mse+=image_mse(np.asarray(data['image']),np.asarray(image_re))\n", - " \n", - "#fidelity of reconstruction\n", - "f=1-mse\n", - "gatecount=gatecount/n\n", - "\n", - "#score for part1\n", - "print(f*(0.999**gatecount))" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.0\n" - ] - } - ], - "source": [ - "#grade part 2\n", - "\n", - "#load classifier circuit\n", - "classifier=qiskit.QuantumCircuit.from_qasm_file('part2.qasm')\n", - " \n", - "score=0\n", - "\n", - "for data in dataset:\n", - " #encode image into circuit\n", - " circuit=encode_qiskit(data['image'])\n", - " \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", - " gatecount+=count_gates(qc)[2]\n", - " \n", - " #simulate circuit\n", - " histogram=simulate(qc)\n", - " \n", - " #convert histogram to category\n", - " cat=histogram_to_category(histogram)\n", - " \n", - " \n", - " if cat==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": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.15" - }, - "orig_nbformat": 4, - "vscode": { - "interpreter": { - "hash": "397704579725e15f5c7cb49fe5f0341eb7531c82d19f2c29d197e8b64ab5776b" - } - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/mock_data_creator.ipynb b/mock_data_creator.ipynb deleted file mode 100644 index 78ad064..0000000 --- a/mock_data_creator.ipynb +++ /dev/null @@ -1,79 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "edbfcaa1", - "metadata": {}, - "outputs": [], - "source": [ - "import cirq\n", - "import numpy as np\n", - "import pickle\n", - "import json" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "3d1a8015", - "metadata": {}, - "outputs": [], - "source": [ - "#making mock data data1.json and data2.json\n", - "\n", - "image1={\"image\":[[0,0],[0,0]],\"category\":1}\n", - "image2={\"image\":[[1,1],[1,1]],\"category\":0}\n", - "\n", - "with open('data1.json', \"w\") as outfile:\n", - " json.dump(image1, outfile)\n", - " \n", - "with open('data2.json', \"w\") as outfile:\n", - " json.dump(image2, outfile)" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "d36c16ef", - "metadata": {}, - "outputs": [], - "source": [ - "circuit=cirq.Circuit()\n", - "circuit.append(cirq.rx(np.pi).on(cirq.LineQubit(0)))\n", - "#making mock submission for part2\n", - "with open('part2.pickle', 'wb') as f:\n", - " pickle.dump(circuit,f)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "55574177", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.8.0" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/part1.py b/part1.py deleted file mode 100644 index d133097..0000000 --- a/part1.py +++ /dev/null @@ -1,25 +0,0 @@ -import cirq -import qiskit -import numpy as np - - -def encode_cirq(image): - circuit=cirq.Circuit() - if image[0][0]==0: - circuit.append(cirq.rx(np.pi).on(cirq.LineQubit(0))) - return circuit - -def encode_qiskit(image): - q = qiskit.QuantumRegister(3) - circuit = qiskit.QuantumCircuit(q) - if image[0][0]==0: - circuit.rx(np.pi,0) - return circuit - - -def decode(histogram): - if 1 in histogram.keys(): - image=[[0,0],[0,0]] - else: - image=[[1,1],[1,1]] - return image \ No newline at end of file diff --git a/part1_example_cirq.ipynb b/part1_example_cirq.ipynb deleted file mode 100644 index c3d383b..0000000 --- a/part1_example_cirq.ipynb +++ /dev/null @@ -1,226 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 8, - "id": "9c97e0dc", - "metadata": {}, - "outputs": [], - "source": [ - "import cirq\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", - "\n", - "#define utility functions\n", - "\n", - "def simulate(circuit: cirq.Circuit) -> dict:\n", - " \"\"\"This funcion simulate a cirq circuit (without measurement) and output results in the format of histogram.\n", - " \"\"\"\n", - " simulator = cirq.Simulator()\n", - " result = simulator.simulate(circuit)\n", - " \n", - " state_vector=result.final_state_vector\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", - "def count_gates(circuit: cirq.Circuit):\n", - " \"\"\"Returns the number of 1-qubit gates, number of 2-qubit gates, number of 3-qubit gates....\"\"\"\n", - " counter=Counter([len(op.qubits) for op in circuit.all_operations()])\n", - " \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", - "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)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "7f19ddcc", - "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": 6, - "id": "a443b6a8", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAej0lEQVR4nO3dfXCU9d3v8c9uHpYEksUQ8lQCDajQCsS7VFJGpVhygHTGAeX0+HRmwOOB0QanSK2edFTUdia9cY51dFL8p4U6Iz7NCBy9O/QomDC2QG9QhmFqcxMaJdyQINgkJJBkk/2dPzhuuxK0v2WTb7K8XzPXDNm9Prm+XFzw4cpufgk455wAABhmQesBAABXJgoIAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJtKtB/iiaDSqEydOKCcnR4FAwHocAIAn55zOnj2rkpISBYOXvs8ZcQV04sQJlZaWWo8BALhMLS0tmjRp0iWf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T8/29aXJ/QoXAF4w4IAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYIICAgCYoIAAACYoIACACRYjxYjXHsn2zpSmf5bQsW7IbfbO/PlcSULH8jUuvdc7E4mmJXSsnmiGdybnr13eGeedQCrhDggAYIICAgCYoIAAACYoIACACQoIAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJFiPFiPf+J1O9M3fk70voWH/rH+uduX7sMe9MIot9JiLiEvsrfrp/nHcmeD7inRnwTiCVcAcEADBBAQEATHgX0O7du3XrrbeqpKREgUBA27Zti3veOacnnnhCxcXFysrKUmVlpY4cOZKseQEAKcK7gLq7u1VeXq66urpBn9+wYYOef/55vfjii9q3b5/Gjh2rxYsXq6en57KHBQCkDu9XKKuqqlRVVTXoc845Pffcc3rssce0dOlSSdJLL72kwsJCbdu2TXfeeeflTQsASBlJfQ2oublZra2tqqysjD0WDodVUVGhPXv2DJrp7e1VZ2dn3AYASH1JLaDW1lZJUmFhYdzjhYWFsee+qLa2VuFwOLaVlpYmcyQAwAhl/i64mpoadXR0xLaWlhbrkQAAwyCpBVRUVCRJamtri3u8ra0t9twXhUIh5ebmxm0AgNSX1AIqKytTUVGRdu7cGXuss7NT+/bt07x585J5KADAKOf9Lriuri41NTXFPm5ubtbBgweVl5enyZMna+3atfr5z3+ua665RmVlZXr88cdVUlKiZcuWJXNuAMAo511A+/fv1y233BL7eN26dZKkFStWaPPmzXrkkUfU3d2t1atXq729XTfddJN27NihMWPGJG9qAMCo511ACxYskHPuks8HAgE9/fTTevrppy9rMOBzkR7/BTV7XGKLfUZcmndmwA3Pe3kyAv5Ld44J+i8QKkklGX/zzuzLuj6hY+HKZf4uOADAlYkCAgCYoIAAACYoIACACQoIAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYMJ/mWFgmP2Xb3zknfm0P7GfrJvIathtkbB3piTTf7XpMQH/la1bInneGUnKC3V5Z9qe8F+tu2C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SWlmY9XtJFo1GtXbtWN954o2bOnCnpwvWQmZmp8ePHx+2bytfDYOdBku6++25NmTJFJSUlOnTokB599FE1NjbqzTffNJw23ogvIPxdVVVV7NezZ89WRUWFpkyZotdff1333Xef4WQYCe68887Yr2fNmqXZs2dr2rRpqq+v18KFCw0nGxrV1dU6fPjwFfE66Je51HlYvXp17NezZs1ScXGxFi5cqKNHj2ratGnDPeagRvyX4PLz85WWlnbRu1ja2tpUVFRkNNXIMH78eF177bVqamqyHsXM59cA18fFpk6dqvz8/JS8PtasWaO3335b7733XtyPbykqKlJfX5/a29vj9k/V6+FS52EwFRUVkjSirocRX0CZmZmaM2eOdu7cGXssGo1q586dmjdvnuFk9rq6unT06FEVFxdbj2KmrKxMRUVFcddHZ2en9u3bd8VfH8ePH9eZM2dS6vpwzmnNmjXaunWrdu3apbKysrjn58yZo4yMjLjrobGxUceOHUup6+GrzsNgDh48KEkj63qwfhfEP+PVV191oVDIbd682f35z392q1evduPHj3etra3Wow2rH//4x66+vt41Nze7P/zhD66ystLl5+e7U6dOWY82pM6ePes+/PBD9+GHHzpJ7tlnn3Uffvih++STT5xzzv3iF79w48ePd9u3b3eHDh1yS5cudWVlZe78+fPGkyfXl52Hs2fPuocfftjt2bPHNTc3u3fffdd961vfctdcc43r6emxHj1pHnjgARcOh119fb07efJkbDt37lxsn/vvv99NnjzZ7dq1y+3fv9/NmzfPzZs3z3Dq5Puq89DU1OSefvppt3//ftfc3Oy2b9/upk6d6ubPn288ebxRUUDOOffCCy+4yZMnu8zMTDd37ly3d+9e65GG3R133OGKi4tdZmam+9rXvubuuOMO19TUZD3WkHvvvfecpIu2FStWOOcuvBX78ccfd4WFhS4UCrmFCxe6xsZG26GHwJedh3PnzrlFixa5iRMnuoyMDDdlyhS3atWqlPtP2mC/f0lu06ZNsX3Onz/vfvjDH7qrrrrKZWdnu9tuu82dPHnSbugh8FXn4dixY27+/PkuLy/PhUIhd/XVV7uf/OQnrqOjw3bwL+DHMQAATIz414AAAKmJAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYIICAgCYoIAAACYoIACAif8H8OZooPKJKDYAAAAASUVORK5CYII=\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "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": 12, - "id": "cb2031cd", - "metadata": {}, - "outputs": [], - "source": [ - "#submission to part 1, you should make this into a .py file\n", - "\n", - "n=len(dataset)\n", - "mse=0\n", - "gatecount=0\n", - "\n", - "def encode(image):\n", - " circuit=cirq.Circuit()\n", - " if image[0][0]==0:\n", - " circuit.append(cirq.rx(np.pi).on(cirq.LineQubit(0)))\n", - " return circuit\n", - "\n", - "def decode(histogram):\n", - " if 1 in histogram.keys():\n", - " image=[[0,0],[0,0]]\n", - " else:\n", - " image=[[1,1],[1,1]]\n", - " return image\n", - "\n", - "def run_part1(image):\n", - " #encode image into a circuit\n", - " circuit=encode(data['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": 13, - "id": "385faa44", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.0\n" - ] - } - ], - "source": [ - "#how we grade your submission\n", - "\n", - "n=len(dataset)\n", - "mse=0\n", - "gatecount=0\n", - "\n", - "for data in dataset:\n", - " #encode image into circuit\n", - " circuit,image_re=run_part1(data['image'])\n", - " \n", - " #count the number of 2qubit gates used\n", - " gatecount+=count_gates(circuit)[2]\n", - " \n", - " #calculate mse\n", - " mse+=image_mse(data['image'],image_re)\n", - " \n", - "#fidelity of reconstruction\n", - "f=1-mse\n", - "gatecount=gatecount/n\n", - "\n", - "#score for part1 \n", - "print(f*(0.999**gatecount))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ad7e81d7", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.8.0" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/part1_example_qiskit.ipynb b/part1_example_qiskit.ipynb deleted file mode 100644 index 90b2c18..0000000 --- a/part1_example_qiskit.ipynb +++ /dev/null @@ -1,234 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "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", - "\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\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": 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/f3N3Abj0dbW7AQDzg7ADSRB2IAnCDiRB2IEkuufzwXqtzxd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7ufu6CveXne+LoskAQf0AFJEHYgCcIOJEHYgSQIO5AEYQeSIOxAEv8PE4DsMh8Hn6sAAAAASUVORK5CYII=", - "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", - "plt.imshow(images[1100])" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "#submission to part 1, you should make this into a .py file\n", - "\n", - "n=len(dataset)\n", - "mse=0\n", - "gatecount=0\n", - "\n", - "# Functions 'encode' and 'decode' are dummy.\n", - "def encode(image):\n", - " q = qiskit.QuantumRegister(3)\n", - " circuit = qiskit.QuantumCircuit(q)\n", - " if image[0][0]==0:\n", - " circuit.rx(np.pi,0)\n", - " return circuit\n", - "\n", - "def decode(histogram):\n", - " if 1 in histogram.keys():\n", - " image=[[0,0],[0,0]]\n", - " else:\n", - " image=[[1,1],[1,1]]\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": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.0\n" - ] - } - ], - "source": [ - "#how we grade your submission\n", - "\n", - "n=len(dataset)\n", - "mse=0\n", - "gatecount=0\n", - "\n", - "for data in dataset:\n", - " #encode image into circuit\n", - " circuit,image_re=run_part1(data['image'])\n", - " \n", - " #count the number of 2qubit gates used\n", - " gatecount+=count_gates(circuit)[2]\n", - " \n", - " #calculate mse\n", - " mse+=image_mse(data['image'],image_re)\n", - " \n", - "#fidelity of reconstruction\n", - "f=1-mse\n", - "gatecount=gatecount/n\n", - "\n", - "#score for part1 \n", - "print(f*(0.999**gatecount))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.15 (main, Oct 11 2022, 22:27:25) \n[Clang 14.0.0 (clang-1400.0.29.102)]" - }, - "orig_nbformat": 4, - "vscode": { - "interpreter": { - "hash": "397704579725e15f5c7cb49fe5f0341eb7531c82d19f2c29d197e8b64ab5776b" - } - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/part2.pickle b/part2.pickle deleted file mode 100644 index 3065aa7..0000000 Binary files a/part2.pickle and /dev/null differ diff --git a/part2.qasm b/part2.qasm deleted file mode 100644 index bad476c..0000000 --- a/part2.qasm +++ /dev/null @@ -1,4 +0,0 @@ -OPENQASM 2.0; -include "qelib1.inc"; -qreg q8[3]; -rx(pi) q8[0]; diff --git a/part2_example_cirq.ipynb b/part2_example_cirq.ipynb deleted file mode 100644 index 2bb7a6d..0000000 --- a/part2_example_cirq.ipynb +++ /dev/null @@ -1,221 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 2, - "id": "5519a2aa", - "metadata": {}, - "outputs": [], - "source": [ - "import cirq\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", - "\n", - "#define utility functions\n", - "\n", - "def simulate(circuit: cirq.Circuit) -> dict:\n", - " \"\"\"This funcion simulate a cirq circuit (without measurement) and output results in the format of histogram.\n", - " \"\"\"\n", - " simulator = cirq.Simulator()\n", - " result = simulator.simulate(circuit)\n", - " \n", - " state_vector=result.final_state_vector\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", - "def count_gates(circuit: cirq.Circuit):\n", - " \"\"\"Returns the number of 1-qubit gates, number of 2-qubit gates, number of 3-qubit gates....\"\"\"\n", - " counter=Counter([len(op.qubits) for op in circuit.all_operations()])\n", - " \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" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "11a77286", - "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": 5, - "id": "dfbb6735", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAej0lEQVR4nO3dfXCU9d3v8c9uHpYEksUQ8lQCDajQCsS7VFJGpVhygHTGAeX0+HRmwOOB0QanSK2edFTUdia9cY51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EBAEwM+Q+kA/7R+JXd3pn2P2R5Z8YEI94ZSerq9//hiFOz/BdY/ai7xDuTHvRfKHU4F2X9j48meWeukf8Cpkgd3AEBAExQQAAAExQQAMAEBQQAMEEBAQBMUEAAABMUEADABAUEADBBAQEATFBAAAATFBAAwAQFBAAwQQEBAEywGjaGVX9rm3fmd+3l3pmbc//DOyNJ//aZ/7FOR3K8M1OyTntnWnvD3pmoC3hnLuT8/29aXJ/QoXAF4w4IAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYIICAgCYoIAAACYoIACACRYjxYjXHsn2zpSmf5bQsW7IbfbO/PlcSULH8jUuvdc7E4mmJXSsnmiGdybnr13eGeedQCrhDggAYIICAgCYoIAAACYoIACACQoIAGCCAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJFiPFiPf+J1O9M3fk70voWH/rH+uduX7sMe9MIot9JiLiEvsrfrp/nHcmeD7inRnwTiCVcAcEADBBAQEATHgX0O7du3XrrbeqpKREgUBA27Zti3veOacnnnhCxcXFysrKUmVlpY4cOZKseQEAKcK7gLq7u1VeXq66urpBn9+wYYOef/55vfjii9q3b5/Gjh2rxYsXq6en57KHBQCkDu9XKKuqqlRVVTXoc845Pffcc3rssce0dOlSSdJLL72kwsJCbdu2TXfeeeflTQsASBlJfQ2oublZra2tqqysjD0WDodVUVGhPXv2DJrp7e1VZ2dn3AYASH1JLaDW1lZJUmFhYdzjhYWFsee+qLa2VuFwOLaVlpYmcyQAwAhl/i64mpoadXR0xLaWlhbrkQAAwyCpBVRUVCRJamtri3u8ra0t9twXhUIh5ebmxm0AgNSX1AIqKytTUVGRdu7cGXuss7NT+/bt07x585J5KADAKOf9Lriuri41NTXFPm5ubtbBgweVl5enyZMna+3atfr5z3+ua665RmVlZXr88cdVUlKiZcuWJXNuAMAo511A+/fv1y233BL7eN26dZKkFStWaPPmzXrkkUfU3d2t1atXq729XTfddJN27NihMWPGJG9qAMCo511ACxYskHPuks8HAg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VQUKDp06frgQce0JkzZ6xHGlIdHR2SpLy8PEnSgQMHFIlE4q6HGTNmaPLkySl9PXzxPHzu5ZdfVn5+vmbOnKmamhqdO3fOYrxLGnGLkX7R6dOnNTAwoMLCwrjHCwsL9Ze//MVoKhsVFRXavHmzpk+frpMnT+qpp57SzTffrMOHDysnJ8d6PBOtra2SNOj18flzV4olS5bo9ttvV1lZmY4ePaqf/vSnqqqq0p49e5SWlmY9XtJFo1GtXbtWN954o2bOnCnpwvWQmZmp8ePHx+2bytfDYOdBku6++25NmTJFJSUlOnTokB599FE1NjbqzTffNJw23ogvIPxdVVVV7NezZ89WRUWFpkyZotdff1333Xef4WQYCe68887Yr2fNmqXZs2dr2rRpqq+v18KFCw0nGxrV1dU6fPjwFfE66Je51HlYvXp17NezZs1ScXGxFi5cqKNHj2ratGnDPeagRvyX4PLz85WWlnbRu1ja2tpUVFRkNNXIMH78eF177bVqamqyHsXM59cA18fFpk6dqvz8/JS8PtasWaO3335b7733XtyPbykqKlJfX5/a29vj9k/V6+FS52EwFRUVkjSirocRX0CZmZmaM2eOdu7cGXssGo1q586dmjdvnuFk9rq6unT06FEVFxdbj2KmrKxMRUVFcddHZ2en9u3bd8VfH8ePH9eZM2dS6vpwzmnNmjXaunWrdu3apbKysrjn58yZo4yMjLjrobGxUceOHUup6+GrzsNgDh48KEkj63qwfhfEP+PVV191oVDIbd682f35z392q1evduPHj3etra3Wow2rH//4x66+vt41Nze7P/zhD66ystLl5+e7U6dOWY82pM6ePes+/PBD9+GHHzpJ7tlnn3Uffvih++STT5xzzv3iF79w48ePd9u3b3eHDh1yS5cudWVlZe78+fPGkyfXl52Hs2fPuocfftjt2bPHNTc3u3fffdd961vfctdcc43r6emxHj1pHnjgARcOh119fb07efJkbDt37lxsn/vvv99NnjzZ7dq1y+3fv9/NmzfPzZs3z3Dq5Puq89DU1OSefvppt3//ftfc3Oy2b9/upk6d6ubPn288ebxRUUDOOffCCy+4yZMnu8zMTDd37ly3d+9e65GG3R133OGKi4tdZmam+9rXvubuuOMO19TUZD3WkHvvvfecpIu2FStWOOcuvBX78ccfd4WFhS4UCrmFCxe6xsZG26GHwJedh3PnzrlFixa5iRMnuoyMDDdlyhS3atWqlPtP2mC/f0lu06ZNsX3Onz/vfvjDH7qrrrrKZWdnu9tuu82dPHnSbugh8FXn4dixY27+/PkuLy/PhUIhd/XVV7uf/OQnrqOjw3bwL+DHMQAATIz414AAAKmJAgIAmKCAAAAmKCAAgAkKCABgggICAJiggAAAJiggAIAJCggAYIICAgCYoIAAACYoIACAif8H8OZooPKJKDYAAAAASUVORK5CYII=\n", - "text/plain": [ - "
" - ] - }, - "metadata": {}, - "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": 9, - "id": "66e9a047", - "metadata": {}, - "outputs": [], - "source": [ - "#you submission\n", - "\n", - "def encode(image):\n", - " circuit=cirq.Circuit()\n", - " if image[0][0]==0:\n", - " circuit.append(cirq.rx(np.pi).on(cirq.LineQubit(0)))\n", - " return circuit\n", - "\n", - "\n", - "def run_part2(image):\n", - "\n", - " #loade the quantum classifier circuit\n", - " with open('part2.pickle', 'rb') as f:\n", - " classifier=pickle.load(f)\n", - " \n", - " #encode image into circuit\n", - " circuit=encode(image)\n", - " \n", - " #append with classifier circuit\n", - " \n", - " circuit.append(classifier)\n", - " \n", - " #simulate circuit\n", - " histogram=simulate(circuit)\n", - " \n", - " #convert histogram to category\n", - " label=histogram_to_category(histogram)\n", - " \n", - " return circuit,label\n", - "#score" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "18e6015f", - "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": null, - "id": "a73d2810", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.8.0" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/part2_example_qiskit.ipynb b/part2_example_qiskit.ipynb deleted file mode 100644 index 8b48841..0000000 --- a/part2_example_qiskit.ipynb +++ /dev/null @@ -1,230 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "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", - "\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/f3N3Abj0dbW7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7q7e8lvSHpdU0Ha1WbertN0y/RX5e0rfZzd7ufu6CveXne+LoskAQf0AFJEHYgCcIOJEHYgSQIO5AEYQeSIOxAEv8PE4DsMh8Hn6sAAAAASUVORK5CYII=", - "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", - " q = qiskit.QuantumRegister(3)\n", - " circuit = qiskit.QuantumCircuit(q)\n", - " if image[0][0]==0:\n", - " circuit.rx(np.pi,0)\n", - " return circuit\n", - "\n", - "\n", - "def run_part2(image):\n", - "\n", - " #loade the quantum classifier circuit\n", - " classifier=qiskit.QuantumCircuit.from_qasm_file('part2.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", - " return circuit,label\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": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.15" - }, - "orig_nbformat": 4, - "vscode": { - "interpreter": { - "hash": "397704579725e15f5c7cb49fe5f0341eb7531c82d19f2c29d197e8b64ab5776b" - } - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/quantum_classifier.qasm b/quantum_classifier.qasm new file mode 100644 index 0000000..d7c0947 --- /dev/null +++ b/quantum_classifier.qasm @@ -0,0 +1,5 @@ +OPENQASM 2.0; +include "qelib1.inc"; +gate gate_RealAmplitudes(param0,param1,param2,param3,param4,param5,param6,param7,param8,param9,param10,param11,param12,param13,param14,param15,param16,param17,param18,param19,param20,param21,param22,param23) q0,q1,q2,q3 { ry(0.555621819228932) q0; ry(1.14319132801287) q1; ry(1.07379590145389) q2; ry(0.409370781763752) q3; cx q2,q3; cx q1,q2; cx q0,q1; ry(0.0165973010020706) q0; ry(0.508652978720279) q1; ry(0.300244419920286) q2; ry(0.136434104028988) q3; cx q2,q3; cx q1,q2; cx q0,q1; ry(-0.0649716942665253) q0; ry(0.577026156276957) q1; ry(0.13664098460932) q2; ry(1.24139060584453) q3; cx q2,q3; cx q1,q2; cx q0,q1; ry(0.455662122094092) q0; ry(0.642944089110158) q1; ry(0.570141938819558) q2; ry(0.0393162465417179) q3; cx q2,q3; cx q1,q2; cx q0,q1; ry(0.872843078509701) q0; ry(0.497896034397818) q1; ry(0.792675492672247) q2; ry(0.0302332873841969) q3; cx q2,q3; cx q1,q2; cx q0,q1; ry(0.448717981940666) q0; ry(1.52403189005694) q1; ry(0.877796397476269) q2; ry(0.508643300858681) q3; } +qreg q[4]; +gate_RealAmplitudes(0.555621819228932,1.14319132801287,1.07379590145389,0.409370781763752,0.0165973010020706,0.508652978720279,0.300244419920286,0.136434104028988,-0.0649716942665253,0.577026156276957,0.13664098460932,1.24139060584453,0.455662122094092,0.642944089110158,0.570141938819558,0.0393162465417179,0.872843078509701,0.497896034397818,0.792675492672247,0.0302332873841969,0.448717981940666,1.52403189005694,0.877796397476269,0.508643300858681) q[0],q[1],q[2],q[3]; diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..678658c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,367 @@ +absl-py==1.4.0 +aiofile==3.8.1 +aiohttp==3.8.3 +aiosignal==1.3.1 +alembic @ file:///home/conda/feedstock_root/build_artifacts/alembic_1647367721563/work +amazon-braket-default-simulator==1.11.4 +amazon-braket-ocean-plugin==1.0.11 +amazon-braket-pennylane-plugin==1.10.4 +amazon-braket-schemas==1.14.0 +amazon-braket-sdk==1.35.3 +antlr4-python3-runtime==4.9.2 +anyio==3.6.2 +appdirs==1.4.4 +appnope==0.1.3 +argcomplete==2.0.0 +argon2-cffi==21.3.0 +argon2-cffi-bindings==21.2.0 +asttokens @ file:///home/conda/feedstock_root/build_artifacts/asttokens_1618968359944/work +astunparse==1.6.3 +async-generator==1.10 +async-timeout==4.0.2 +attrs==20.3.0 +autograd==1.5 +autoray==0.6.0 +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==0.2.0 +backoff==2.2.1 +backports.functools-lru-cache @ file:///home/conda/feedstock_root/build_artifacts/backports.functools_lru_cache_1618230623929/work +beautifulsoup4==4.11.1 +bleach==6.0.0 +blinker==1.4 +bokeh==3.0.3 +boltons==21.0.0 +boto3==1.26.57 +botocore==1.29.57 +brotlipy @ file:///home/conda/feedstock_root/build_artifacts/brotlipy_1636012194889/work +cached-property==1.5.2 +cachetools==4.2.4 +caio==0.9.11 +certifi==2022.12.7 +certipy==0.1.3 +cffi==1.15.1 +chardet==3.0.4 +charset-normalizer==3.0.1 +cirq==1.1.0 +cirq-aqt==1.1.0 +cirq-core==1.1.0 +cirq-google==1.1.0 +cirq-ionq==1.1.0 +cirq-pasqal==1.1.0 +cirq-rigetti==1.1.0 +cirq-web==1.1.0 +click==8.1.3 +code-snippets @ file:///tmp/qbraid/wheels/code_snippets-0.1.2-py3-none-any.whl +colorama==0.4.6 +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==39.0.0 +cycler==0.11.0 +Cython==0.29.33 +debugpy==1.6.6 +decorator==5.1.1 +defusedxml==0.7.1 +Deprecated==1.2.13 +deprecation==2.1.0 +dill==0.3.5.1 +dimod==0.12.3 +diskcache==5.4.0 +dlx==1.0.4 +docplex==2.25.236 +docs-react-widget @ file:///tmp/qbraid/wheels/docs_react_widget-0.1.0-py3-none-any.whl +docutils==0.16 +duet==0.2.7 +dwave-cloud-client==0.10.4 +dwave-greedy==0.3.0 +dwave-hybrid==0.6.10 +dwave-inspector==0.4.0 +dwave-neal==0.6.0 +dwave-networkx==0.8.13 +dwave-ocean-sdk==6.2.0 +dwave-preprocessing==0.5.4 +dwave-samplers==1.0.0 +dwave-system==1.18.0 +dwave-tabu==0.5.0 +dwavebinarycsp==0.2.0 +entrypoints==0.4 +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 +fastdtw==0.3.4 +fasteners==0.18 +fastjsonschema==2.16.2 +Flask==2.2.2 +flatbuffers==23.1.21 +flit_core @ file:///home/conda/feedstock_root/build_artifacts/flit-core_1645629044586/work/source/flit_core +fonttools==4.38.0 +frozendict==2.3.4 +frozenlist==1.3.3 +future==0.18.3 +gast==0.4.0 +gitdb==4.0.10 +GitPython==3.1.30 +google-api-core==1.34.0 +google-api-python-client==2.31.0 +google-auth==2.16.0 +google-auth-httplib2==0.1.0 +google-auth-oauthlib==0.4.6 +google-pasta==0.2.0 +googleapis-common-protos==1.58.0 +graphviz==0.20.1 +greenlet @ file:///home/conda/feedstock_root/build_artifacts/greenlet_1635836790477/work +grpcio==1.51.1 +grpcio-status==1.48.2 +h11==0.14.0 +h5py==3.2.1 +homebase==1.0.1 +html5lib==1.1 +httpcore==0.16.3 +httplib2==0.21.0 +httpx==0.23.3 +ibm-cloud-sdk-core==3.16.1 +ibm-platform-services==0.31.0 +idna==2.8 +imageio==2.25.0 +importlib-metadata==6.0.0 +importlib-resources @ file:///home/conda/feedstock_root/build_artifacts/importlib_resources_1635615662634/work +inflection==0.5.1 +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 +iso8601==1.1.0 +isodate==0.6.1 +itsdangerous==2.1.2 +jedi @ file:///home/conda/feedstock_root/build_artifacts/jedi_1637175083648/work +Jinja2==3.1.2 +jmespath==1.0.1 +joblib==1.2.0 +json5 @ file:///home/conda/feedstock_root/build_artifacts/json5_1600692310011/work +jsonref==1.1.0 +jsonschema==4.17.3 +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 +keras==2.11.0 +keras-nightly==2.12.0.dev2023012508 +Keras-Preprocessing==1.1.2 +kiwisolver==1.4.4 +lab-main-menu @ file:///tmp/qbraid/wheels/lab_main_menu-0.1.1-py3-none-any.whl +lark==0.11.3 +lark-parser==0.12.0 +libclang==15.0.6.1 +libmambapy @ file:///home/conda/feedstock_root/build_artifacts/mamba-split_1644831758535/work/libmambapy +lxml==4.9.2 +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==2.1.2 +matplotlib==3.6.0 +matplotlib-inline @ file:///home/conda/feedstock_root/build_artifacts/matplotlib-inline_1631080358261/work +minorminer==0.2.10 +mistune==2.0.4 +more-itertools==9.0.0 +mpltools==0.2.0 +mpmath==1.2.1 +msal==1.20.0 +msal-extensions==1.0.0 +msgpack==0.6.2 +msrest==0.7.1 +mthree==1.1.0 +multidict==6.0.4 +multitasking==0.0.11 +mypy-extensions==0.4.3 +Nasdaq-Data-Link==1.0.4 +nbclassic==0.4.8 +nbclient==0.7.2 +nbconvert==7.2.9 +nbdime==3.1.1 +nbformat==5.7.3 +nest-asyncio==1.5.6 +networkx==2.8.8 +ninja==1.11.1 +notebook==6.5.2 +notebook-shim @ file:///home/conda/feedstock_root/build_artifacts/notebook-shim_1646330736330/work +ntlm-auth==1.5.0 +numpy==1.21.6 +nvidia-cublas-cu11==11.10.3.66 +nvidia-cuda-nvrtc-cu11==11.7.99 +nvidia-cuda-runtime-cu11==11.7.99 +nvidia-cudnn-cu11==8.5.0.96 +oauth2client==4.1.3 +oauthlib==3.2.2 +opencv-python==4.7.0.68 +openfermion==1.5.1 +openpulse==0.4.1 +openqasm3==0.4.0 +opt-einsum==3.3.0 +oqpy==0.1.2 +orjson==3.8.5 +packaging==23.0 +pamela==1.0.0 +pandas==1.5.3 +pandocfilters==1.5.0 +parso==0.8.3 +pbr==5.11.1 +penaltymodel==1.0.2 +PennyLane==0.27.0 +PennyLane-Cirq==0.28.0 +PennyLane-Lightning==0.28.0 +PennyLane-qiskit==0.28.0 +pexpect==4.8.0 +pickleshare==0.7.5 +Pillow==9.4.0 +platformdirs==2.6.2 +plucky==0.4.3 +ply==3.11 +portalocker==2.7.0 +prometheus-client==0.16.0 +prompt-toolkit==3.0.36 +proto-plus==1.22.2 +protobuf==3.19.6 +psutil==5.9.4 +ptyprocess==0.7.0 +PubChemPy==1.0.4 +pure-eval @ file:///home/conda/feedstock_root/build_artifacts/pure_eval_1642875951954/work +py==1.11.0 +pyasn1==0.4.8 +pyasn1-modules==0.2.8 +pybind11==2.10.3 +pycosat @ file:///home/conda/feedstock_root/build_artifacts/pycosat_1636020362356/work +pycparser==2.21 +pycurl==7.45.1 +pydantic==1.10.4 +Pygments==2.14.0 +PyJWT==2.6.0 +pylatexenc==2.10 +pyOpenSSL @ file:///home/conda/feedstock_root/build_artifacts/pyopenssl_1643496850550/work +pyparsing==3.0.9 +pyqir-generator==0.4.2a1 +pyqubo==1.4.0 +pyquil==3.3.2 +pyrsistent==0.19.3 +pyscf==2.1.1 +PySocks==1.7.1 +python-constraint==1.4.0 +python-dateutil==2.8.2 +python-json-logger @ file:///home/conda/feedstock_root/build_artifacts/python-json-logger_1602545356084/work +python-markdown-math==0.8 +python-rapidjson==1.9 +pytket==1.11.1 +pytket-cirq==0.28.0 +pytket-qiskit==0.34.0 +pytz==2022.7.1 +PyYAML==5.4.1 +pyzmq==25.0.0 +qcs-api-client==0.21.2 +qdk @ file:///home/vsts_azpcontainer/conda-bld/qsharp_1670279498240/work/src/drops/wheels/qdk-0.27.244707-py3-none-any.whl +qickstart-graders @ git+https://github.com/TheGupta2012/QickStart.git@65501cc7d5e98506b90e58e43d8d4a2aee551739 +QInfer==1.0 +qiskit==0.39.5 +qiskit-aer==0.11.2 +qiskit-aqua==0.9.5 +qiskit-finance==0.3.4 +qiskit-ibm-runtime==0.8.0 +qiskit-ibmq-provider==0.19.2 +qiskit-ignis==0.7.0 +qiskit-ionq==0.3.10 +qiskit-machine-learning==0.5.0 +qiskit-nature==0.5.2 +qiskit-optimization==0.4.0 +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 +Quandl==3.7.0 +quantum-jobs @ file:///tmp/qbraid/wheels/quantum_jobs-0.1.1-py3-none-any.whl +qutip==4.7.1 +qwasm==1.0.1 +rectangle-packer==2.0.1 +requests==2.28.2 +requests-ntlm==1.1.0 +requests-oauthlib==1.3.1 +retry==0.9.2 +retrying==1.3.4 +retworkx==0.12.1 +rfc3339==6.2 +rfc3986==1.5.0 +rpcq==3.10.0 +rsa==4.9 +ruamel-yaml-conda @ file:///home/conda/feedstock_root/build_artifacts/ruamel_yaml_1636009144459/work +ruamel.yaml==0.17.21 +ruamel.yaml.clib==0.2.7 +rustworkx==0.12.1 +s3transfer==0.6.0 +scikit-learn==1.2.1 +scipy==1.10.0 +seaborn==0.12.2 +semantic-version==2.10.0 +Send2Trash==1.8.0 +six==1.16.0 +smmap==5.0.0 +sniffio==1.3.0 +sortedcontainers==2.4.0 +soupsieve==2.3.2.post1 +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 +tensorboard==2.11.2 +tensorboard-data-server==0.6.1 +tensorboard-plugin-wit==1.8.1 +tensorflow==2.11.0 +tensorflow-estimator==2.11.0 +tensorflow-io-gcs-filesystem==0.30.0 +termcolor==2.2.0 +terminado==0.17.1 +testpath==0.6.0 +threadpoolctl==3.1.0 +tinycss2==1.2.1 +toml==0.10.2 +tomli==2.0.1 +torch==1.13.1 +tornado==6.2 +tqdm==4.64.1 +traitlets==5.8.1 +tweedledum==1.1.1 +types-Jinja2==2.11.9 +types-MarkupSafe==1.1.10 +types-pkg-resources==0.1.3 +types-python-dateutil==2.8.19.6 +types-retry==0.9.9.1 +typing_extensions==4.4.0 +ui-tweaks @ file:///tmp/qbraid/wheels/ui_tweaks-0.1.1-py3-none-any.whl +uritemplate==4.1.1 +urllib3==1.26.14 +wcwidth==0.2.6 +webencodings==0.5.1 +websocket-client==1.3.3 +websockets==10.4 +Werkzeug==2.2.2 +widgetsnbextension==4.0.5 +wrapt==1.14.1 +xyzservices==2022.9.0 +yarl==1.8.2 +yfinance==0.2.6 +zipp==3.11.0 diff --git a/test.ipynb b/test.ipynb new file mode 100644 index 0000000..bf9c8a7 --- /dev/null +++ b/test.ipynb @@ -0,0 +1,328 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 5, + "id": "e2e5bcd9-2cb8-465d-b166-23128574b2c7", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 2000/2000 [00:00<00:00, 23292.31it/s]\n", + "100%|██████████| 10/10 [00:01<00:00, 7.02it/s]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.9379616325363924\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 10/10 [00:01<00:00, 6.84it/s]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.9379616325363924,0.3944362547996004,./data\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "import qiskit\n", + "from qiskit import quantum_info, QuantumCircuit\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", + "import sys\n", + "from collections import Counter\n", + "from sklearn.metrics import mean_squared_error\n", + "from typing import Dict, List\n", + "from sklearn.decomposition import PCA\n", + "import tqdm\n", + "\n", + "\n", + "import matplotlib.pyplot as plt\n", + "\n", + "if len(sys.argv) > 1:\n", + " data_path = sys.argv[1]\n", + "else:\n", + " data_path = '.'\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 takes a histogram representation of circuit execution results, and processes 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", + "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(3,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(255*image1,255*image2)\n", + "\n", + "# [normalize]\n", + "def normalize(row):\n", + " #We calculate the squareroot of the sum of the square values of the row\n", + " normalization_factor = np.sqrt(np.sum(row**2)) \n", + " if normalization_factor == 0.:\n", + " #If the sum is zero we return a 0\n", + " return 0.0\n", + " #Else we divide each value between the sum value above\n", + " row = row / normalization_factor\n", + " return row, normalization_factor\n", + "#\n", + "data_path = \"./data\"\n", + "\n", + "def test():\n", + " #load the actual hackthon data (fashion-mnist)\n", + " images=np.load(data_path+'/images.npy')\n", + " labels=np.load(data_path+'/labels.npy')\n", + " \n", + " #test part 1\n", + " global pca, AMPLITUDE_ENCODING_N_QUBITS,IMAGE_SIZE, dataset\n", + "\n", + " AMPLITUDE_ENCODING_N_QUBITS = 4\n", + " IMAGE_SIZE = 28\n", + " N_IMAGES = len(images)\n", + "\n", + " pca = PCA(n_components=2**AMPLITUDE_ENCODING_N_QUBITS)\n", + " \n", + " data = images.reshape(N_IMAGES, IMAGE_SIZE * IMAGE_SIZE)\n", + " pca.fit(data)\n", + " \n", + " # Apply dimensionality reduction on your data\n", + " images_pca = pca.transform(data)\n", + " \n", + " dataset = []\n", + " for i in tqdm.tqdm(range(len(images))):\n", + " image_pca = images_pca[i]\n", + " image_pca_min_ = image_pca.min()\n", + " image_pca_positive = image_pca - image_pca_min_\n", + " \n", + " dataset_i = {}\n", + " \n", + " normalized_state, normalization_factor = normalize(image_pca_positive)\n", + " \n", + " dataset_i[\"image\"] = images[i]\n", + " dataset_i[\"image_vector\"] = normalized_state\n", + " dataset_i[\"label\"] = labels[i]\n", + " dataset_i[\"normalization_factor\"] = normalization_factor\n", + " dataset_i[\"pca_min_\"] = image_pca_min_\n", + " \n", + " dataset.append(dataset_i)\n", + " \n", + " n=len(images)\n", + " mse=0\n", + " gatecount=0\n", + " n = 10 # sanity check to test that code works\n", + " \n", + " for i in tqdm.tqdm(range(n)):\n", + " #encode image into circuit\n", + " circuit,image_re=run_part1(dataset[i][\"image_vector\"])\n", + " image_re = np.asarray(image_re)\n", + "\n", + " #count the number of 2qubit gates used\n", + " gatecount += count_gates(circuit)[2]\n", + "\n", + " #calculate mse\n", + " mse+=image_mse(dataset[i][\"image\"], image_re)\n", + "\n", + " #fidelity of reconstruction\n", + " f=1-mse/n\n", + " gatecount=gatecount/n\n", + "\n", + " #score for part1\n", + " score_part1=f*(0.999**gatecount)\n", + " \n", + " print(score_part1)\n", + "\n", + " #test part 2\n", + " \n", + " score=0\n", + " gatecount=0\n", + " n=len(images)\n", + " \n", + " n = 10\n", + " for i in tqdm.tqdm(range(n)):\n", + " #run part 2\n", + " circuit,label=run_part2(dataset[i * 100][\"image_vector\"])\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==labels[i * 100]:\n", + " score+=1\n", + " \n", + " #score\n", + " score=score/n\n", + " gatecount=gatecount/n\n", + "\n", + " score_part2=score*(0.999**gatecount)\n", + " \n", + " print(score_part1, \",\", score_part2, \",\", data_path, sep=\"\")\n", + "\n", + "\n", + "############################\n", + "# YOUR CODE HERE #\n", + "############################\n", + "def encode(image):\n", + " qc = QuantumCircuit(AMPLITUDE_ENCODING_N_QUBITS)\n", + "\n", + " qc.initialize(image)\n", + " \n", + " for i in range(AMPLITUDE_ENCODING_N_QUBITS + 2):\n", + " qc = qc.decompose()\n", + " \n", + " return qc\n", + "\n", + "def decode(histogram):\n", + " histogram_array = np.zeros(2 ** AMPLITUDE_ENCODING_N_QUBITS)\n", + " for i in range(2 ** AMPLITUDE_ENCODING_N_QUBITS):\n", + " histogram_array[i] = histogram.get(i, 0)\n", + " \n", + " root = np.sqrt(histogram_array)\n", + " \n", + " root = root * dataset[i][\"normalization_factor\"]\n", + " \n", + " root = root + dataset[i][\"pca_min_\"]\n", + "\n", + " reconstruction = pca.inverse_transform([root])\n", + "\n", + " \n", + " image = reconstruction.reshape(IMAGE_SIZE, IMAGE_SIZE)\n", + " \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", + "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", + "############################\n", + "# END YOUR CODE #\n", + "############################\n", + "\n", + "test()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21a93cc3-13b1-40bc-85fa-6e5bfd5ee403", + "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" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/test.py b/test.py new file mode 100644 index 0000000..21d0d05 --- /dev/null +++ b/test.py @@ -0,0 +1,245 @@ +import qiskit +from qiskit import quantum_info, QuantumCircuit +from qiskit.execute_function import execute +from qiskit import BasicAer +import numpy as np +import pickle +import json +import os +import sys +from collections import Counter +from sklearn.metrics import mean_squared_error +from typing import Dict, List +from sklearn.decomposition import PCA +import tqdm + + +import matplotlib.pyplot as plt + +if len(sys.argv) > 1: + data_path = sys.argv[1] +else: + data_path = '.' + +#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 takes a histogram representation of circuit execution results, and processes 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(3,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(255*image1,255*image2) + +# [normalize] +def normalize(row): + #We calculate the squareroot of the sum of the square values of the row + normalization_factor = np.sqrt(np.sum(row**2)) + if normalization_factor == 0.: + #If the sum is zero we return a 0 + return 0.0 + #Else we divide each value between the sum value above + row = row / normalization_factor + return row, normalization_factor + +def test(): + #load the actual hackthon data (fashion-mnist) + images=np.load(data_path+'/images.npy') + labels=np.load(data_path+'/labels.npy') + + #test part 1 + global pca, AMPLITUDE_ENCODING_N_QUBITS,IMAGE_SIZE, dataset + + AMPLITUDE_ENCODING_N_QUBITS = 4 + IMAGE_SIZE = 28 + N_IMAGES = len(images) + + pca = PCA(n_components=2**AMPLITUDE_ENCODING_N_QUBITS) + + data = images.reshape(N_IMAGES, IMAGE_SIZE * IMAGE_SIZE) + pca.fit(data) + + # Apply dimensionality reduction on your data + images_pca = pca.transform(data) + + dataset = [] + for i in tqdm.tqdm(range(len(images))): + image_pca = images_pca[i] + image_pca_min_ = image_pca.min() + image_pca_positive = image_pca - image_pca_min_ + + dataset_i = {} + + normalized_state, normalization_factor = normalize(image_pca_positive) + + dataset_i["image"] = images[i] + dataset_i["image_vector"] = normalized_state + dataset_i["label"] = labels[i] + dataset_i["normalization_factor"] = normalization_factor + dataset_i["pca_min_"] = image_pca_min_ + + dataset.append(dataset_i) + + n=len(images) + mse=0 + gatecount=0 + + for i in tqdm.tqdm(range(n)): + #encode image into circuit + circuit,image_re=run_part1(dataset[i]["image_vector"]) + image_re = np.asarray(image_re) + + #count the number of 2qubit gates used + gatecount += count_gates(circuit)[2] + + #calculate mse + mse+=image_mse(dataset[i]["image"], image_re) + + #fidelity of reconstruction + f=1-mse/n + gatecount=gatecount/n + + #score for part1 + score_part1=f*(0.999**gatecount) + + print(score_part1) + + #test part 2 + + score=0 + gatecount=0 + n=len(images) + + for i in tqdm.tqdm(range(n)): + #run part 2 + circuit,label=run_part2(dataset[i]["image_vector"]) + + #count the gate used in the circuit for score calculation + gatecount+=count_gates(circuit)[2] + + #check label + if label==labels[i]: + score+=1 + + #score + score=score/n + gatecount=gatecount/n + + score_part2=score*(0.999**gatecount) + + print(score_part1, ",", score_part2, ",", data_path, sep="") + + +############################ +# YOUR CODE HERE # +############################ +def encode(image): + qc = QuantumCircuit(AMPLITUDE_ENCODING_N_QUBITS) + + qc.initialize(image) + + for i in range(AMPLITUDE_ENCODING_N_QUBITS + 2): + qc = qc.decompose() + + return qc + +def decode(histogram): + histogram_array = np.zeros(2 ** AMPLITUDE_ENCODING_N_QUBITS) + for i in range(2 ** AMPLITUDE_ENCODING_N_QUBITS): + histogram_array[i] = histogram.get(i, 0) + + root = np.sqrt(histogram_array) + + root = root * dataset[i]["normalization_factor"] + + root = root + dataset[i]["pca_min_"] + + reconstruction = pca.inverse_transform([root]) + + + image = reconstruction.reshape(IMAGE_SIZE, IMAGE_SIZE) + + 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) + + #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 + +############################ +# END YOUR CODE # +############################ + +test() \ No newline at end of file diff --git a/train_classifier.ipynb b/train_classifier.ipynb new file mode 100644 index 0000000..6743ceb --- /dev/null +++ b/train_classifier.ipynb @@ -0,0 +1,2694 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "code", + "source": [ + "pip install qiskit" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "3PB9KaTr2CIt", + "outputId": "5288d69d-2245-41cc-ead0-1f0219092a17" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", + "Collecting qiskit\n", + " Downloading qiskit-0.40.0.tar.gz (14 kB)\n", + " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + "Collecting qiskit-terra==0.23.0\n", + " Downloading qiskit_terra-0.23.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.1 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.1/5.1 MB\u001b[0m \u001b[31m67.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting qiskit-aer==0.11.2\n", + " Downloading qiskit_aer-0.11.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.8 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.8/12.8 MB\u001b[0m \u001b[31m77.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting qiskit-ibmq-provider==0.19.2\n", + " Downloading qiskit_ibmq_provider-0.19.2-py3-none-any.whl (240 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m240.4/240.4 KB\u001b[0m \u001b[31m29.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: numpy>=1.16.3 in /usr/local/lib/python3.8/dist-packages (from qiskit-aer==0.11.2->qiskit) (1.21.6)\n", + "Requirement already satisfied: scipy>=1.0 in /usr/local/lib/python3.8/dist-packages (from qiskit-aer==0.11.2->qiskit) (1.7.3)\n", + "Collecting websocket-client>=1.0.1\n", + " Downloading websocket_client-1.5.0-py3-none-any.whl (55 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m55.9/55.9 KB\u001b[0m \u001b[31m8.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting websockets>=10.0\n", + " Downloading websockets-10.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (106 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m107.0/107.0 KB\u001b[0m \u001b[31m15.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: urllib3>=1.21.1 in /usr/local/lib/python3.8/dist-packages (from qiskit-ibmq-provider==0.19.2->qiskit) (1.24.3)\n", + "Collecting requests-ntlm>=1.1.0\n", + " Downloading requests_ntlm-1.1.0-py2.py3-none-any.whl (5.7 kB)\n", + "Requirement already satisfied: python-dateutil>=2.8.0 in /usr/local/lib/python3.8/dist-packages (from qiskit-ibmq-provider==0.19.2->qiskit) (2.8.2)\n", + "Requirement already satisfied: requests>=2.19 in /usr/local/lib/python3.8/dist-packages (from qiskit-ibmq-provider==0.19.2->qiskit) (2.25.1)\n", + "Collecting stevedore>=3.0.0\n", + " Downloading stevedore-4.1.1-py3-none-any.whl (50 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.0/50.0 KB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: dill>=0.3 in /usr/local/lib/python3.8/dist-packages (from qiskit-terra==0.23.0->qiskit) (0.3.6)\n", + "Collecting symengine>=0.9\n", + " Downloading symengine-0.9.2-cp38-cp38-manylinux2010_x86_64.whl (37.5 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m37.5/37.5 MB\u001b[0m \u001b[31m16.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting ply>=3.10\n", + " Downloading ply-3.11-py2.py3-none-any.whl (49 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.6/49.6 KB\u001b[0m \u001b[31m7.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: sympy>=1.3 in /usr/local/lib/python3.8/dist-packages (from qiskit-terra==0.23.0->qiskit) (1.7.1)\n", + "Requirement already satisfied: psutil>=5 in /usr/local/lib/python3.8/dist-packages (from qiskit-terra==0.23.0->qiskit) (5.4.8)\n", + "Collecting rustworkx>=0.12.0\n", + " Downloading rustworkx-0.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.9/1.9 MB\u001b[0m \u001b[31m61.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: six>=1.5 in /usr/local/lib/python3.8/dist-packages (from python-dateutil>=2.8.0->qiskit-ibmq-provider==0.19.2->qiskit) (1.15.0)\n", + "Requirement already satisfied: chardet<5,>=3.0.2 in /usr/local/lib/python3.8/dist-packages (from requests>=2.19->qiskit-ibmq-provider==0.19.2->qiskit) (4.0.0)\n", + "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.8/dist-packages (from requests>=2.19->qiskit-ibmq-provider==0.19.2->qiskit) (2.10)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.8/dist-packages (from requests>=2.19->qiskit-ibmq-provider==0.19.2->qiskit) (2022.12.7)\n", + "Collecting cryptography>=1.3\n", + " Downloading cryptography-39.0.0-cp36-abi3-manylinux_2_28_x86_64.whl (4.2 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.2/4.2 MB\u001b[0m \u001b[31m95.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting ntlm-auth>=1.0.2\n", + " Downloading ntlm_auth-1.5.0-py2.py3-none-any.whl (29 kB)\n", + "Collecting pbr!=2.1.0,>=2.0.0\n", + " Downloading pbr-5.11.1-py2.py3-none-any.whl (112 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m112.7/112.7 KB\u001b[0m \u001b[31m12.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.8/dist-packages (from sympy>=1.3->qiskit-terra==0.23.0->qiskit) (1.2.1)\n", + "Requirement already satisfied: cffi>=1.12 in /usr/local/lib/python3.8/dist-packages (from cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-ibmq-provider==0.19.2->qiskit) (1.15.1)\n", + "Requirement already satisfied: pycparser in /usr/local/lib/python3.8/dist-packages (from cffi>=1.12->cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-ibmq-provider==0.19.2->qiskit) (2.21)\n", + "Building wheels for collected packages: qiskit\n", + " Building wheel for qiskit (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + " Created wheel for qiskit: filename=qiskit-0.40.0-py3-none-any.whl size=12841 sha256=da78fe2389582649fb7eea82e893b93862fa51cb70676cd30c07ddbeed1f956a\n", + " Stored in directory: /root/.cache/pip/wheels/44/52/90/52d837f0b0cc96b59422d8c3a66dd38e8e08660439e513d707\n", + "Successfully built qiskit\n", + "Installing collected packages: ply, websockets, websocket-client, symengine, rustworkx, pbr, ntlm-auth, stevedore, cryptography, requests-ntlm, qiskit-terra, qiskit-ibmq-provider, qiskit-aer, qiskit\n", + "Successfully installed cryptography-39.0.0 ntlm-auth-1.5.0 pbr-5.11.1 ply-3.11 qiskit-0.40.0 qiskit-aer-0.11.2 qiskit-ibmq-provider-0.19.2 qiskit-terra-0.23.0 requests-ntlm-1.1.0 rustworkx-0.12.1 stevedore-4.1.1 symengine-0.9.2 websocket-client-1.5.0 websockets-10.4\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "pip install qiskit_machine_learning" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 679 + }, + "id": "D0bSM9FA21tR", + "outputId": "9e8c3eb6-f65d-4b6c-afb3-1e666bf883e1" + }, + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", + "Collecting qiskit_machine_learning\n", + " Downloading qiskit_machine_learning-0.5.0-py3-none-any.whl (152 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m152.8/152.8 KB\u001b[0m \u001b[31m12.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: scipy>=1.4 in /usr/local/lib/python3.8/dist-packages (from qiskit_machine_learning) (1.7.3)\n", + "Collecting dill<0.3.6,>=0.3.4\n", + " Downloading dill-0.3.5.1-py2.py3-none-any.whl (95 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m95.8/95.8 KB\u001b[0m \u001b[31m13.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: psutil>=5 in /usr/local/lib/python3.8/dist-packages (from qiskit_machine_learning) (5.4.8)\n", + "Requirement already satisfied: qiskit-terra>=0.22 in /usr/local/lib/python3.8/dist-packages (from qiskit_machine_learning) (0.23.0)\n", + "Requirement already satisfied: setuptools>=40.1.0 in /usr/local/lib/python3.8/dist-packages (from qiskit_machine_learning) (57.4.0)\n", + "Requirement already satisfied: scikit-learn>=0.20.0 in /usr/local/lib/python3.8/dist-packages (from qiskit_machine_learning) (1.0.2)\n", + "Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.8/dist-packages (from qiskit_machine_learning) (1.21.6)\n", + "Requirement already satisfied: fastdtw in /usr/local/lib/python3.8/dist-packages (from qiskit_machine_learning) (0.3.4)\n", + "Requirement already satisfied: python-dateutil>=2.8.0 in /usr/local/lib/python3.8/dist-packages (from qiskit-terra>=0.22->qiskit_machine_learning) (2.8.2)\n", + "Requirement already satisfied: symengine>=0.9 in /usr/local/lib/python3.8/dist-packages (from qiskit-terra>=0.22->qiskit_machine_learning) (0.9.2)\n", + "Requirement already satisfied: rustworkx>=0.12.0 in /usr/local/lib/python3.8/dist-packages (from qiskit-terra>=0.22->qiskit_machine_learning) (0.12.1)\n", + "Requirement already satisfied: stevedore>=3.0.0 in /usr/local/lib/python3.8/dist-packages (from qiskit-terra>=0.22->qiskit_machine_learning) (4.1.1)\n", + "Requirement already satisfied: ply>=3.10 in /usr/local/lib/python3.8/dist-packages (from qiskit-terra>=0.22->qiskit_machine_learning) (3.11)\n", + "Requirement already satisfied: sympy>=1.3 in /usr/local/lib/python3.8/dist-packages (from qiskit-terra>=0.22->qiskit_machine_learning) (1.7.1)\n", + "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.8/dist-packages (from scikit-learn>=0.20.0->qiskit_machine_learning) (3.1.0)\n", + "Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.8/dist-packages (from scikit-learn>=0.20.0->qiskit_machine_learning) (1.2.0)\n", + "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.8/dist-packages (from python-dateutil>=2.8.0->qiskit-terra>=0.22->qiskit_machine_learning) (1.15.0)\n", + "Requirement already satisfied: pbr!=2.1.0,>=2.0.0 in /usr/local/lib/python3.8/dist-packages (from stevedore>=3.0.0->qiskit-terra>=0.22->qiskit_machine_learning) (5.11.1)\n", + "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.8/dist-packages (from sympy>=1.3->qiskit-terra>=0.22->qiskit_machine_learning) (1.2.1)\n", + "Installing collected packages: dill, qiskit_machine_learning\n", + " Attempting uninstall: dill\n", + " Found existing installation: dill 0.3.6\n", + " Uninstalling dill-0.3.6:\n", + " Successfully uninstalled dill-0.3.6\n", + "Successfully installed dill-0.3.5.1 qiskit_machine_learning-0.5.0\n" + ] + }, + { + "output_type": "display_data", + "data": { + "application/vnd.colab-display-data+json": { + "pip_warning": { + "packages": [ + "dill" + ] + } + } + }, + "metadata": {} + } + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 443 + }, + "id": "eXGMb6MT14_8", + "outputId": "b6a0b24b-76ea-485a-d2b4-097fbbda2d43" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 2000/2000 [00:00<00:00, 22945.77it/s]\n", + " 0%| | 8/2000 [00:01<07:06, 4.67it/s]\n" + ] + }, + { + "output_type": "error", + "ename": "KeyboardInterrupt", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 245\u001b[0m \u001b[0;31m############################\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 246\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 247\u001b[0;31m \u001b[0mtest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36mtest\u001b[0;34m()\u001b[0m\n\u001b[1;32m 125\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mtqdm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtqdm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 126\u001b[0m \u001b[0;31m#encode image into circuit\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 127\u001b[0;31m \u001b[0mcircuit\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mimage_re\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrun_part1\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdataset\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"image_vector\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 128\u001b[0m \u001b[0mimage_re\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masarray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimage_re\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 129\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mrun_part1\u001b[0;34m(image)\u001b[0m\n\u001b[1;32m 205\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 206\u001b[0m \u001b[0;31m#simulate circuit\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 207\u001b[0;31m \u001b[0mhistogram\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msimulate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcircuit\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 208\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 209\u001b[0m \u001b[0;31m#reconstruct the image\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36msimulate\u001b[0;34m(circuit)\u001b[0m\n\u001b[1;32m 27\u001b[0m \u001b[0;34m\"\"\"Simulate the circuit, give the state vector as the result.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 28\u001b[0m \u001b[0mbackend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mBasicAer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_backend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'statevector_simulator'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 29\u001b[0;31m \u001b[0mjob\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcircuit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbackend\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 30\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjob\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 31\u001b[0m \u001b[0mstate_vector\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_statevector\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/qiskit/execute_function.py\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(experiments, backend, basis_gates, coupling_map, backend_properties, initial_layout, seed_transpiler, optimization_level, pass_manager, qobj_id, qobj_header, shots, memory, max_credits, seed_simulator, default_qubit_los, default_meas_los, qubit_lo_range, meas_lo_range, schedule_los, meas_level, meas_return, memory_slots, memory_slot_size, rep_time, rep_delay, parameter_binds, schedule_circuit, inst_map, meas_map, scheduling_method, init_qubits, **run_config)\u001b[0m\n\u001b[1;32m 297\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 298\u001b[0m \u001b[0;31m# transpiling the circuits using given transpile options\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 299\u001b[0;31m experiments = transpile(\n\u001b[0m\u001b[1;32m 300\u001b[0m \u001b[0mexperiments\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 301\u001b[0m \u001b[0mbasis_gates\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mbasis_gates\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/qiskit/compiler/transpiler.py\u001b[0m in \u001b[0;36mtranspile\u001b[0;34m(circuits, backend, basis_gates, inst_map, coupling_map, backend_properties, initial_layout, layout_method, routing_method, translation_method, scheduling_method, instruction_durations, dt, approximation_degree, timing_constraints, seed_transpiler, optimization_level, callback, output_name, unitary_synthesis_method, unitary_synthesis_plugin_config, target, hls_config, init_method, optimization_method, ignore_backend_supplied_default_methods)\u001b[0m\n\u001b[1;32m 379\u001b[0m \u001b[0mtranspile_config\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpass_manager\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_combine_args\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mshared_args\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0munique_args\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 380\u001b[0m output_circuits.append(\n\u001b[0;32m--> 381\u001b[0;31m _serial_transpile_circuit(\n\u001b[0m\u001b[1;32m 382\u001b[0m \u001b[0mcircuit\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 383\u001b[0m \u001b[0mpass_manager\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/qiskit/compiler/transpiler.py\u001b[0m in \u001b[0;36m_serial_transpile_circuit\u001b[0;34m(circuit, pass_manager, callback, output_name, num_qubits, faulty_qubits_map, backend_prop)\u001b[0m\n\u001b[1;32m 472\u001b[0m \u001b[0mbackend_prop\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 473\u001b[0m ):\n\u001b[0;32m--> 474\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpass_manager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcircuit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcallback\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput_name\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0moutput_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 475\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mfaulty_qubits_map\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 476\u001b[0m return _remap_circuit_faulty_backend(\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passmanager.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, circuits, output_name, callback)\u001b[0m\n\u001b[1;32m 526\u001b[0m ) -> Union[QuantumCircuit, List[QuantumCircuit]]:\n\u001b[1;32m 527\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_update_passmanager\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 528\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcircuits\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passmanager.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, circuits, output_name, callback)\u001b[0m\n\u001b[1;32m 226\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mcircuits\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 227\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcircuits\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mQuantumCircuit\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 228\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_run_single_circuit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcircuits\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 229\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcircuits\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 230\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_run_single_circuit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcircuits\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/passmanager.py\u001b[0m in \u001b[0;36m_run_single_circuit\u001b[0;34m(self, circuit, output_name, callback)\u001b[0m\n\u001b[1;32m 281\u001b[0m \"\"\"\n\u001b[1;32m 282\u001b[0m \u001b[0mrunning_passmanager\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_create_running_passmanager\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 283\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrunning_passmanager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcircuit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput_name\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0moutput_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcallback\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcallback\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 284\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mproperty_set\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrunning_passmanager\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mproperty_set\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 285\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/qiskit/transpiler/runningpassmanager.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, circuit, output_name, callback)\u001b[0m\n\u001b[1;32m 115\u001b[0m \"\"\"\n\u001b[1;32m 116\u001b[0m \u001b[0mname\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcircuit\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 117\u001b[0;31m \u001b[0mdag\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcircuit_to_dag\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcircuit\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 118\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0mcircuit\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 119\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/qiskit/converters/circuit_to_dag.py\u001b[0m in \u001b[0;36mcircuit_to_dag\u001b[0;34m(circuit)\u001b[0m\n\u001b[1;32m 59\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0minstruction\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mcircuit\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 60\u001b[0m dagcircuit.apply_operation_back(\n\u001b[0;32m---> 61\u001b[0;31m \u001b[0mcopy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdeepcopy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minstruction\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moperation\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minstruction\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mqubits\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minstruction\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclbits\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 62\u001b[0m )\n\u001b[1;32m 63\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/lib/python3.8/copy.py\u001b[0m in \u001b[0;36mdeepcopy\u001b[0;34m(x, memo, _nil)\u001b[0m\n\u001b[1;32m 151\u001b[0m \u001b[0mcopier\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"__deepcopy__\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 152\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcopier\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 153\u001b[0;31m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcopier\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmemo\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 154\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 155\u001b[0m \u001b[0mreductor\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdispatch_table\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcls\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.8/dist-packages/qiskit/circuit/instruction.py\u001b[0m in \u001b[0;36m__deepcopy__\u001b[0;34m(self, _memo)\u001b[0m\n\u001b[1;32m 435\u001b[0m \u001b[0mcpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_params\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcopy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 436\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_definition\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 437\u001b[0;31m \u001b[0mcpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_definition\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdeepcopy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_definition\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_memo\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 438\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mcpy\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 439\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/lib/python3.8/copy.py\u001b[0m in \u001b[0;36mdeepcopy\u001b[0;34m(x, memo, _nil)\u001b[0m\n\u001b[1;32m 170\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 171\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 172\u001b[0;31m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_reconstruct\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmemo\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0mrv\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 173\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 174\u001b[0m \u001b[0;31m# If is its own copy, don't memoize.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/lib/python3.8/copy.py\u001b[0m in \u001b[0;36m_reconstruct\u001b[0;34m(x, memo, func, args, state, listiter, dictiter, deepcopy)\u001b[0m\n\u001b[1;32m 256\u001b[0m \u001b[0mmemo\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmemo\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 257\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 258\u001b[0;31m def _reconstruct(x, memo, func, args,\n\u001b[0m\u001b[1;32m 259\u001b[0m \u001b[0mstate\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlistiter\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdictiter\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 260\u001b[0m deepcopy=deepcopy):\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "import qiskit\n", + "from qiskit import quantum_info, QuantumCircuit\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", + "import sys\n", + "from collections import Counter\n", + "from sklearn.metrics import mean_squared_error\n", + "from typing import Dict, List\n", + "from sklearn.decomposition import PCA\n", + "import tqdm\n", + "\n", + "\n", + "import matplotlib.pyplot as plt\n", + "\n", + "if len(sys.argv) > 1:\n", + " data_path = sys.argv[1]\n", + "else:\n", + " data_path = '.'\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 takes a histogram representation of circuit execution results, and processes 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", + "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(3,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(255*image1,255*image2)\n", + "\n", + "# [normalize]\n", + "def normalize(row):\n", + " #We calculate the squareroot of the sum of the square values of the row\n", + " normalization_factor = np.sqrt(np.sum(row**2)) \n", + " if normalization_factor == 0.:\n", + " #If the sum is zero we return a 0\n", + " return 0.0\n", + " #Else we divide each value between the sum value above\n", + " row = row / normalization_factor\n", + " return row, normalization_factor\n", + "#\n", + "data_path = \"./data\"\n", + "\n", + "def test():\n", + " #load the actual hackthon data (fashion-mnist)\n", + " images=np.load(data_path+'/images.npy')\n", + " labels=np.load(data_path+'/labels.npy')\n", + " \n", + " #test part 1\n", + " global pca, AMPLITUDE_ENCODING_N_QUBITS,IMAGE_SIZE, dataset\n", + "\n", + " AMPLITUDE_ENCODING_N_QUBITS = 4\n", + " IMAGE_SIZE = 28\n", + " N_IMAGES = len(images)\n", + "\n", + " pca = PCA(n_components=2**AMPLITUDE_ENCODING_N_QUBITS)\n", + " \n", + " data = images.reshape(N_IMAGES, IMAGE_SIZE * IMAGE_SIZE)\n", + " pca.fit(data)\n", + " \n", + " # Apply dimensionality reduction on your data\n", + " images_pca = pca.transform(data)\n", + " \n", + " dataset = []\n", + " for i in tqdm.tqdm(range(len(images))):\n", + " image_pca = images_pca[i]\n", + " image_pca_min_ = image_pca.min()\n", + " image_pca_positive = image_pca - image_pca_min_\n", + " \n", + " dataset_i = {}\n", + " \n", + " normalized_state, normalization_factor = normalize(image_pca_positive)\n", + " \n", + " dataset_i[\"image\"] = images[i]\n", + " dataset_i[\"image_vector\"] = normalized_state\n", + " dataset_i[\"label\"] = labels[i]\n", + " dataset_i[\"normalization_factor\"] = normalization_factor\n", + " dataset_i[\"pca_min_\"] = image_pca_min_\n", + " \n", + " dataset.append(dataset_i)\n", + " \n", + " n=len(images)\n", + " mse=0\n", + " gatecount=0\n", + "\n", + " for i in tqdm.tqdm(range(n)):\n", + " #encode image into circuit\n", + " circuit,image_re=run_part1(dataset[i][\"image_vector\"])\n", + " image_re = np.asarray(image_re)\n", + "\n", + " #count the number of 2qubit gates used\n", + " gatecount += count_gates(circuit)[2]\n", + "\n", + " #calculate mse\n", + " mse+=image_mse(dataset[i][\"image\"], image_re)\n", + "\n", + " #fidelity of reconstruction\n", + " f=1-mse/n\n", + " gatecount=gatecount/n\n", + "\n", + " #score for part1\n", + " score_part1=f*(0.999**gatecount)\n", + " \n", + " print(score_part_1)\n", + "\n", + " #test part 2\n", + " \n", + " score=0\n", + " gatecount=0\n", + " n=len(images)\n", + "\n", + " for i in range(n):\n", + " #run part 2\n", + " circuit,label=run_part2(images[i])\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==labels[i]:\n", + " score+=1\n", + " \n", + " #score\n", + " score=score/n\n", + " gatecount=gatecount/n\n", + "\n", + " score_part2=score*(0.999**gatecount)\n", + " \n", + " print(score_part1, \",\", score_part2, \",\", data_path, sep=\"\")\n", + "\n", + "\n", + "############################\n", + "# YOUR CODE HERE #\n", + "############################\n", + "def encode(image):\n", + " qc = QuantumCircuit(AMPLITUDE_ENCODING_N_QUBITS)\n", + "\n", + " qc.initialize(image)\n", + " \n", + " for i in range(AMPLITUDE_ENCODING_N_QUBITS + 2):\n", + " qc = qc.decompose()\n", + " \n", + " return qc\n", + "\n", + "def decode(histogram):\n", + " histogram_array = np.zeros(2 ** AMPLITUDE_ENCODING_N_QUBITS)\n", + " for i in range(2 ** AMPLITUDE_ENCODING_N_QUBITS):\n", + " histogram_array[i] = histogram.get(i, 0)\n", + " \n", + " root = np.sqrt(histogram_array)\n", + " \n", + " root = root * dataset[i][\"normalization_factor\"]\n", + " \n", + " root = root + dataset[i][\"pca_min_\"]\n", + "\n", + " reconstruction = pca.inverse_transform([root])\n", + "\n", + " \n", + " image = reconstruction.reshape(IMAGE_SIZE, IMAGE_SIZE)\n", + " \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", + "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", + "############################\n", + "# END YOUR CODE #\n", + "############################\n", + "\n", + "test()" + ] + }, + { + "cell_type": "code", + "source": [ + "from sklearn.utils import shuffle\n", + "from sklearn.metrics import log_loss\n", + "import tqdm\n", + "from qiskit.circuit.library import RealAmplitudes\n", + "from qiskit.utils import algorithm_globals\n", + "\n", + "\n", + "from scipy.optimize import minimize \n", + "\n", + "\n", + "def ansatz(num_qubits):\n", + " return RealAmplitudes(num_qubits, reps=5)\n", + "\n", + "#Function to identify a function cost\n", + "'''\n", + "Input: An array of parameters(vector of complex amplitudes)\n", + "Output: Function cost\n", + "'''\n", + "\n", + "def objective_function(params, images, labels, shots=1024, mini_batch=5, n_qubits=8):\n", + " running_loss = 0\n", + " images, labels = shuffle(images, labels)\n", + " y_pred = []\n", + "\n", + " #For each item of the trainig set\n", + " for i in tqdm.tqdm(range(mini_batch)):\n", + " \n", + " image = images[i]\n", + " \n", + " circuit = encode(image) #Create a inicial circuit\n", + " vqc = ansatz(n_qubits)\n", + "\n", + " vqc = vqc.assign_parameters(params)\n", + "\n", + " #Create a new circuit based on the size of the initial circuit and the desired qubits to reduce\n", + " circuit_full = QuantumCircuit(n_qubits)\n", + " \n", + " qubits = list(range(n_qubits))\n", + " \n", + " circuit_full.append(circuit.to_instruction(), qubits)\n", + " circuit_full.append(vqc.to_instruction(), qubits)\n", + "\n", + " #Combine the initial circuit, the quantum variatinal circuit and the swap test\n", + " #For the initial circuit and QVC we start at the qubit size_reduce + 1\n", + " \n", + " #Execute the circuit in the qasm_simulator\n", + " histogram = simulate(circuit_full)\n", + "\n", + " pred_label = histogram_to_category(histogram)\n", + " \n", + " y_pred.append(pred_label)\n", + " \n", + " print(labels.shape)\n", + " \n", + " print(len(y_pred))\n", + " y_true = labels[:mini_batch].astype(int)\n", + " \n", + " \n", + "\n", + " loss = log_loss(y_true, y_pred, labels=[0, 1])\n", + " \n", + " print(y_true, y_pred)\n", + " print(\"Loss\")\n", + " print(loss)\n", + " \n", + "\n", + " return loss\n", + "\n", + "def train_classifier():\n", + " images=np.load(data_path+'/images.npy')\n", + " labels=np.load(data_path+'/labels.npy')\n", + "\n", + " N_images = len(images) \n", + " N_QUBITS = 4\n", + " shots = 1024\n", + " mini_batch = 25\n", + "\n", + " vqc = ansatz(N_QUBITS)\n", + " np.random.seed(42)\n", + " initial_point = algorithm_globals.random.random(vqc.num_parameters)\n", + "\n", + " #test part 1\n", + " global pca, AMPLITUDE_ENCODING_N_QUBITS,IMAGE_SIZE, dataset\n", + "\n", + " AMPLITUDE_ENCODING_N_QUBITS = 4\n", + " IMAGE_SIZE = 28\n", + " N_IMAGES = len(images)\n", + "\n", + " pca = PCA(n_components=2**AMPLITUDE_ENCODING_N_QUBITS)\n", + " \n", + " data = images.reshape(N_IMAGES, IMAGE_SIZE * IMAGE_SIZE)\n", + " pca.fit(data)\n", + " \n", + " # Apply dimensionality reduction on your data\n", + " images_pca = pca.transform(data)\n", + " # dataset pre-processing\n", + " X_train = []\n", + " dataset = []\n", + " for i in tqdm.tqdm(range(len(images))):\n", + " image_pca = images_pca[i]\n", + " image_pca_min_ = image_pca.min()\n", + " image_pca_positive = image_pca - image_pca_min_\n", + " \n", + " dataset_i = {}\n", + " \n", + " normalized_state, normalization_factor = normalize(image_pca_positive)\n", + " \n", + " dataset_i[\"image\"] = images[i]\n", + " dataset_i[\"image_vector\"] = normalized_state\n", + " dataset_i[\"label\"] = labels[i]\n", + " dataset_i[\"normalization_factor\"] = normalization_factor\n", + " dataset_i[\"pca_min_\"] = image_pca_min_\n", + " X_train.append(normalized_state)\n", + " dataset.append(dataset_i)\n", + "\n", + " X_train = np.array(X_train)\n", + "\n", + " #Minimization of the objective_fucntion by a COBYLA method\n", + " minimum = minimize(objective_function, \n", + " initial_point, \n", + " args=(X_train, labels, shots, mini_batch, N_QUBITS), \n", + " method='COBYLA', \n", + " tol=1e-6,\n", + " options={\n", + " \"maxiter\": 100\n", + " }\n", + " )\n", + " params = minimum.x #Get the solution array\n", + " #Show the cost of the solution array\n", + " #print(\"Cost: \", objective_function(params))\n", + " print(params)\n", + "\n", + " return params, minimum\n", + "\n", + "params, minimum = train_classifier()" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "kardiamJ16C-", + "outputId": "cbe18b21-af38-4fd7-f4ec-544e358d9164" + }, + "execution_count": 18, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 2000/2000 [00:00<00:00, 24238.72it/s]\n", + "100%|██████████| 25/25 [00:05<00:00, 4.58it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 1 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0] [0.44519858402025986, 0.5085602502018445, 0.40632671451209795, 0.20092020244151756, 0.3977107001676153, 0.41472526492673534, 0.6251959425415752, 0.29942951568515996, 0.3723311667474298, 0.6656642171294723, 0.30642829538372324, 0.628821208180102, 0.40582039822943494, 0.6455649988743064, 0.39777949169730054, 0.3522800502215791, 0.6681438022149653, 0.27692736072648644, 0.7358593160250066, 0.4871031485313555, 0.7418107528346649, 0.7457709858003171, 0.40421499000484673, 0.6774790218773664, 0.7173770307390636]\n", + "Loss\n", + "0.6950484021617176\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.43it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 0 1 0 0 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0] [0.6713651596247816, 0.32797071264017913, 0.6159082805404793, 0.6948126275844074, 0.5181274856264813, 0.4416224649531305, 0.7651560098836326, 0.3891186175970222, 0.8428280495170285, 0.38185086463612594, 0.34402203331214204, 0.39887725924693174, 0.5719200121674068, 0.6428755510693174, 0.7002503570243181, 0.342133916074148, 0.41743510840906595, 0.6569694358548138, 0.7230374549782524, 0.5044971611725263, 0.9487756613093175, 0.4196608441677173, 0.38158536866452547, 0.5494787663284962, 0.81562557728394]\n", + "Loss\n", + "1.007307867649984\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.22it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 1 0] [0.3161426804619409, 0.525812893918048, 0.15152449778814656, 0.5159805905465868, 0.30521341548078657, 0.627944887691082, 0.21770975675776247, 0.6530907982853387, 0.4014338771026449, 0.40717556762670043, 0.3896615528359388, 0.5639420091848597, 0.2775013762502942, 0.41409152496054935, 0.554807525668249, 0.36825999659599246, 0.5180061637894745, 0.6113942345112583, 0.6928522357788024, 0.5890127031885675, 0.28966828678925205, 0.588864736144661, 0.2270164169457504, 0.592547965790828, 0.3529251305449724]\n", + "Loss\n", + "0.5492886348847913\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.32it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0] [0.489827375402157, 0.36110212645926676, 0.23295179255985293, 0.2575735528362733, 0.30338182519741513, 0.2947606895479705, 0.218686257828648, 0.2625493709929567, 0.27985818747882485, 0.1779685396878382, 0.45939146186879665, 0.2954152989110424, 0.18178467127761633, 0.4042178128458602, 0.28523571013168103, 0.3046970339951046, 0.1938272322377514, 0.11179042638179577, 0.28760325075437876, 0.3596147639239648, 0.24603199478078613, 0.17891620899275845, 0.14200324937875072, 0.3574500805061423, 0.2379756713585529]\n", + "Loss\n", + "0.5299397602370532\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.32it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 1 1 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 0 0 0 1] [0.1076630497237271, 0.3515095648675286, 0.3621367638714106, 0.055942117274697084, 0.5341235045371815, 0.5288924287427778, 0.39750470627839896, 0.36303646939700224, 0.15159662921810343, 0.4076748737811838, 0.20453772428573636, 0.3983483526914981, 0.4116847642750084, 0.5399922284087225, 0.38026968538055694, 0.461413773323828, 0.3635609378363328, 0.1498338322893529, 0.4665637784534496, 0.66313938010933, 0.3912011444603135, 0.2806752362687405, 0.11906109575875003, 0.35687829289123624, 0.3821415657587119]\n", + "Loss\n", + "0.5900131532286113\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:05<00:00, 4.92it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0] [0.6703963935419779, 0.5382387003989364, 0.5989349055525331, 0.49066693591667276, 0.6380069245212516, 0.8709332681278472, 0.652771723560037, 0.3310431373134298, 0.7184702211227347, 0.5679171370819375, 0.37921021544673966, 0.5485553716829865, 0.4436537452652735, 0.5579751232105111, 0.5482632606391545, 0.5171419535092207, 0.42849468302268334, 0.5661112304803004, 0.44672510833846857, 0.6327243230988808, 0.5512678404100027, 0.7624315155687088, 0.41069281281468917, 0.5403593632133151, 0.6182999935296536]\n", + "Loss\n", + "0.810766448882395\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.25it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0.4058154382957029, 0.5121152048021309, 0.3595669412574303, 0.49173355580401584, 0.5048628073502891, 0.6769411534774596, 0.7934609608382284, 0.8114074698860186, 0.5352091120608897, 0.5940644898632671, 0.495142248055607, 0.7552141690717098, 0.7448197672155208, 0.6016208908224239, 0.8628053116607186, 0.42642623341605623, 0.514477190119382, 0.47256324327038257, 0.36005006886849045, 0.4230425962632963, 0.3928197725754425, 0.5173651819495484, 0.5109642019195214, 0.5351580036942589, 0.8232376277175146]\n", + "Loss\n", + "0.896769716361815\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.39it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 1 0 0] [0.5547811686003535, 0.24008645165985898, 0.46604865827018027, 0.3627249271191896, 0.3991248101627021, 0.5933141874841698, 0.37921586653278905, 0.2261932814892541, 0.6738375000288936, 0.380896746585959, 0.5319970562101544, 0.4869951523643044, 0.5608560342435324, 0.41394321202930767, 0.44226400946336397, 0.7020612522740677, 0.4409037742186424, 0.5808765940375586, 0.5512187473868894, 0.5180941064237825, 0.4908226747412065, 0.568061216571957, 0.567953759014902, 0.3613358665115178, 0.40309777123666823]\n", + "Loss\n", + "0.645266248037059\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.21it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 0 0] [0.5574878871124967, 0.31730094732166547, 0.36595364725249063, 0.21979415847461165, 0.44079624815109547, 0.2934444923834692, 0.2429529462000074, 0.34197868781379875, 0.2151966950039165, 0.3579367214676502, 0.29638969045699515, 0.3229313263372552, 0.4142677706573377, 0.6384836167663386, 0.25850837051574116, 0.3053647103374007, 0.3030867021476561, 0.41736872347010806, 0.42966552501683397, 0.36814494845026047, 0.41445176304682196, 0.2984989852433838, 0.30438335141612627, 0.321030623947243, 0.31836400477192456]\n", + "Loss\n", + "0.5939544107353314\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.40it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1] [0.06433534790970587, 0.5074828485062922, 0.16689421243740182, 0.15245690724781258, 0.13797539956913238, 0.3271524743972863, 0.09108654595203658, 0.6219615910961256, 0.1704373604772264, 0.0953124532373042, 0.19706159708424761, 0.2532514676238848, 0.5656205542821644, 0.38068193435224096, 0.3896439514201853, 0.6407888610594891, 0.09560933730969953, 0.16405764204831066, 0.09669101099151492, 0.5045810886907645, 0.2797203002864601, 0.10349913358846313, 0.42166852798793863, 0.3678460791475427, 0.22698816078398143]\n", + "Loss\n", + "0.9270658315828387\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.32it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 1] [0.13915137442817482, 0.07208408427537984, 0.4722635006544194, 0.18562996310786123, 0.3468186788175827, 0.3269277267323909, 0.32580728509117124, 0.26450713805472714, 0.37545452503105387, 0.19414435318822404, 0.13541332814490334, 0.26541629323791943, 0.29239528933800607, 0.39266176713075773, 0.2612033251072293, 0.18060277433795305, 0.2641923265329735, 0.12845091354789995, 0.28334071469587546, 0.4083341238128736, 0.3448505812948566, 0.12017666332591435, 0.14135144742772707, 0.395483515856559, 0.2510788845001727]\n", + "Loss\n", + "0.5999810319327736\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:05<00:00, 4.75it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 0 1 1 0 0] [0.2972320755544233, 0.15535842241659148, 0.5543912365669875, 0.3301862850565475, 0.6492310260291216, 0.3071399967346729, 0.19897543077022337, 0.24684268540745924, 0.29507046140616094, 0.1438300999380153, 0.5090502575830858, 0.19191742849921176, 0.20735660143600076, 0.15144952677077164, 0.27859063600812756, 0.25171439818444746, 0.39927695310574524, 0.49131629280782163, 0.6525807120455412, 0.35171265355034753, 0.21483533943135782, 0.5308745958899868, 0.2737170991012762, 0.14056943722756485, 0.22087953218398573]\n", + "Loss\n", + "0.6555997670349555\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:05<00:00, 4.49it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 1] [0.4962013147404283, 0.23515931151877342, 0.5377658549385856, 0.22765502377354838, 0.38857728095276023, 0.17841334087006577, 0.31955390185775095, 0.1780872123640531, 0.18257374373016708, 0.3220702775793027, 0.5240882178897629, 0.16426217496200202, 0.3369766549144346, 0.2671299806820289, 0.2277529216364139, 0.5800454614336916, 0.3910992727185255, 0.32812093409596427, 0.28371424868748574, 0.15663868270246806, 0.09988518523427102, 0.2247510290204852, 0.3095220873680078, 0.35766927924880704, 0.21670545169387886]\n", + "Loss\n", + "0.7439377488351986\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.30it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0] [0.6375373115932557, 0.394921550933168, 0.6375851358021226, 0.48039638807550555, 0.5323296170497155, 0.5979325479190568, 0.5792895371823035, 0.5881683253618746, 0.4975070032652983, 0.8306105971570923, 0.46923427884311003, 0.5204673237099549, 0.5506655155695737, 0.6294536642762751, 0.6715040891497774, 0.6445704930424091, 0.6564763573614711, 0.6329023964831019, 0.44665351258284325, 0.49039718126039245, 0.7556471632490424, 0.5724830537097136, 0.5632650061496771, 0.514590274271011, 0.6121567859133411]\n", + "Loss\n", + "0.8051027275410554\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.36it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 0 0 1 0 0 0] [0.5809279326852694, 0.5787342445130249, 0.47334985543901203, 0.5201567860967695, 0.5945233645802285, 0.5407573229493594, 0.6870934919739524, 0.48918290793414043, 0.49654677037978906, 0.3219680638540187, 0.8298408423519577, 0.6533734019336586, 0.5067767141307389, 0.5501267186433428, 0.45345914929307163, 0.7957552091437112, 0.5444759237809715, 0.5525337918804041, 0.6902338628152074, 0.709789983966451, 0.6290713980693543, 0.6830379687690529, 0.8494426792239576, 0.4402410855150118, 0.43265107148652404]\n", + "Loss\n", + "0.7852859530981681\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.23it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 1] [0.4573126661862429, 0.2792050959686748, 0.2725433310432512, 0.48289216114928235, 0.19359401096884343, 0.29090860504426974, 0.3559828840699166, 0.33956263555344307, 0.4793756691130753, 0.38308967368012015, 0.22974270268109875, 0.4138074321227002, 0.37264145191444353, 0.27098954657853513, 0.2994319016193355, 0.5117415477625172, 0.5520579043226983, 0.41001537410664435, 0.3651803316150706, 0.26982157954557745, 0.4151756017704016, 0.5544687594318843, 0.4487529158569858, 0.2663369480475301, 0.2571254206379988]\n", + "Loss\n", + "0.6241871825220557\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.36it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0] [0.380037053756083, 0.31429247929950344, 0.5552881513921635, 0.43661366063216045, 0.356357748469392, 0.5221492515971922, 0.4191454656644541, 0.4813635336206337, 0.23175778915166878, 0.599777221989054, 0.28110384986519527, 0.47236700913577695, 0.4545599483729894, 0.25773415587039283, 0.25950303043450684, 0.32119856027076227, 0.4694261341249724, 0.23864491209883498, 0.25665194004171643, 0.24431623537794098, 0.5459053996718373, 0.5076209075348597, 0.39329519942773483, 0.32350568157153436, 0.36881419394664583]\n", + "Loss\n", + "0.5353110980861441\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.33it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0] [0.2916200556347915, 0.46974717760359697, 0.5536357643796718, 0.3440451472135647, 0.35664277664606653, 0.7784233045761044, 0.5607973842439778, 0.40216342127018007, 0.2242478308255083, 0.24007316080165003, 0.4800270749587116, 0.5138707523906018, 0.7353606893076261, 0.6286805098858643, 0.560993414953511, 0.4823407763690367, 0.564450845145279, 0.4436904391126636, 0.33522311368759095, 0.45083743837492724, 0.42511900217645104, 0.18169908138122337, 0.4882394071074552, 0.2810496983461326, 0.39119858644474376]\n", + "Loss\n", + "0.8190514607938465\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.26it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0] [0.3608661076601218, 0.29843757605396154, 0.2474506066493457, 0.18630502286165376, 0.3942677685937604, 0.2804236878190935, 0.15088186653488028, 0.42612074601156746, 0.3899666970799271, 0.18460605653810064, 0.36667673147256485, 0.3922294287736279, 0.2970371978186375, 0.36265570574617034, 0.1996624564982773, 0.49452060601197234, 0.45221312557646526, 0.1644234766386213, 0.40421124848923046, 0.38225566846265613, 0.3820207940463038, 0.28240004718734324, 0.23623745681311395, 0.28315347317549966, 0.2589792047174237]\n", + "Loss\n", + "0.5375035142675022\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.37it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 1 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1] [0.3634129472999538, 0.14267859602065194, 0.11091695182739396, 0.4280407183834297, 0.27953274451318283, 0.15369537472350223, 0.2896016257423768, 0.14691882925846253, 0.24319916106813882, 0.06936876429143865, 0.16522716575224417, 0.5687834378655566, 0.48391463082276254, 0.1762155899748491, 0.3794409749048626, 0.43100810473061757, 0.3163275144885015, 0.2299724098653843, 0.46393449010047094, 0.15527915040821558, 0.12970659149712993, 0.1139132218354316, 0.2586051952852234, 0.21503753604999043, 0.3622891221372586]\n", + "Loss\n", + "0.5509766169532706\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.28it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 1 0 0 0 0 1 0 0 1 1 1 1 1 0 1 0 0 1 0 0 1 0] [0.18918735480359833, 0.13374763855913377, 0.2982928249242249, 0.39840639810305334, 0.4848425617525859, 0.13993650824587786, 0.4215575791645655, 0.44812555778622676, 0.3715220712177961, 0.15071829794511526, 0.10164769271640191, 0.16899311372008283, 0.4137350870275539, 0.4146736196817678, 0.35409971987080546, 0.31111464638775793, 0.25065554556280545, 0.2955077242435698, 0.2272012745506866, 0.3949251336205574, 0.1865093695285427, 0.13962069359776882, 0.1356831124249656, 0.36046272215426045, 0.16917026064725724]\n", + "Loss\n", + "0.6998036516253374\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.38it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1] [0.5544126666210487, 0.6408619702648494, 0.45253410417335366, 0.7389956608703482, 0.3815277833835158, 0.4019037152809214, 0.5703986775622684, 0.6133383015878743, 0.5616531705278426, 0.44619153155173347, 0.3998857768826336, 0.4607066414095792, 0.7140858029039648, 0.4539524515031816, 0.4424658235100303, 0.5717380207738608, 0.5916522281386476, 0.6950548780971775, 0.6150020544105095, 0.8008838155460177, 0.5574307461159778, 0.5629497991049439, 0.4149686823601287, 0.3677683070824295, 0.709242067325374]\n", + "Loss\n", + "0.7992723307600351\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.39it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0] [0.5470518571794623, 0.26887415151992616, 0.28749967375550994, 0.4901881945461513, 0.3750463561279367, 0.3585862273556254, 0.3665924138602481, 0.2186862578286481, 0.3910525967362009, 0.43233960303129326, 0.4856951564991841, 0.3802272332795821, 0.24380499284931825, 0.30082667892957854, 0.29961139081328547, 0.19196072083669574, 0.4671359549327671, 0.16740876364158266, 0.300935391921436, 0.183831381009661, 0.19404058782838907, 0.30416940724563457, 0.37931665303263756, 0.2354776006536153, 0.11179042638179577]\n", + "Loss\n", + "0.49523616801992715\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.25it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 1 0 1 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0] [0.2569661855823211, 0.4887741735859771, 0.3527071120427178, 0.235086081031203, 0.3915036526061315, 0.32131976555187225, 0.24653322808819894, 0.30147595261635945, 0.22617254818739557, 0.4752202012144776, 0.44214290775734383, 0.3969823851655403, 0.2093142023667517, 0.1621355002405807, 0.12532328511699062, 0.15156336609187923, 0.33245902632410607, 0.46322821197122666, 0.3129480060302372, 0.5308694630161197, 0.21470010335349557, 0.1785771959748302, 0.3095688051170094, 0.18638040890531277, 0.2332799675292917]\n", + "Loss\n", + "0.6383259801889571\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.37it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 1 1 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 1 0 0 0 1 0 1] [0.4176053416012342, 0.43104722268384754, 0.41896664375944304, 0.3341277419652158, 0.32131976555187214, 0.18675453681229312, 0.2181435570044632, 0.335843089319768, 0.4900331927067718, 0.4713644637727435, 0.39078925300728, 0.3572046184307819, 0.3357153546497531, 0.33039756465412856, 0.4064529283756293, 0.19417475589678473, 0.5118173484409118, 0.2735794768345956, 0.3492311689353607, 0.22072457794229022, 0.15035011342371313, 0.20815826605092083, 0.34720024690387963, 0.27435397051672794, 0.4117090926454872]\n", + "Loss\n", + "0.6456072591278645\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.24it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 0 0] [0.3329252560956439, 0.3636228331035207, 0.3643255946820611, 0.19664114088325613, 0.28713021697713087, 0.2488851403894542, 0.5594613635480162, 0.5611017346319602, 0.23308857927382207, 0.5660083707584962, 0.6922500767032166, 0.46753400887481616, 0.27395901578983795, 0.3845347621883715, 0.3402496317535896, 0.4456364969861335, 0.5135298400504532, 0.2666183716111477, 0.2123828282055899, 0.49480317758301046, 0.23143543308154865, 0.20971555551769652, 0.3286429337987887, 0.23982573627936601, 0.26983955484969874]\n", + "Loss\n", + "0.5717471085536292\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:05<00:00, 4.35it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0] [0.20247061340516215, 0.4472500961966206, 0.23455124100524907, 0.11042085171801426, 0.4128841017615651, 0.22354995202617015, 0.19141982302199462, 0.29289648507535665, 0.2905245377472092, 0.34163141406381825, 0.12091946229485237, 0.16176212391422057, 0.7296906535240025, 0.3991833807032641, 0.20789543770505017, 0.19599734266813046, 0.22971859063109876, 0.1002349618873657, 0.09265534068655898, 0.5349208530596542, 0.29781381467222257, 0.1834171637224102, 0.22730724696351004, 0.08079107314683139, 0.5688555338536512]\n", + "Loss\n", + "0.5381181239965518\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.07it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 1 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0] [0.6532498488657295, 0.3559143915303845, 0.22377432263246896, 0.46913364109838795, 0.3096051991631266, 0.2611813657776445, 0.342404168212737, 0.3419492725019492, 0.44304553466705354, 0.24498647917171826, 0.24908020443579465, 0.2714429027454147, 0.3734334627091059, 0.35547267626379897, 0.3550110906756798, 0.3935215145457033, 0.3313468468509265, 0.3671148481075856, 0.44201896070445024, 0.17961067156157506, 0.34238225072759787, 0.12278605478650559, 0.24392033589499154, 0.41780725268480207, 0.24048961512392683]\n", + "Loss\n", + "0.53365011075199\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.25it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0] [0.28739978560439616, 0.36280775095217915, 0.3472636525579941, 0.5501736450454403, 0.23763948525556144, 0.19704575253402096, 0.41942562960117646, 0.19514718135801667, 0.44361572499125224, 0.48059134890905997, 0.27464159152266865, 0.42515976230959207, 0.41994494949228156, 0.2519153176513088, 0.2369866989429475, 0.35836856279068524, 0.3813454080176372, 0.3346144668897188, 0.3784982891160505, 0.49712444288417296, 0.2100367763588507, 0.2811374313209223, 0.2818282173241043, 0.34893240170505974, 0.2412253015475282]\n", + "Loss\n", + "0.46791101608912866\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.14it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0] [0.1166080908042371, 0.23285841436229243, 0.1491194350964561, 0.32603712272022234, 0.25436436553593533, 0.5632621224934903, 0.3077311951448165, 0.7246053035818216, 0.32088698369836377, 0.17315192007074093, 0.43415906587876163, 0.40437874345258584, 0.19518594331486086, 0.46824099989213247, 0.26960496563216535, 0.32213785202997436, 0.1608075349713798, 0.18089613832088058, 0.319696016393196, 0.5515257455258302, 0.3320337235968034, 0.4898609748598822, 0.47432905305324213, 0.31318817556678563, 0.21023949143358847]\n", + "Loss\n", + "0.5885410570377506\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:06<00:00, 4.13it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1] [0.46582022262433476, 0.3723458357365397, 0.7985662908715331, 0.34008361453289465, 0.601382170828066, 0.4907255417564113, 0.20269192611037834, 0.3570096955733828, 0.31353045531977675, 0.34433946660009573, 0.26569027802950673, 0.44283247669915515, 0.2152033690498618, 0.1657896469958733, 0.35503247901146195, 0.229936362074208, 0.46004573396144505, 0.32136719078994275, 0.25798238040242544, 0.38325495865348697, 0.22634903710259396, 0.44722758569256493, 0.30148777943756333, 0.22486784012109773, 0.3063865575030408]\n", + "Loss\n", + "0.5365838996749019\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.34it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0] [0.17008914007495637, 0.25731077413270614, 0.4548859735090597, 0.45776467526431885, 0.2371764213231881, 0.1897278869137794, 0.37269967783723323, 0.2202937725229689, 0.4050727850895174, 0.19240871455975905, 0.3924138754220051, 0.22482435714656396, 0.17913243869010279, 0.24200512298378576, 0.3823469414980931, 0.20310940611906847, 0.3280422111840855, 0.46000548829483273, 0.21147181982494628, 0.2727472979201906, 0.5390725133651193, 0.2560155607264672, 0.2694054465834687, 0.18385510531701998, 0.19087877509010132]\n", + "Loss\n", + "0.5079296740581982\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.18it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0] [0.41282879936726147, 0.34166022042887156, 0.16711885978832614, 0.293933842945807, 0.3534562763508921, 0.3961050998678018, 0.33644729547815977, 0.49665210237051094, 0.29332787386090164, 0.5349955263986093, 0.6366351109335846, 0.5682522141410473, 0.29969404209781453, 0.4479324595343947, 0.29214739806231027, 0.4559653219731424, 0.2799469001160261, 0.5254859845611279, 0.42731797408592564, 0.21831198098490365, 0.48767350314659874, 0.29568540650304087, 0.3397194869320807, 0.6393221964455822, 0.2788990721706763]\n", + "Loss\n", + "0.5399283214332288\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.33it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 1 0 1 0] [0.31685783398709577, 0.37451112670134246, 0.18724747331024735, 0.4076859959730174, 0.2803147200746946, 0.22401458235702626, 0.32502695783635216, 0.25285054782658684, 0.18858971184984955, 0.2648296660798878, 0.5097693101877533, 0.5765496320168635, 0.18792660053015406, 0.41253947431833915, 0.36501239319787515, 0.2256561498451868, 0.2958272975664411, 0.5130734791980032, 0.32043564225375226, 0.3673249612853051, 0.4130095704088428, 0.44469562134424856, 0.5997338244984932, 0.21240330310714842, 0.1808150392996649]\n", + "Loss\n", + "0.5266928229083481\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.21it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 0 1 0 0 1 0 1 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0] [0.4713992509245458, 0.3783469212820418, 0.3207060470942085, 0.467787291824187, 0.2924503867892831, 0.48553392133564477, 0.19853818083654695, 0.5509433917889195, 0.40819125258524513, 0.48125159338902634, 0.5579130786963601, 0.2908622531977835, 0.5487036951340905, 0.5869994186701883, 0.5095159990444305, 0.6089132946558891, 0.392749298388123, 0.446019786600484, 0.33532121370764134, 0.47097720779390784, 0.3453679712575347, 0.34920397645866824, 0.25662016735070525, 0.4259891496156958, 0.612672457185347]\n", + "Loss\n", + "0.6227262315712123\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.39it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 1 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0.2547728919388048, 0.3804261581862051, 0.5172991372348762, 0.4621089292913077, 0.611455882122396, 0.4856003870011876, 0.4489945545872605, 0.20916016344754476, 0.5387893546618032, 0.35105588973302665, 0.46050743360014357, 0.3595971239979474, 0.31338266833228867, 0.21029570629045768, 0.40799411738285246, 0.26584375758527795, 0.6219765570019401, 0.3214932422642731, 0.5593502976170656, 0.301529510406895, 0.22148041963918325, 0.4034165599921827, 0.4407657770070058, 0.17117716537807598, 0.3970674781805412]\n", + "Loss\n", + "0.533449260797153\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.29it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0] [0.19549163056322286, 0.5309207974081798, 0.39362531410515456, 0.20475601856434, 0.12347120982038687, 0.3541698659301371, 0.21493027820478472, 0.34603376001233715, 0.5272235816586701, 0.1978199503863524, 0.23720904548723265, 0.48810277286703563, 0.25477279895042726, 0.4648750158616854, 0.31697690905567266, 0.2016726731713026, 0.5589873143294287, 0.3665047963954319, 0.19110690509607614, 0.41225450105181255, 0.25125582761859144, 0.20965022420844548, 0.283825582182074, 0.21872939037416872, 0.2698439375504655]\n", + "Loss\n", + "0.39932965771038037\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.11it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 0 0 0] [0.28520521942335153, 0.3312113212478303, 0.3929058860568856, 0.26431235439636763, 0.5374259793793499, 0.3230923620053276, 0.3695181085750129, 0.28618055945501863, 0.33588952219565815, 0.5216591888897124, 0.256611609989397, 0.1924355180426852, 0.7159128225644736, 0.30451747567603166, 0.5654492014535428, 0.6338723302670065, 0.18331892904794253, 0.4276047271019378, 0.29868756836797755, 0.42907869885878464, 0.6563606611007528, 0.3772925703661654, 0.42613997999244096, 0.4045449803608471, 0.47511129504697447]\n", + "Loss\n", + "0.6103609121789184\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:05<00:00, 4.57it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 1 0 0 0 0 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0 0 1] [0.28364266826572715, 0.4926862394592051, 0.3151546304138531, 0.33365873117884426, 0.2827845180318583, 0.4362221255332502, 0.5267231174989091, 0.4482838413015346, 0.5663312451871242, 0.39932364373852264, 0.3322221494288286, 0.24068413116664525, 0.33971048365095435, 0.36313530552828605, 0.4520250053035479, 0.3451528810230497, 0.48342193772127584, 0.4074072858273507, 0.3233250190586884, 0.17167579899380325, 0.24035236960217163, 0.31699105270047045, 0.535305703625031, 0.24736708092158835, 0.36870514677128663]\n", + "Loss\n", + "0.5984076729004326\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:07<00:00, 3.46it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 1 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0] [0.5352119603314303, 0.40071250759414195, 0.32779626308141985, 0.4734644016086396, 0.3819532113260762, 0.45300877383913585, 0.24760192990773228, 0.5251223925437503, 0.5170478207762655, 0.4025261481922494, 0.5889163068668355, 0.2947912736555935, 0.5547892460162507, 0.5683978963389029, 0.21061966669314272, 0.2887240358062117, 0.46243815437956226, 0.2693220749370572, 0.37719197346774314, 0.2811621449236997, 0.5568373822111277, 0.5856046234724708, 0.35598491625346174, 0.372081627800176, 0.36474249462657804]\n", + "Loss\n", + "0.5727855231408753\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.18it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0] [0.48401978103989324, 0.563821528875892, 0.42590030419978764, 0.313908086658949, 0.20418318696172266, 0.40584333541182277, 0.3313607405447591, 0.39150178000736247, 0.4930913286770988, 0.4900852109658332, 0.5949035579892624, 0.32528092274424875, 0.28959765200200727, 0.3982086676806537, 0.41418964103998, 0.3113036830998552, 0.49830848072232337, 0.3999688169716667, 0.3952330071478612, 0.349435175820061, 0.3536671481020385, 0.5341176145219109, 0.42098362670775624, 0.43383966190284423, 0.4237107866638943]\n", + "Loss\n", + "0.6103446695007086\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.23it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 0 0 0] [0.32698731594069635, 0.31417000644304627, 0.2910517862206071, 0.2569774079085812, 0.18377714556511746, 0.27203997627385695, 0.3746361541287121, 0.4674786610822109, 0.5079284136709448, 0.4719361089611496, 0.40460953486590057, 0.446850462502949, 0.19243300814471637, 0.3274090846462312, 0.27702826033958766, 0.4613758636255477, 0.256927984484965, 0.476190196240772, 0.32168200976538575, 0.2894067080972653, 0.393224656113158, 0.32151457710061493, 0.20951437118902982, 0.275931094208333, 0.5706267533401896]\n", + "Loss\n", + "0.5617689441882758\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.24it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0] [0.4732194168670343, 0.31713330045826116, 0.3993262935116213, 0.2283425388859865, 0.20512332542577816, 0.21774266533021647, 0.22111939430393326, 0.4384924703054732, 0.36246992207484907, 0.5752290828103918, 0.31767669951887034, 0.3812455874273563, 0.3177994007532596, 0.385256239684015, 0.20737753800811798, 0.3311280627171276, 0.47161665618614546, 0.2269825570322795, 0.45966748066997487, 0.4059406048754991, 0.3918303943614391, 0.33293209559229564, 0.37920583239603867, 0.31511230997348366, 0.3040281991257459]\n", + "Loss\n", + "0.575211098781069\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.32it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 1 0 0 1 1 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0] [0.511531418291707, 0.2910915151001859, 0.5383357728883009, 0.29743860068537575, 0.2678848013222837, 0.4689216905477181, 0.5002912125055374, 0.4372210437492676, 0.19414134781576797, 0.15454748477767172, 0.5816168360632801, 0.5696919187210128, 0.29855908475368836, 0.29921616100144655, 0.2581246801470779, 0.4275108072467987, 0.3374881403434067, 0.20119095171755055, 0.2768029951958806, 0.6030809792889879, 0.4039967490959382, 0.4779928884496826, 0.2891338605153062, 0.519723825646957, 0.4501150373626767]\n", + "Loss\n", + "0.5104016120949666\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.13it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 0] [0.20354231023320518, 0.4417076660816024, 0.2134469925010923, 0.4203904907202823, 0.32952299947323954, 0.22863004572895207, 0.45985257869481444, 0.19407626963105012, 0.5165738331224623, 0.3257888000960214, 0.2501765078693101, 0.4816344735935858, 0.23407095187626653, 0.2832979911575429, 0.4575999943595184, 0.44273502501175876, 0.32084570742941104, 0.3786855309061769, 0.5759226597565791, 0.19189226149956232, 0.45340405122863003, 0.27228221975173134, 0.3453212380766607, 0.2908942499662926, 0.25510811123830873]\n", + "Loss\n", + "0.5417855944903984\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.35it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0] [0.4584989610744503, 0.31811754845866164, 0.3248732910097147, 0.6737914801784745, 0.34596741591381264, 0.41397820421332343, 0.4595580820908803, 0.5105903960619202, 0.2872483604391442, 0.3646980653651311, 0.617332488061397, 0.30291591760018355, 0.3463369681338638, 0.28781315638655464, 0.13424916508986215, 0.5064993240450271, 0.36137125441345674, 0.4783123422634619, 0.42761326611294015, 0.33078256652661364, 0.2443210200703319, 0.22506864180480352, 0.3081095067907856, 0.3097867814289068, 0.39547789984781834]\n", + "Loss\n", + "0.4932757497189705\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.37it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0] [0.5005777019453568, 0.38027373995369546, 0.580878033528621, 0.30467304157933317, 0.2913235653103464, 0.45866593312960563, 0.15572829917885467, 0.412204562656464, 0.5818352138195779, 0.34051881281734286, 0.3532986279078704, 0.45764869481429665, 0.5895947305930033, 0.2661041069769167, 0.4233640001449838, 0.4870928938143031, 0.6347337514958522, 0.5684462457996526, 0.6610687741560244, 0.19887624845418572, 0.3668382550296754, 0.30947254838563476, 0.5182854469995648, 0.7639739891516273, 0.26849002171543146]\n", + "Loss\n", + "0.5698638934919297\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.14it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0] [0.21044428357846484, 0.5353962616772903, 0.4963888296290724, 0.42858591079104114, 0.38253903114623333, 0.39938250944185777, 0.48112812016849515, 0.24273912300850126, 0.29192827219212236, 0.442882943731739, 0.2905795839984147, 0.2272683086546534, 0.24926303399321664, 0.5060718889912963, 0.2032520181820331, 0.3466256870646747, 0.42737836088991193, 0.30210945264388833, 0.6394309903649115, 0.19913896743484477, 0.17470574100861624, 0.3221270746341736, 0.5080504956066517, 0.48792596106751907, 0.39131954869345137]\n", + "Loss\n", + "0.5091632400352943\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.30it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 0 0 1 1 0 0 0 0 0 1 0 0 1 1 0 0 1 0 0 1 0 1 0] [0.5955071637182237, 0.37694352723059416, 0.4557049650269383, 0.20684211016557624, 0.36952712223279793, 0.3176911006362709, 0.3802972312708427, 0.21935262335562716, 0.3125213578053787, 0.2668178765349784, 0.39951222825302135, 0.4564196467387206, 0.27157219525634047, 0.4125901382931505, 0.4133373694775989, 0.3855322011954009, 0.26049990385405686, 0.2764106692618034, 0.384047940382775, 0.38834734332309295, 0.13363534545060402, 0.3631376444814981, 0.32187838807710384, 0.5302566011535998, 0.26973670180788756]\n", + "Loss\n", + "0.5928632225598061\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:06<00:00, 3.91it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0] [0.4420339410911929, 0.39520974337465686, 0.6197050332420448, 0.4454535743878772, 0.48390196431051286, 0.5544364944929059, 0.46571772383647403, 0.4948154298464023, 0.5354894802337692, 0.2502704876512177, 0.5202143616937138, 0.3742098578852481, 0.3893789888654027, 0.536082288824066, 0.3648803638383359, 0.45480575041714466, 0.36399120100634574, 0.36697263613920705, 0.37557287559751784, 0.2823372850002534, 0.6453194679888876, 0.20674662503943272, 0.462186277598447, 0.5459345265512606, 0.3115207947052525]\n", + "Loss\n", + "0.6081439674106455\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:05<00:00, 4.29it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0] [0.4430737069030667, 0.1858646917701331, 0.19254246220574497, 0.4348998426652589, 0.3555306867040342, 0.34228938053949826, 0.35728987323768446, 0.23982488257433082, 0.36532933314641275, 0.4048760853546357, 0.2342380934761562, 0.14874365679940377, 0.42644479801892643, 0.32999380801924566, 0.46756429221623996, 0.26512723920720566, 0.24922679644021506, 0.28254324643284007, 0.4920850617519363, 0.15974888351947825, 0.07381028622772035, 0.18653336928748418, 0.4284255894911534, 0.29155932455674116, 0.33298190065899386]\n", + "Loss\n", + "0.4229607390520711\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:05<00:00, 4.79it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 0 1 0 0 1 1 1 0 1 0 0 1 0 0 0 1 0 1 1 0 0 1] [0.25290043859345057, 0.16691356862626985, 0.4043094859240721, 0.1892836952296002, 0.30616366065412004, 0.6368530635085738, 0.20774609819901665, 0.26551113094191897, 0.36579591960409213, 0.386034471480728, 0.23424823826633162, 0.3548673151082866, 0.14885380470347614, 0.2555794563927272, 0.3665223537099418, 0.29397086495577834, 0.4082599323339161, 0.40098417082815563, 0.5704249963695825, 0.2808886676148515, 0.4010115438916538, 0.45625861457483335, 0.2425079752526268, 0.21982063811033575, 0.4916223304757307]\n", + "Loss\n", + "0.6388832760772822\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.18it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0] [0.3201196450644189, 0.26640058240064096, 0.29280592628879004, 0.5273987110567004, 0.2639097999054483, 0.1862019728972542, 0.22470162395277793, 0.5002072751692062, 0.14295330435739675, 0.31398783687284104, 0.3393342466074118, 0.13419101783569906, 0.4428586895575576, 0.3667195916821687, 0.24266779584069412, 0.21703219759836578, 0.45951715502769774, 0.12295724698475015, 0.24051362299661957, 0.5152686185854503, 0.2942234422579017, 0.37609039492096363, 0.31582351030808536, 0.3277370321754593, 0.21898107120348193]\n", + "Loss\n", + "0.5259676919193843\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.16it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 1 0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0] [0.35813178549195257, 0.36490768391205297, 0.4775489226881117, 0.44003926233099244, 0.637609970475058, 0.3156896388961821, 0.35217399974401414, 0.5212010812998582, 0.44997056846785344, 0.43711016962695387, 0.3004121921545305, 0.40495492706255065, 0.5210670836027308, 0.4923838925347529, 0.137996401982666, 0.5817868712318264, 0.30270563216317914, 0.38659008162624375, 0.42170147888665316, 0.4063148147694634, 0.4901651494714865, 0.5324638931493016, 0.4162401104384651, 0.3878993549909036, 0.3693654011595282]\n", + "Loss\n", + "0.6222429493084956\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.24it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0] [0.3613269119241675, 0.27553264151882617, 0.556332025541354, 0.264920928360856, 0.4851482121520407, 0.25651313517103086, 0.36115360886412096, 0.4597318122835928, 0.4165742995344238, 0.41940015185128215, 0.34586462236333826, 0.25801719074331336, 0.3934537840211493, 0.5021444932769814, 0.2469374483563625, 0.3003559543651572, 0.27459481493918425, 0.5306234127545526, 0.4606076930709735, 0.35338894839449475, 0.26762695308172285, 0.4255007750459878, 0.35429668215682875, 0.19667598174004475, 0.4675517041356021]\n", + "Loss\n", + "0.5498456310275086\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.19it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 1 0 0] [0.3729873544912892, 0.41155335142697336, 0.4712515882431627, 0.4115346460577253, 0.3049115130361036, 0.43046807841649476, 0.3612961603642385, 0.1733738896612128, 0.42499283677566313, 0.2736114198978266, 0.5171662916761341, 0.2603354629884507, 0.2209208581059258, 0.28202240673915274, 0.6075363335718362, 0.28421411705693417, 0.3930904972256354, 0.3651026675003695, 0.3959667845400988, 0.37918499939668415, 0.37644963527380304, 0.26663561768846605, 0.43313509497252684, 0.4386029337622933, 0.5264333695458441]\n", + "Loss\n", + "0.588180648992632\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.14it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 1 0 0 0 1 0] [0.14884270741704564, 0.36822591266104343, 0.2919369456451784, 0.1613194878849371, 0.1490241251850555, 0.25500253795562766, 0.25688722306297246, 0.4799985185106404, 0.4801220982990417, 0.26501725945330357, 0.2199535798582279, 0.5441750358192818, 0.3297542431315666, 0.47738758187883157, 0.38801115403425135, 0.2568626519336329, 0.5090881167417738, 0.4765327253062697, 0.4662948181635126, 0.38683850489119775, 0.28135238757993636, 0.3415848035463651, 0.24897196882061387, 0.32561554697054873, 0.285434556271989]\n", + "Loss\n", + "0.5067088505646095\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.25it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 1 0] [0.24625512404277752, 0.2462981593949584, 0.22983788897414525, 0.37921744632585647, 0.20409024972934428, 0.17940911078116384, 0.3461857754946631, 0.30849567140238626, 0.332862372189897, 0.22865425676718643, 0.4524763502638156, 0.27184939411887526, 0.2950326953108659, 0.4299853277778143, 0.5730886251208307, 0.46806000825528815, 0.20676707814968542, 0.20143285262295568, 0.21516018854635974, 0.2843561019752331, 0.18738922347145895, 0.39208138766800893, 0.2535566451958483, 0.17618577375547714, 0.28450970475237747]\n", + "Loss\n", + "0.6050161513246813\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.23it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0] [0.4391894098920167, 0.662640051286044, 0.27113367033714614, 0.41090590202704835, 0.5168239502949229, 0.4766351770407503, 0.45639411461623447, 0.28086052527286137, 0.2563241124262114, 0.46943413779918813, 0.2750218481516089, 0.4660730820183997, 0.3942084256423864, 0.4042882020503485, 0.20373424266450993, 0.31074196203125987, 0.26261842507644495, 0.2580285115248057, 0.4627508938769428, 0.41770858621113555, 0.4944536294031928, 0.4324549091436286, 0.6011904587065898, 0.49734720627429685, 0.23464519234468587]\n", + "Loss\n", + "0.6080320820733537\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.24it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] [0.19861017797586988, 0.2163254578029424, 0.5059118836811026, 0.5417990642791297, 0.31842530767329735, 0.5346347557732876, 0.46905280344054656, 0.4543575454215485, 0.4076698305835798, 0.3370636445841664, 0.4014869944581012, 0.4954843992735604, 0.23776235455499906, 0.3336955068284575, 0.6188284172310288, 0.37535799876394926, 0.3826254125431981, 0.40056154402887845, 0.35327847728894585, 0.3186761336678008, 0.5788502944789881, 0.44866165024402804, 0.24478415526679975, 0.25086108199099, 0.255056608133568]\n", + "Loss\n", + "0.5255624906589909\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.28it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1] [0.34624723076888575, 0.2551082006289983, 0.5435826275787223, 0.25086792702829486, 0.2778723200603402, 0.603514206891626, 0.4511551656001711, 0.2075463425687216, 0.542881249066028, 0.2667160277679815, 0.3465829963497688, 0.49872127681383044, 0.25827983211821975, 0.3038825646822295, 0.36240759889853025, 0.3688381425430311, 0.3615301087578653, 0.2403572873289223, 0.2838704763420709, 0.673720656806265, 0.6101216375868628, 0.24177958110539827, 0.5631334421469396, 0.40008897220083794, 0.4635940018796856]\n", + "Loss\n", + "0.5879309922996583\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.25it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0] [0.4842373271686802, 0.2307065929885675, 0.2897568965229526, 0.2975571021283536, 0.45001311737786576, 0.38716451326031764, 0.44301068594858095, 0.5661019765790765, 0.4568085857010303, 0.6498127402658684, 0.29344362219581976, 0.5095941728810865, 0.14313395280843483, 0.39421725113527273, 0.38983357796716767, 0.4951655978807999, 0.24130883028646133, 0.25433633343474243, 0.20822331365984909, 0.37411898440460695, 0.3784137426916895, 0.4212594898431623, 0.25522794506928204, 0.19057184182689435, 0.4577662616041194]\n", + "Loss\n", + "0.5220322296878352\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:05<00:00, 4.44it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0] [0.35338388492298123, 0.5000449872133323, 0.23089704033880165, 0.2583039920724605, 0.2953015266897089, 0.47734608473132145, 0.4609735884677204, 0.35122162742903973, 0.39268358032529826, 0.18689011987498474, 0.38590626048468174, 0.4994423527817656, 0.5235943828023552, 0.45340479350742013, 0.2748922039029307, 0.3312399272529256, 0.38288902343826003, 0.2769471209304062, 0.356333129221284, 0.2538581465599312, 0.49728579652059857, 0.3016346329065612, 0.6921439129681197, 0.40755228779561087, 0.41968532611007237]\n", + "Loss\n", + "0.5119865937778176\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.20it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0] [0.342559690331089, 0.5236431241218416, 0.39628886395541474, 0.19335613663550102, 0.2837828204639113, 0.4703759078942138, 0.4284506600136497, 0.6608366696220808, 0.39360841260107926, 0.4449489284749565, 0.21687905101233224, 0.2523630166994392, 0.3973889347609008, 0.5040277695734428, 0.4847747962056561, 0.4200890739814074, 0.36510889020303045, 0.5516686879068586, 0.41421620515569646, 0.34385402034795975, 0.4656760746011727, 0.2762120873200823, 0.39613727954647066, 0.3310853425015312, 0.36579512368023487]\n", + "Loss\n", + "0.564162258313717\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.36it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0] [0.4589448569550353, 0.26566084787533323, 0.22927664736496245, 0.510035275562386, 0.4540486682493762, 0.42858704452122454, 0.3354855171511124, 0.5684283855765744, 0.26894785488905293, 0.44962605094435315, 0.2517184471361147, 0.5394308401219512, 0.38460967475631747, 0.4450967197409512, 0.566292007133549, 0.2357463320856374, 0.2067789192054524, 0.44014483220069456, 0.40086801305300174, 0.402581810547434, 0.3788010251467508, 0.3528894586974961, 0.5416896442835829, 0.2822508853652364, 0.366028102967136]\n", + "Loss\n", + "0.5671493018138115\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.20it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 1 1 0 0 1 0 0 0 1 0 1 1 0 0 0 1 0 0 0 0 1] [0.34499165144241833, 0.6816553336956847, 0.2589062376634626, 0.24132515858101444, 0.35496997424297866, 0.39766564049027897, 0.6413573327805075, 0.7374894372578197, 0.5085210496605679, 0.186467037055655, 0.2784195337723493, 0.21245062189641079, 0.5525829519725585, 0.35019661442591365, 0.4366646307274816, 0.33242558254593413, 0.1349768988035671, 0.2929192112385002, 0.5258518214517556, 0.47418339789682024, 0.24771828946237429, 0.2845859991260803, 0.28490927792303056, 0.1754545303688279, 0.4351034018006982]\n", + "Loss\n", + "0.5932082204148282\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.35it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0] [0.5098742797573447, 0.34386704543332935, 0.4636366414127328, 0.4357659143005347, 0.44827906466392264, 0.2885432615094855, 0.46079745909019365, 0.46701787560357194, 0.273456451903569, 0.4724631365349622, 0.36484001836439894, 0.3084578924899501, 0.4788900604962193, 0.4064569596343399, 0.31208652027615535, 0.4212414791128897, 0.3365814291772728, 0.3787332680451353, 0.6476870633735803, 0.29032882975014473, 0.3129898512961542, 0.20470697904842522, 0.4570112210980386, 0.2763313493862599, 0.3997811504797958]\n", + "Loss\n", + "0.5723140615821187\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.40it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 0 1 1] [0.4587187410029443, 0.40928647691885633, 0.2635596711053038, 0.22975354990945282, 0.3967719471789216, 0.4798898654545906, 0.3998618927942513, 0.620853557309515, 0.23660055938147187, 0.27043406067989656, 0.4138099180568078, 0.35095347078742756, 0.4105980696929751, 0.26004990401421385, 0.42854274317392416, 0.47231393174993286, 0.3548794271120392, 0.3217087085986659, 0.6763532488559285, 0.27538243170112797, 0.6635963925239381, 0.6275009302908465, 0.278485987401268, 0.37457399356944604, 0.49440568700734067]\n", + "Loss\n", + "0.625523667652792\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.25it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 0 1 0 0 1 0 1 0 0 0] [0.2259737990495084, 0.46613560065830373, 0.27302224170123834, 0.2857052834113135, 0.2049352641431454, 0.4637144332007915, 0.33575046812458376, 0.5005483164901555, 0.26043713582528877, 0.4051586973184169, 0.5930972162566825, 0.28290184321854445, 0.46871912096621615, 0.275642270177589, 0.38823798263827025, 0.43339297950318745, 0.31168904754305665, 0.5493793882610989, 0.2536611818655393, 0.3320096364472244, 0.3973144443604305, 0.23329461717043642, 0.36885223948267293, 0.3249501263366549, 0.29113322270731307]\n", + "Loss\n", + "0.6257360322701057\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.36it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0] [0.22906161776508693, 0.456143452858393, 0.355919546470794, 0.7324442762103764, 0.33260967767768557, 0.44279507078874314, 0.5116971322663821, 0.393490966225872, 0.2712019570515655, 0.5733836407408478, 0.41621172739033235, 0.48806297511212393, 0.19167520698611426, 0.2968452303462556, 0.5440197129403526, 0.4548005983270972, 0.29354263870490505, 0.37247943618190926, 0.5610143022391185, 0.4882459662731552, 0.2703245813830587, 0.217427526932321, 0.24155566804834003, 0.2825819805614949, 0.5669657393471044]\n", + "Loss\n", + "0.5672939629626144\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.27it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 1 0 1 0 0 0 0 1 0 1 1 1 1 0 1 1 0 0 0 0 0 0 0] [0.4065324998453015, 0.40528464331729697, 0.3448841622117507, 0.5755028792767087, 0.4863468717025396, 0.3235850497157585, 0.28891048201827685, 0.21101003642893765, 0.6565101216816709, 0.3751482740719252, 0.31421942625311505, 0.471485805566489, 0.35509027103214963, 0.32580272898506, 0.7124506935001863, 0.2809961314776041, 0.489563737740958, 0.4239550185256047, 0.5991837430003344, 0.5823759779526019, 0.2709112213350293, 0.3274688097394671, 0.2934391683242277, 0.4685579646200807, 0.29247596688825145]\n", + "Loss\n", + "0.6573091060678599\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.35it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 1 0 1 1 0 0 1 0 0] [0.4874109786743642, 0.40765408205724163, 0.40659402295611957, 0.6683781977179005, 0.29213611584135885, 0.24030137581006614, 0.4610062638038247, 0.4917647342706687, 0.37642037105742104, 0.27219488166755534, 0.45676373914539026, 0.5158813361573482, 0.31029051979295563, 0.20514059843612525, 0.5348872180048297, 0.4198838148627013, 0.48975603307547705, 0.36761903312736016, 0.37675322033357733, 0.30628703490839176, 0.15989976834419453, 0.4271039237213497, 0.2860151458059087, 0.4531081608764877, 0.31029051325304663]\n", + "Loss\n", + "0.6837929322195414\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.25it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0] [0.4306538026379048, 0.3161003932862271, 0.19278469240393065, 0.3903806519466912, 0.4015205244596922, 0.4316936422295392, 0.28677761493910475, 0.34267676692954674, 0.23463296502278697, 0.29367472811466677, 0.6176268089792343, 0.2715623738665731, 0.18642635770488517, 0.32845768393992825, 0.19719240636229557, 0.41740922645185274, 0.3856880644415962, 0.5110417178951031, 0.4515180555447038, 0.4130105999041319, 0.5097406364514208, 0.2916699969052607, 0.3911086968704943, 0.3419979592878614, 0.20382691186430396]\n", + "Loss\n", + "0.503883535716793\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.40it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 1 0 0 0 1 1 0] [0.2854343389423734, 0.22341914660986625, 0.15144305609980174, 0.34678595094441483, 0.5707771967564699, 0.2078632859002025, 0.429969550123765, 0.4994865401013099, 0.5965663861271703, 0.36963300864673104, 0.45858015155034776, 0.19201548354326606, 0.6443496289338823, 0.295953108592948, 0.49498352421061403, 0.7247212768759308, 0.3111068340542225, 0.4849442502373036, 0.47035578553260493, 0.28363825664636344, 0.46612237944004875, 0.2993002788327958, 0.3903570479376789, 0.3136043757078111, 0.34750558146264743]\n", + "Loss\n", + "0.55523675198344\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.34it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 1] [0.4550034045796181, 0.4024069912446461, 0.6028327843394405, 0.41858391737020173, 0.4267099865639714, 0.5267490109209085, 0.48206709413869286, 0.39796209275372424, 0.3094145966918649, 0.18657724529205788, 0.48007499996774394, 0.7007848978234428, 0.43515522958371133, 0.5578285067871955, 0.3764653761989042, 0.3727024654918156, 0.25677072063962714, 0.5462407597946706, 0.23138629002775107, 0.5088844367723425, 0.4703608242421737, 0.1972762196564329, 0.2255149564046599, 0.3542248892388192, 0.4545947724030077]\n", + "Loss\n", + "0.5319766608494801\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.39it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0] [0.3029307116448536, 0.6725128579376702, 0.5371318684479938, 0.23568331232813136, 0.28690517028061835, 0.36205187904126335, 0.2952704790785773, 0.4786520181644036, 0.15512626432530247, 0.613420263220013, 0.09844454189486934, 0.29256150265238445, 0.47244628137488826, 0.46511186812332483, 0.33562180169711975, 0.49304195496657705, 0.47662782299665524, 0.17320583673569304, 0.35457578673634443, 0.41963038320287094, 0.38111657957619643, 0.2731029924182975, 0.4839762106832507, 0.27369712744796565, 0.4582376373000071]\n", + "Loss\n", + "0.5594094009733912\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.44it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 1 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0] [0.4072387773594184, 0.408185166868005, 0.3704243331726294, 0.43546573358095636, 0.3548080860566547, 0.26694791237048443, 0.30340194514772295, 0.1860958864123046, 0.5023584824705679, 0.3398371429657956, 0.20395478408938805, 0.5658285297700361, 0.6157822425173605, 0.26804346491282727, 0.4650543371031943, 0.26680900299481325, 0.5337880158331658, 0.35638320609718654, 0.32658013603376373, 0.24021359570060902, 0.6251326253817966, 0.29949256615899145, 0.4715226691953611, 0.29656168409688805, 0.34867600303884094]\n", + "Loss\n", + "0.53318608803566\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.32it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 1] [0.2374903903059873, 0.2777813135380293, 0.3411222449133261, 0.28043357013457876, 0.2769444111123329, 0.27565857110148195, 0.553924468144404, 0.4719934033746668, 0.36502611440933375, 0.3122498245780688, 0.46626381129192146, 0.6336717341415739, 0.35483175674493794, 0.2907714765152037, 0.36223784959220195, 0.3709600753930126, 0.31703186234003566, 0.2617398952673643, 0.40417477902971377, 0.31480530545545016, 0.537712786198294, 0.3118822574173347, 0.5476599801443977, 0.443599862973186, 0.46551906718675606]\n", + "Loss\n", + "0.5708355744094075\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.42it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 1 0 0 1 0 0 0 1 0] [0.2794817092559835, 0.3049865880525296, 0.22121631903700137, 0.4838659687422586, 0.3812426612092576, 0.27394250008270427, 0.3796572159522169, 0.24206434377879282, 0.415057838450637, 0.24509217941954492, 0.3936008439956759, 0.35226119293616276, 0.34588876428699283, 0.24070601391642063, 0.3597498822396854, 0.24581260348934564, 0.3927120620133214, 0.24337135246469196, 0.2241961257383111, 0.4346055081572392, 0.39988599509396805, 0.4165168211443475, 0.377125346539378, 0.43956324487380555, 0.31486417415241935]\n", + "Loss\n", + "0.5191758491624942\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.41it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1] [0.23487577852542899, 0.2937624263484869, 0.28484763107045097, 0.31609470136650314, 0.504019649508362, 0.41246186230899906, 0.24725163894952817, 0.2869534477519903, 0.47798895149809534, 0.469155961926953, 0.27639816396634653, 0.2911064581377919, 0.4092599466539797, 0.21005559854245714, 0.3076964627651282, 0.2550857375280304, 0.5023109042168485, 0.5607005341508147, 0.649141586813452, 0.44610967984059247, 0.26138594705879636, 0.29610936545459077, 0.4752722836536353, 0.3100669445870144, 0.3159955631192477]\n", + "Loss\n", + "0.47847541670798754\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.26it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0] [0.30786126124593216, 0.4558775304027567, 0.5950277424637225, 0.2891689345573553, 0.3822088622634321, 0.495286955158686, 0.2863884416418506, 0.3101955814035088, 0.4684153149681554, 0.41410104149629323, 0.11844597264511003, 0.5084504997391166, 0.4084242505596338, 0.5389924501587189, 0.2652434208343567, 0.5187960423240754, 0.38334002118713034, 0.24554805787661463, 0.4361345585574841, 0.4947508338430574, 0.5372087563970813, 0.3825617349737256, 0.37305404256424257, 0.4576671710117691, 0.2579656202396821]\n", + "Loss\n", + "0.6541377228415368\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.37it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0] [0.31326938827327555, 0.2561655765095824, 0.2238399712535663, 0.2755630910208595, 0.24596758087044182, 0.17115167454251612, 0.45722994947537743, 0.21243949051339547, 0.6064338435859076, 0.5703871808987849, 0.39121088275734556, 0.27168248453880683, 0.21396677183483614, 0.17314959355132004, 0.5331367467086929, 0.2568063513752424, 0.27535352423829035, 0.6564571430157717, 0.2582127440149655, 0.3470922426301329, 0.539266763644767, 0.22970378128974914, 0.48111461955867935, 0.22772023252626045, 0.4718697401744505]\n", + "Loss\n", + "0.4489687103252303\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.36it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0] [0.2763247293026467, 0.27753533551180176, 0.24140129734053184, 0.49246840354544685, 0.48333809512146514, 0.3110712206539013, 0.24534768069587098, 0.2774563395658926, 0.5319473894916995, 0.22647908703870612, 0.22904011930235268, 0.3097679013010772, 0.39793707962325203, 0.4754269538966829, 0.5777557199728691, 0.32724199186647507, 0.48438047539554285, 0.42211017457871947, 0.47003613215153306, 0.6747870483581206, 0.5468288793003417, 0.38412404467539607, 0.24020860168694927, 0.2826841246597908, 0.46813977384934036]\n", + "Loss\n", + "0.5101709212398042\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.35it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0] [0.33476714866296897, 0.4695854870030304, 0.3540539676263318, 0.4850281190710748, 0.5748113533899537, 0.3963407021272704, 0.2560090857755006, 0.3695020627002438, 0.45601609992621955, 0.4387173418620466, 0.33945053822694354, 0.5720440448571305, 0.4133403943915796, 0.37710842194106997, 0.412776446881589, 0.21991401127358962, 0.26399891721757457, 0.2938895408078156, 0.45226658993711444, 0.31696908413884306, 0.4083234099646236, 0.303708909985716, 0.3270447356683235, 0.5745119828912805, 0.3465857488037399]\n", + "Loss\n", + "0.580110022342041\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.43it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 0 1 1 0 0 0 1 1 1 1 0 1 0 1 0 1 0 0 0 0 0 0] [0.48755907504485085, 0.38921457849189534, 0.3686453053770695, 0.2664103896488317, 0.44544783777364777, 0.39322741070488587, 0.3931574604490279, 0.42914023241952876, 0.3075622645894014, 0.365663064315066, 0.5306379917208914, 0.4562547000819376, 0.6459488171748391, 0.4404665759427797, 0.46516004560894453, 0.2829323053541594, 0.41504002654695393, 0.48611602898394735, 0.49727508227032124, 0.4272457498148128, 0.27948306093010217, 0.2381298894265002, 0.3221629084358746, 0.6396086892421532, 0.2077822442830013]\n", + "Loss\n", + "0.5893575025890542\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.36it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1] [0.4761737468572701, 0.46335403884286563, 0.3124056151948978, 0.20889555167306212, 0.3259188152544734, 0.2690302024475903, 0.23921056511158356, 0.24388726938506664, 0.2820628635390516, 0.5336436399441695, 0.1556627431633497, 0.3873732367557685, 0.24434868867436346, 0.5775867569209762, 0.4333311558010891, 0.3737391874766227, 0.2830126032905617, 0.4505342485176952, 0.2643667253341768, 0.6251433034376424, 0.35949099450661326, 0.3848403643229422, 0.3552200313366326, 0.6835022474134604, 0.4732689023609927]\n", + "Loss\n", + "0.5401399775064768\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.46it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 1 1 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0] [0.4591939177252313, 0.6202784313860856, 0.32275716894155604, 0.47973549171418417, 0.6184243407048905, 0.4663123357697524, 0.4672384861164829, 0.3705270045104539, 0.28603769277411845, 0.361209481315273, 0.4597220307595333, 0.4004037459772542, 0.2685388208981012, 0.39593958875403884, 0.21149298778255116, 0.4506681339259347, 0.35670221444130523, 0.47834646417067933, 0.2141269901524909, 0.1662824443615835, 0.530336107937883, 0.20157107778115488, 0.2193679352259913, 0.19566911537463183, 0.26702045300309935]\n", + "Loss\n", + "0.5221044196453131\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.46it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 0] [0.49907967212377247, 0.42151075205689165, 0.3618429732120282, 0.4015378008033015, 0.49782646328517394, 0.46666653163553307, 0.492533935121576, 0.372950880554099, 0.40390293538863836, 0.2232063664870488, 0.23078741810583384, 0.23601810715562177, 0.3787747524891755, 0.4899107501452352, 0.38713714946538624, 0.6044147146571415, 0.633634846034287, 0.24064503096148418, 0.6625101958957433, 0.27492663959102565, 0.5395955121676737, 0.47952015661756187, 0.5637826818255206, 0.5281631160540776, 0.27572449253924886]\n", + "Loss\n", + "0.5805412089099845\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.35it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0] [0.5988278981856332, 0.4500141228739078, 0.3939524088657773, 0.37879717250534534, 0.561616266079152, 0.43164534267396043, 0.4530224575461337, 0.28753725857550394, 0.22490197504586384, 0.4045665054829799, 0.39939662560296996, 0.28973459026201, 0.4644572684669657, 0.5023114266288122, 0.30673980003193196, 0.19464951704410105, 0.38732741418366556, 0.3476069388842789, 0.2790825550884747, 0.49216392779984575, 0.5834746511575599, 0.5036202475280993, 0.2267606154463004, 0.23930797753600325, 0.4555246046929717]\n", + "Loss\n", + "0.5904759058598446\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.39it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0] [0.23771062663551024, 0.4801890644886302, 0.6442113053065759, 0.3588200312444634, 0.5684923001326601, 0.3433520486333863, 0.2801505220506256, 0.4051399915272826, 0.28313579917683673, 0.4574725114055847, 0.25344019857837563, 0.4661412415456311, 0.24423831182346364, 0.5787277638967014, 0.3247281336437787, 0.3337208727288321, 0.42466053912837187, 0.4325343836132765, 0.30461664096147045, 0.24776779868353055, 0.23099535940355706, 0.43978518052264914, 0.6691778625561848, 0.23499119731240473, 0.2825801350974801]\n", + "Loss\n", + "0.5049127742884032\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.34it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1] [0.23555327814535978, 0.3938520955733311, 0.2502713112487151, 0.34530019966396075, 0.25416822308327314, 0.5041486035814842, 0.4667297886197652, 0.39413733101886844, 0.2515688768341789, 0.3882236270057972, 0.4028007988823741, 0.34229087342737474, 0.21572595543181722, 0.1995397207986096, 0.2751848336948765, 0.34128507088354304, 0.5057246765727201, 0.22366951378561378, 0.3292985260796535, 0.5055076642478623, 0.3714621512072047, 0.4435926392250792, 0.5008345412206341, 0.266133796832484, 0.4837243057952208]\n", + "Loss\n", + "0.4837325910955243\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.31it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1] [0.26880316495604784, 0.21978215361953946, 0.3523494648361227, 0.473904604071491, 0.34319068593722646, 0.18146679112761352, 0.2635912588466722, 0.5441855724888387, 0.4854594526090723, 0.6227765654878945, 0.40029667703628236, 0.42419009824437426, 0.3919867345622857, 0.32287063785980646, 0.25159358611484556, 0.2778232730156857, 0.27709696142104645, 0.5759273991638778, 0.564656040778249, 0.22674280941035746, 0.42730940760368247, 0.3531371393366176, 0.33976459069860804, 0.34631958213113145, 0.40446290546125324]\n", + "Loss\n", + "0.547149692646935\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.44it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 1 0 0 0 1 0 0 1 1 1 0 0 1 0 0 0 1 0 1 1 0] [0.344184738540878, 0.26544251313584305, 0.30693316754896904, 0.2797472949745911, 0.4893461442931555, 0.23878049053387904, 0.3395029185072831, 0.49556574419176125, 0.4620094951435631, 0.4600140112125587, 0.2610499953038929, 0.5368399353582775, 0.3715038576915887, 0.4194094332764476, 0.34711566173704667, 0.24687634276463796, 0.3449702445112335, 0.2447231537182194, 0.25248316167895546, 0.24389982547243275, 0.4722649200104047, 0.25170446013175, 0.48369260203798686, 0.3851749109244691, 0.35897317469875956]\n", + "Loss\n", + "0.5389783595886454\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.44it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1] [0.39788656948016254, 0.5453614376312044, 0.6838838487941593, 0.4596594961595248, 0.3569639810054452, 0.28494396358705876, 0.3743798245445423, 0.5791444192447648, 0.27548994037032815, 0.4069793809715258, 0.6385837115044033, 0.46270347303470694, 0.30634619028764515, 0.6756330929784163, 0.3098232449651085, 0.2886335111258068, 0.36750402918195546, 0.42324979800430196, 0.1886760735113156, 0.24133541060922284, 0.5369488700324706, 0.35563040798649687, 0.2567024240496755, 0.25056143692138966, 0.4883070585573208]\n", + "Loss\n", + "0.534423244235851\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.35it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 1 0 0 0] [0.35076680931453325, 0.36813945599689624, 0.2423008392452746, 0.18812807716006574, 0.2741288557364272, 0.40148732322449776, 0.42163933600459613, 0.329607450333196, 0.26356990566803096, 0.4759152674455227, 0.5640930174457641, 0.3885014948361618, 0.597749319888975, 0.4028823618989008, 0.23100405580515906, 0.27134684351103855, 0.373033569589572, 0.2927722266626428, 0.41314764477866184, 0.2987216925188219, 0.3918132763245623, 0.3864632673719498, 0.2850218053481738, 0.4891666657413192, 0.5448604178279075]\n", + "Loss\n", + "0.6419530802497471\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.43it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0] [0.48963531856240783, 0.4391148284280446, 0.35634798733839523, 0.39165174707074946, 0.39132333770734223, 0.34198386144068627, 0.3774931297115475, 0.5566448241082393, 0.2526672732899332, 0.2656629134831282, 0.39594157505373406, 0.22125618866703323, 0.4089212659039269, 0.4595071213690432, 0.22659398064216063, 0.23685276564383187, 0.21638080778056248, 0.4768234104436464, 0.3471715349282979, 0.255438046482327, 0.2194226672864823, 0.4216469353722725, 0.41813203877179345, 0.349439869075088, 0.2930366659695531]\n", + "Loss\n", + "0.475827482273573\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.42it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 0 1 1 0] [0.4053722767037281, 0.37989143236862194, 0.47323504508327285, 0.49078394465976377, 0.45562840744268207, 0.47418907801383764, 0.5003226292779379, 0.400232896270396, 0.2811965362334977, 0.3713591533637336, 0.2673613925996377, 0.40322301309480846, 0.23298207228524323, 0.3452135320974887, 0.46670458970843837, 0.2474451830338704, 0.22802816551706984, 0.39525353466152646, 0.4909458071396119, 0.587017592501768, 0.32631529963064565, 0.33655502314392166, 0.3712275106466, 0.4923950776682408, 0.2580982360169816]\n", + "Loss\n", + "0.6085268462878561\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.32it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 1 0 1 0 1 0 0 0 0 0 1 1 1 1 0 0 1 0 0 0 0 0 0] [0.5064117276658848, 0.582606394530645, 0.43159801524815045, 0.2830759500562336, 0.45220109310645795, 0.37717952523497517, 0.355352641852072, 0.356804406701175, 0.2595683105616583, 0.4265578514056183, 0.34368333191994493, 0.5670550425654248, 0.5031492997027959, 0.39130293939839844, 0.6471133768901106, 0.49704317725029523, 0.2775908288929886, 0.1857201606178082, 0.489306308204554, 0.3399390343856141, 0.44858304782373737, 0.20556068386896048, 0.5829410813160572, 0.3080436388833854, 0.22895089300015303]\n", + "Loss\n", + "0.5743672965309764\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.44it/s]\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0] [0.44337416390285245, 0.22347025276139912, 0.4072912541043265, 0.37766311460352586, 0.3295190573725797, 0.3408275648833128, 0.4871100069392723, 0.2726044317927426, 0.3841790962794557, 0.3774391639455364, 0.3717301345404526, 0.5724713212872472, 0.2838573958376767, 0.32353255401048003, 0.25107948278654957, 0.3507348520007304, 0.16193560909690166, 0.5661635677831014, 0.4054158502441977, 0.24700077035303386, 0.3791385306708585, 0.25520862678452616, 0.507448457872475, 0.3922288476864353, 0.2692315495095034]\n", + "Loss\n", + "0.532458449969321\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "100%|██████████| 25/25 [00:04<00:00, 5.29it/s]" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "(2000,)\n", + "25\n", + "[0 0 0 1 0 0 1 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0] [0.3417753386555086, 0.5536320468722367, 0.42613222915669113, 0.4412413804602271, 0.3205896641985686, 0.42071812688023735, 0.5023080336617323, 0.4804877689496918, 0.37041189940560204, 0.5967165922866011, 0.468403262165466, 0.3624440501946382, 0.35831932881784306, 0.4905533743320733, 0.3694065635938489, 0.45968188883127525, 0.46445083378450114, 0.28430256309503754, 0.23795509623995448, 0.22151486007673432, 0.2759404667112512, 0.22965115146463683, 0.7141930492003385, 0.4768950328074967, 0.2394397339014594]\n", + "Loss\n", + "0.5776595803693259\n", + "[ 0.55562182 1.14319133 1.0737959 0.40937078 0.0165973 0.50865298\n", + " 0.30024442 0.1364341 -0.06497169 0.57702616 0.13664098 1.24139061\n", + " 0.45566212 0.64294409 0.57014194 0.03931625 0.87284308 0.49789603\n", + " 0.79267549 0.03023329 0.44871798 1.52403189 0.8777964 0.5086433 ]\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "best_params = params" + ], + "metadata": { + "id": "9mKYCp4u7g9p" + }, + "execution_count": 20, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "vqc." + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 314 + }, + "id": "QhCDvNUq9NMD", + "outputId": "e6da79f8-5307-48e7-e1d4-0bbf58dcef6f" + }, + "execution_count": 25, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " »\n", + "q_0: »\n", + " »\n", + "q_1: »\n", + " »\n", + "q_2: »\n", + " »\n", + "q_3: »\n", + " »\n", + "« ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐\n", + "«q_0: ┤0 ├\n", + "« │ │\n", + "«q_1: ┤1 ├\n", + "« │ RealAmplitudes(θ[0],θ[1],θ[2],θ[3],θ[4],θ[5],θ[6],θ[7],θ[8],θ[9],θ[10],θ[11],θ[12],θ[13],θ[14],θ[15],θ[16],θ[17],θ[18],θ[19],θ[20],θ[21],θ[22],θ[23]) │\n", + "«q_2: ┤2 ├\n", + "« │ │\n", + "«q_3: ┤3 ├\n", + "« └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘" + ], + "text/html": [ + "
     »\n",
+              "q_0: »\n",
+              "     »\n",
+              "q_1: »\n",
+              "     »\n",
+              "q_2: »\n",
+              "     »\n",
+              "q_3: »\n",
+              "     »\n",
+              "«     ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐\n",
+              "«q_0: ┤0                                                                                                                                                       ├\n",
+              "«     │                                                                                                                                                        │\n",
+              "«q_1: ┤1                                                                                                                                                       ├\n",
+              "«     │  RealAmplitudes(θ[0],θ[1],θ[2],θ[3],θ[4],θ[5],θ[6],θ[7],θ[8],θ[9],θ[10],θ[11],θ[12],θ[13],θ[14],θ[15],θ[16],θ[17],θ[18],θ[19],θ[20],θ[21],θ[22],θ[23]) │\n",
+              "«q_2: ┤2                                                                                                                                                       ├\n",
+              "«     │                                                                                                                                                        │\n",
+              "«q_3: ┤3                                                                                                                                                       ├\n",
+              "«     └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
" + ] + }, + "metadata": {}, + "execution_count": 25 + } + ] + }, + { + "cell_type": "code", + "source": [ + "from qiskit import QuantumCircuit\n", + "N_QUBITS = 4\n", + "vqc = ansatz(N_QUBITS)\n", + "\n", + "vqc = vqc.assign_parameters(best_params)\n", + "\n", + "vqc.qasm(filename=\"quantum_classifier.qasm\")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 268 + }, + "id": "gfq8UhJH7CEn", + "outputId": "556e5a7c-ec1e-4da6-f764-62130a5ce4c0" + }, + "execution_count": 27, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'OPENQASM 2.0;\\ninclude \"qelib1.inc\";\\ngate gate_RealAmplitudes(param0,param1,param2,param3,param4,param5,param6,param7,param8,param9,param10,param11,param12,param13,param14,param15,param16,param17,param18,param19,param20,param21,param22,param23) q0,q1,q2,q3 { ry(0.555621819228932) q0; ry(1.14319132801287) q1; ry(1.07379590145389) q2; ry(0.409370781763752) q3; cx q2,q3; cx q1,q2; cx q0,q1; ry(0.0165973010020706) q0; ry(0.508652978720279) q1; ry(0.300244419920286) q2; ry(0.136434104028988) q3; cx q2,q3; cx q1,q2; cx q0,q1; ry(-0.0649716942665253) q0; ry(0.577026156276957) q1; ry(0.13664098460932) q2; ry(1.24139060584453) q3; cx q2,q3; cx q1,q2; cx q0,q1; ry(0.455662122094092) q0; ry(0.642944089110158) q1; ry(0.570141938819558) q2; ry(0.0393162465417179) q3; cx q2,q3; cx q1,q2; cx q0,q1; ry(0.872843078509701) q0; ry(0.497896034397818) q1; ry(0.792675492672247) q2; ry(0.0302332873841969) q3; cx q2,q3; cx q1,q2; cx q0,q1; ry(0.448717981940666) q0; ry(1.52403189005694) q1; ry(0.877796397476269) q2; ry(0.508643300858681) q3; }\\nqreg q[4];\\ngate_RealAmplitudes(0.555621819228932,1.14319132801287,1.07379590145389,0.409370781763752,0.0165973010020706,0.508652978720279,0.300244419920286,0.136434104028988,-0.0649716942665253,0.577026156276957,0.13664098460932,1.24139060584453,0.455662122094092,0.642944089110158,0.570141938819558,0.0393162465417179,0.872843078509701,0.497896034397818,0.792675492672247,0.0302332873841969,0.448717981940666,1.52403189005694,0.877796397476269,0.508643300858681) q[0],q[1],q[2],q[3];\\n'" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + } + }, + "metadata": {}, + "execution_count": 27 + } + ] + }, + { + "cell_type": "code", + "source": [ + "!ls" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "a7ArfSyV9Xiq", + "outputId": "f06143d5-aaf0-411e-81a9-079f79e989b0" + }, + "execution_count": 28, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "data quantum_classifier.qasm sample_data\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "from google.colab import files\n", + "\n", + "files.download('quantum_classifier.qasm')" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 17 + }, + "id": "XZTU5w3x9cel", + "outputId": "6994ed13-9732-4aea-88b0-c04ddf7f33bb" + }, + "execution_count": 30, + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/plain": [ + "" + ], + "application/javascript": [ + "\n", + " async function download(id, filename, size) {\n", + " if (!google.colab.kernel.accessAllowed) {\n", + " return;\n", + " }\n", + " const div = document.createElement('div');\n", + " const label = document.createElement('label');\n", + " label.textContent = `Downloading \"${filename}\": `;\n", + " div.appendChild(label);\n", + " const progress = document.createElement('progress');\n", + " progress.max = size;\n", + " div.appendChild(progress);\n", + " document.body.appendChild(div);\n", + "\n", + " const buffers = [];\n", + " let downloaded = 0;\n", + "\n", + " const channel = await google.colab.kernel.comms.open(id);\n", + " // Send a message to notify the kernel that we're ready.\n", + " channel.send({})\n", + "\n", + " for await (const message of channel.messages) {\n", + " // Send a message to notify the kernel that we're ready.\n", + " channel.send({})\n", + " if (message.buffers) {\n", + " for (const buffer of message.buffers) {\n", + " buffers.push(buffer);\n", + " downloaded += buffer.byteLength;\n", + " progress.value = downloaded;\n", + " }\n", + " }\n", + " }\n", + " const blob = new Blob(buffers, {type: 'application/binary'});\n", + " const a = document.createElement('a');\n", + " a.href = window.URL.createObjectURL(blob);\n", + " a.download = filename;\n", + " div.appendChild(a);\n", + " a.click();\n", + " div.remove();\n", + " }\n", + " " + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "" + ], + "application/javascript": [ + "download(\"download_4991390e-5a53-4b29-ab15-96165d0de025\", \"quantum_classifier.qasm\", 1519)" + ] + }, + "metadata": {} + } + ] + }, + { + "cell_type": "code", + "source": [ + "vqc = ansatz(N_QUBITS)" + ], + "metadata": { + "id": "k2MPHTTD7lmK" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "params" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 204 + }, + "id": "6GvYf_fP2TG_", + "outputId": "b9f0011e-dac5-448b-e933-a58af1de4db4" + }, + "execution_count": 17, + "outputs": [ + { + "output_type": "error", + "ename": "NameError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mparams\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mNameError\u001b[0m: name 'params' is not defined" + ] + } + ] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "DVtOX_Ep6ve8" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file