Commit 127b93bc authored by Abhishek's avatar Abhishek

.

parent c5992180
......@@ -546,6 +546,7 @@
"outputs": [],
"source": [
"x = np.array([0.53896774, 0.79503606, 0.27826503, 0.0])\n",
"\n",
"ang = get_angles(x)\n",
"\n",
"@qml.qnode(dev)\n",
......
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# **Quantum Computing: Lab 10**\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this lab we are going to work on creating Error Correction Codes on Quantum Circuits."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before you begin, execute this cell to import numpy and packages from the D-Wave Ocean suite, and all necessary functions for the gate-model framework you are going to use, whether that is the Forest SDK or Qiskit. In the case of Forest SDK, it also starts the qvm and quilc servers."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Available frameworks:\n",
"Qiskit\n",
"D-Wave Ocean\n"
]
}
],
"source": [
"%run -i \"assignment_helper_QML.py\"\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# **Hamming Code** #"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0 1 1 1 0 0 0]]\n",
"[[0 1 1]]\n",
"[[0 1 1]]\n"
]
}
],
"source": [
"import numpy as np\n",
"import math\n",
"\n",
"G = np.array([[1, 0, 0, 0, 1, 1, 1],\n",
" [0, 1, 0, 0, 1, 1, 0],\n",
" [0, 0, 1, 0, 1, 0, 1],\n",
" [0, 0, 0, 1, 0, 1, 1]])\n",
"# G corrects one error\n",
"\n",
"\n",
"# Codewords are row space(mod 2)\n",
"# Encode: mG\n",
"\n",
"# Suppose is m = [1, 1, 0, 1]\n",
"m = np.array([[0, 1, 1, 1]])\n",
"\n",
"\n",
"print(np.matmul(m,G) % 2)\n",
"\n",
"e = np.array([[0, 0, 0, 0, 0, 0, 0]])\n",
"e[0,3] = 1\n",
"\n",
"H = np.array([[1, 1, 1],\n",
" [1, 1, 0],\n",
" [1, 0, 1],\n",
" [0, 1, 1],\n",
" [1, 0, 0],\n",
" [0, 1, 0],\n",
" [0, 0, 1]])\n",
"\n",
"print(np.matmul((np.matmul(m,G) + e),H)%2)\n",
"print(np.matmul(e,H)%2)\n",
"# and hence we know that the error is at ith position of e\n",
"\n",
"#print(np.matmul(e,H))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# **Shor's Bit Error Correction Code** #"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# **Shor's Phase Error Correction Code** #"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# **Shor's 9-Qubit Bit-Phase Error Correction Code*** #"
]
},
{
"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.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# **Quantum Computing: Lab 10**\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this lab we are going to work on creating Error Correction Codes on Quantum Circuits."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before you begin, execute this cell to import numpy and packages from the D-Wave Ocean suite, and all necessary functions for the gate-model framework you are going to use, whether that is the Forest SDK or Qiskit. In the case of Forest SDK, it also starts the qvm and quilc servers."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Available frameworks:\n",
"Qiskit\n",
"D-Wave Ocean\n"
]
}
],
"source": [
"%run -i \"assignment_helper_QML.py\"\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# **B92 Protocol** #"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 0 0 0 1 1 1 0 0 1 0 0 0 1 1 1 0 0 0 1 1 0 1 1 0 1 0 0 0 0 1 0 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 0 1 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 0 1 1 0 0 1 0 0 1 0 1\n",
"+ 0 0 0 + + + 0 0 + 0 0 0 + + + 0 0 0 + + 0 + + 0 + 0 0 0 0 + 0 + 0 + + 0 + + + 0 + + 0 + + 0 + + + + 0 + 0 + + + + 0 0 0 0 0 + 0 0 + + 0 + + 0 + 0 0 + 0 0 + + 0 0 0 + + 0 0 + 0 + 0 0 + + + + 0 + + 0 + + + 0 + 0 0 + + 0 + 0 0 0 + + 0 0 + 0 0 + 0 +\n",
"0 0 1 0 0 1 1 1 1 0 1 1 0 0 0 1 0 1 1 1 1 0 0 1 0 1 0 1 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 1 1 1 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 1 0 0 0 1 0 0 0 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 1 1 1\n",
"R R D R R D D D D R D D R R R D R D D D D R R D R D R D D D D R D D R R D R D R D R R D D D D D R D D R R D D D D D R R R R D R D D R R D D D D R R R D R D R R R D R R R R D R D D D D R R D D R D D D D R D D R D D D R R R R R R D R R D D R R D D D\n",
"1 0 1 0 1 0 0 0 1 1 1 1 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n",
"1 0 1 0 1 0 0 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 1 1 0 0 1 0\n",
"1 0 1 0 1 0 0 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 1 1 0 0 1 0\n",
"40\n"
]
}
],
"source": [
"# -*- coding: utf-8 -*-\n",
"\"\"\"\n",
"Created on Fri Sep 21 08:37:50 2018\n",
"\n",
"@author: aawasthi\n",
"\"\"\"\n",
"\n",
"import numpy as np\n",
"\n",
"def createQubits_Alice(Bits):\n",
" Qubits = []\n",
" for i in range(len(Bits)):\n",
" if Bits[i] == 0:\n",
" Qubits.append('0')\n",
" else:\n",
" Qubits.append('+')\n",
" return Qubits\n",
"\n",
"\n",
"def createBases_Bob(Bits):\n",
" Bases = []\n",
" for i in range(len(Bits)):\n",
" if Bits[i] == 0:\n",
" Bases.append('R')\n",
" else:\n",
" Bases.append('D')\n",
" return Bases\n",
"\n",
"def measureBob(Qubits,Bob_Bases):\n",
" Bob_Measurement = [0] * len(Qubits)\n",
" for i in range(len(Qubits)):\n",
" if Bob_Bases[i] == 'R' and (Qubits[i] == '0' or Qubits[i] == '1'):\n",
" Bob_Measurement[i] = int(Qubits[i])\n",
" elif Bob_Bases[i] == 'D' and Qubits[i] == '+':\n",
" Bob_Measurement[i] = int(0)\n",
" elif Bob_Bases[i] == 'R' and Qubits[i] == '+':\n",
" if np.random.rand() < 0.5:\n",
" Bob_Measurement[i] = int(0)\n",
" else:\n",
" Bob_Measurement[i] = int(1)\n",
" elif Bob_Bases[i] == 'D' and (Qubits[i] == '0' or Qubits[i] == '1'):\n",
" if np.random.rand() < 0.5:\n",
" Bob_Measurement[i] = int(0)\n",
" else:\n",
" Bob_Measurement[i] = int(1)\n",
" return np.asarray(Bob_Measurement)\n",
"\n",
"\n",
" \n",
"bitLength = 128\n",
"\n",
"\n",
"Alice_Bits = np.random.randint(0,2,bitLength)\n",
"print(' '.join(map(str, Alice_Bits)))\n",
"Qubits = createQubits_Alice(Alice_Bits)\n",
"print(' '.join(Qubits))\n",
"\n",
"\n",
"Bob_Bits = np.random.randint(0,2,bitLength)\n",
"print(' '.join(map(str, Bob_Bits)))\n",
"Bob_Bases = createBases_Bob(Bob_Bits)\n",
"print(' '.join(Bob_Bases))\n",
"Bob_Measurement = measureBob(Qubits,Bob_Bases)\n",
"print(' '.join(map(str, Bob_Measurement)))\n",
"\n",
"locations = np.where(Bob_Measurement==1)[0]\n",
"AliceSecretKey = Alice_Bits[locations]\n",
"BobSecretKey = 1-Bob_Bits[locations]\n",
"print(' '.join(map(str, AliceSecretKey)))\n",
"print(' '.join(map(str, BobSecretKey)))\n",
"\n",
"print(len(AliceSecretKey))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# **BB84 Protocol** #"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# **E91 Protocol** #"
]
}
],
"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.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment