Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ionQ Hackhaton #67

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions part1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

{
"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
}
35 changes: 35 additions & 0 deletions part1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Adnaan Chida
# [email protected]

# 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
63 changes: 63 additions & 0 deletions part2.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
Binary file added part2.pickle
Binary file not shown.
33 changes: 33 additions & 0 deletions part2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Adnaan Chida
# [email protected]

# 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