From 99b01e2b14d6c9c43d8322373b2724abbbcc08df Mon Sep 17 00:00:00 2001 From: adnaanchida <64286274+adnaanchida@users.noreply.github.com> Date: Sat, 28 Jan 2023 14:22:31 -0600 Subject: [PATCH 1/7] Add files via upload --- part1.ipynb | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ part1.py | 32 +++++++++++++++++++++++++ part2.ipynb | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ part2.pickle | Bin 0 -> 497 bytes part2.py | 30 +++++++++++++++++++++++ 5 files changed, 191 insertions(+) create mode 100644 part1.ipynb create mode 100644 part1.py create mode 100644 part2.ipynb create mode 100644 part2.pickle create mode 100644 part2.py diff --git a/part1.ipynb b/part1.ipynb new file mode 100644 index 0000000..e49d821 --- /dev/null +++ b/part1.ipynb @@ -0,0 +1,66 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "dd6bee73-2f0f-427c-afa8-c14089574323", + "metadata": {}, + "outputs": [], + "source": [ + "# part 1\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" + ] + } + ], + "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/part1.py b/part1.py new file mode 100644 index 0000000..92b5a38 --- /dev/null +++ b/part1.py @@ -0,0 +1,32 @@ +# part 1 + +n=len(dataset) +mse=0 +gatecount=0 + +# Functions 'encode' and 'decode' are dummy. +def encode(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 + +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 \ No newline at end of file diff --git a/part2.ipynb b/part2.ipynb new file mode 100644 index 0000000..6f68ccb --- /dev/null +++ b/part2.ipynb @@ -0,0 +1,63 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "741b396e-1c49-4f23-a46d-fa47f4ca2f46", + "metadata": {}, + "outputs": [], + "source": [ + "# part 2\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", + " #load 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" + ] + } + ], + "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/part2.pickle b/part2.pickle new file mode 100644 index 0000000000000000000000000000000000000000..3065aa7e6212c84960ac864c9f6e12c35889815f GIT binary patch literal 497 zcmY*Wy-ve05H1x^3RFS}1VUoyRtEA4Ac54O{0PK~PPStjLt?kN1eE~^1~xB<<9T=$ zCT4aPE=i+;C0q9QW8Zgvnt%VAYm~!pDwB=_UQ})}tT*IaM-@bGwD(MpL0edKUc^5+rABYGIExSrvAbAG;jxov6CVOjLZ!aAD>fV2b8eR z8pT}gV@O3hq%*$^q2c(*Nodf_rEkGFm)x>CR;cfd(ip_X>WU)YKHPBlA?e?PXEB68tEig}Y@f&cbAHd05q#jcp QP|jwliwn4faw$*-zoEs#wg3PC literal 0 HcmV?d00001 diff --git a/part2.py b/part2.py new file mode 100644 index 0000000..e84ac4e --- /dev/null +++ b/part2.py @@ -0,0 +1,30 @@ +# part 2 + +def encode(image): + circuit=cirq.Circuit() + if image[0][0]==0: + circuit.append(cirq.rx(np.pi).on(cirq.LineQubit(0))) + return circuit + + +def run_part2(image): + + #load the quantum classifier circuit + with open('part2.pickle', 'rb') as f: + classifier=pickle.load(f) + + #encode image into circuit + circuit=encode(image) + + #append with classifier circuit + + circuit.append(classifier) + + #simulate circuit + histogram=simulate(circuit) + + #convert histogram to category + label=histogram_to_category(histogram) + + return circuit + return label From 60a40e710af6f47e05caa1d3827b3a89468b3119 Mon Sep 17 00:00:00 2001 From: adnaanchida <64286274+adnaanchida@users.noreply.github.com> Date: Sat, 28 Jan 2023 14:46:24 -0600 Subject: [PATCH 2/7] Update part1.ipynb --- part1.ipynb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/part1.ipynb b/part1.ipynb index e49d821..c5f8842 100644 --- a/part1.ipynb +++ b/part1.ipynb @@ -1,3 +1,6 @@ +# Adnaan Chida +# adnaan.chida@gmail.com + { "cells": [ { From a76e80134c1d6fec2c9a6f3cfb5a0c37f9e2e3f7 Mon Sep 17 00:00:00 2001 From: adnaanchida <64286274+adnaanchida@users.noreply.github.com> Date: Sat, 28 Jan 2023 14:46:44 -0600 Subject: [PATCH 3/7] Update part1.ipynb --- part1.ipynb | 3 --- 1 file changed, 3 deletions(-) diff --git a/part1.ipynb b/part1.ipynb index c5f8842..e49d821 100644 --- a/part1.ipynb +++ b/part1.ipynb @@ -1,6 +1,3 @@ -# Adnaan Chida -# adnaan.chida@gmail.com - { "cells": [ { From 4a4effce4e447c846142c4c2ec2e4a9c08621410 Mon Sep 17 00:00:00 2001 From: adnaanchida <64286274+adnaanchida@users.noreply.github.com> Date: Sat, 28 Jan 2023 14:47:38 -0600 Subject: [PATCH 4/7] Update part1.ipynb --- part1.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/part1.ipynb b/part1.ipynb index e49d821..3b297ee 100644 --- a/part1.ipynb +++ b/part1.ipynb @@ -1,3 +1,5 @@ +"# Adnaan Chida" +"# adnaan.chida@gmail.com" { "cells": [ { From 0347dd47fa2d6b40ff6f982aed71ecbac14295b5 Mon Sep 17 00:00:00 2001 From: adnaanchida <64286274+adnaanchida@users.noreply.github.com> Date: Sat, 28 Jan 2023 14:47:50 -0600 Subject: [PATCH 5/7] Update part1.ipynb --- part1.ipynb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/part1.ipynb b/part1.ipynb index 3b297ee..ca2bbca 100644 --- a/part1.ipynb +++ b/part1.ipynb @@ -1,5 +1,4 @@ -"# Adnaan Chida" -"# adnaan.chida@gmail.com" + { "cells": [ { From 31de193e77c8870ce93c019da390f76993eb8700 Mon Sep 17 00:00:00 2001 From: adnaanchida <64286274+adnaanchida@users.noreply.github.com> Date: Sat, 28 Jan 2023 14:48:16 -0600 Subject: [PATCH 6/7] Update part2.py --- part2.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/part2.py b/part2.py index e84ac4e..d0407cb 100644 --- a/part2.py +++ b/part2.py @@ -1,3 +1,6 @@ +# Adnaan Chida +# adnaan.chida@gmail.com + # part 2 def encode(image): From fe21d350709d39ca638ffbd4f00be9c41aaa9b80 Mon Sep 17 00:00:00 2001 From: adnaanchida <64286274+adnaanchida@users.noreply.github.com> Date: Sat, 28 Jan 2023 14:49:23 -0600 Subject: [PATCH 7/7] Update part1.py --- part1.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/part1.py b/part1.py index 92b5a38..1e07fd1 100644 --- a/part1.py +++ b/part1.py @@ -1,3 +1,6 @@ +# Adnaan Chida +# adnaan.chida@gmail.com + # part 1 n=len(dataset) @@ -29,4 +32,4 @@ def run_part1(image): #reconstruct the image image_re=decode(histogram) - return circuit,image_re \ No newline at end of file + return circuit,image_re