Commit 29784826 authored by Abhishek's avatar Abhishek

-

parent ac2f9e76
......@@ -89,7 +89,7 @@
"# **Shor's Bit Error Correction Code** #\n",
"\n",
"\n",
"<img src=\"images/bitCorrection.png\" style=\"width: 600px;\"/>"
"<img src=\"images/qubit.png\" style=\"width: 600px;\"/>"
]
},
{
......@@ -240,7 +240,7 @@
"# **Shor's Phase Error Correction Code** #\n",
"\n",
"\n",
"<img src=\"images/phaseCorrection.png\" style=\"width: 400px;\"/>"
"<img src=\"images/phase.png\" style=\"width: 700px;\"/>"
]
},
{
......@@ -358,6 +358,13 @@
"# **EXERCISE: Build Shor's 9-Qubit Bit-Phase Error Correction Code** #"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"images/shors9.png\" style=\"width: 800px;\"/>"
]
},
{
"cell_type": "code",
"execution_count": null,
......
......@@ -51,32 +51,10 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 1 1 0 1 1 0 1 1 1 0 0 1 1 0 1 1 0 0 1\n",
"+ + + 0 + + 0 + + + 0 0 + + 0 + + 0 0 +\n",
"0 1 0 0 0 0 1 0 1 0 0 1 1 0 1 1 0 1 0 0\n",
"R D R R R R D R D R R D D R D D R D R R\n",
"0 0 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 1\n",
"1 1 1 0 1 1\n",
"1 1 1 0 1 1\n",
"6\n"
]
}
],
"outputs": [],
"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",
......@@ -88,7 +66,6 @@
" Qubits.append('+')\n",
" return Qubits\n",
"\n",
"\n",
"def createBases_Bob(Bits):\n",
" Bases = []\n",
" for i in range(len(Bits)):\n",
......@@ -118,30 +95,78 @@
" return np.asarray(Bob_Measurement)\n",
"\n",
"\n",
" \n",
"bitLength = 20\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Alice_Bits: 1 1 0 1 1 0 0 1 1 1 0 0 1 0 0 0 1 1 0 1 1 0 1 0 1 0 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 1 1 0 0 0 1 0 1 0\n",
"Qubits: + + 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"
]
}
],
"source": [
"bitLength = 50\n",
"\n",
"Alice_Bits = np.random.randint(0,2,bitLength)\n",
"print(' '.join(map(str, Alice_Bits)))\n",
"print('Alice_Bits: ',' '.join(map(str, Alice_Bits)))\n",
"Qubits = createQubits_Alice(Alice_Bits)\n",
"print(' '.join(Qubits))\n",
"\n",
"\n",
"print('Qubits: ',' '.join(Qubits))"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Bob_Bits: 0 1 0 1 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 0 1 1 1 1 1 0 1 0 0 0 1 1 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0\n",
"Bob_Bases: R D R D D R D R D R D R R R D R R D R D R D D D D D R D R R R D D D R R D R R R R R D R D R R R D R\n",
"Bob_Measurement: 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0\n"
]
}
],
"source": [
"Bob_Bits = np.random.randint(0,2,bitLength)\n",
"print(' '.join(map(str, Bob_Bits)))\n",
"print('Bob_Bits: ',' '.join(map(str, Bob_Bits)))\n",
"Bob_Bases = createBases_Bob(Bob_Bits)\n",
"print(' '.join(Bob_Bases))\n",
"print('Bob_Bases: ',' '.join(Bob_Bases))\n",
"Bob_Measurement = measureBob(Qubits,Bob_Bases)\n",
"print(' '.join(map(str, Bob_Measurement)))\n",
"\n",
"print('Bob_Measurement: ',' '.join(map(str, Bob_Measurement)))\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Locations: 0 6 10 14 21 25 26 29 31 34 40 46\n",
"Alice_Secret_Key: 1 0 0 0 0 0 1 1 0 1 1 1\n",
"Bob_Secret_Key: 1 0 0 0 0 0 1 1 0 1 1 1\n"
]
}
],
"source": [
"locations = np.where(Bob_Measurement==1)[0]\n",
"print('Locations: ',' '.join(map(str, locations)))\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))"
"print('Alice_Secret_Key: ',' '.join(map(str, AliceSecretKey)))\n",
"print('Bob_Secret_Key: ',' '.join(map(str, BobSecretKey)))"
]
},
{
......@@ -152,11 +177,168 @@
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"# **E91 Protocol** #"
"import numpy as np\n",
"\n",
"def createBases(bitLength):\n",
" Bases = []\n",
" for i in range(bitLength):\n",
" if np.random.rand() < 0.5:\n",
" Bases.append('R')\n",
" else:\n",
" Bases.append('D')\n",
" return Bases\n",
"\n",
" \n",
"def Measurement(Qubits,Bases):\n",
" Measurement = []\n",
" for i in range(len(Qubits)):\n",
" if Bases[i] == 'R' and (Qubits[i] == '0' or Qubits[i] == '1'):\n",
" Measurement.append(Qubits[i])\n",
" elif Bases[i] == 'D' and (Qubits[i] == '+' or Qubits[i] == '-'):\n",
" Measurement.append(Qubits[i])\n",
" elif Bases[i] == 'R' and (Qubits[i] == '+' or Qubits[i] == '-'):\n",
" if np.random.rand() < 0.5:\n",
" Measurement.append('0')\n",
" else:\n",
" Measurement.append('1')\n",
" elif Bases[i] == 'D' and (Qubits[i] == '0' or Qubits[i] == '1'):\n",
" if np.random.rand() < 0.5:\n",
" Measurement.append('+')\n",
" else:\n",
" Measurement.append('-')\n",
" return np.asarray(Measurement)\n",
"\n",
"\n",
"def checkSameBases(Alice_Bases, Bob_Bases):\n",
" locations = []\n",
" for i in range(len(Alice_Bases)):\n",
" if Alice_Bases[i] == Bob_Bases[i]:\n",
" locations.append(i)\n",
" return locations\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Alice_Bits: 1 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0\n",
"Alice_Bases: D R R D D R R D R D D D R D R D D R D R D R D R R R R R R D R D D D R D R R D D D R R R D D D R R R\n",
"Alice_Measurement: - 1 1 + + 0 0 - 1 + - - 1 + 0 + + 1 + 1 + 0 + 0 1 0 0 1 0 - 1 + - - 0 + 1 1 - - - 0 0 0 + - + 0 1 0\n"
]
}
],
"source": [
"bitLength = 50\n",
"\n",
"Alice_Bits = ''.join(map(str, np.random.randint(0,2,bitLength)))\n",
"print('Alice_Bits: ',' '.join(Alice_Bits))\n",
"Alice_Bases = createBases(bitLength)\n",
"print('Alice_Bases: ',' '.join(Alice_Bases))\n",
"Alice_Measurement = Measurement(Alice_Bits,Alice_Bases)\n",
"print('Alice_Measurement:',' '.join(Alice_Measurement))\n",
"qubitsSentByAlice = Alice_Measurement"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Eve_Bases: R D R D D R R D D R R D D R D R R R R D D R R D D D R D D R D D R R R D R D R R D D R D D D D D D R\n",
"Eve_Measurement: 1 + 1 + + 0 0 - + 1 0 - + 1 - 1 1 1 0 + + 0 1 + + - 0 - - 0 - + 1 0 0 + 1 - 1 0 - + 0 - + - + + + 0\n"
]
}
],
"source": [
"Eve_Bases = createBases(bitLength)\n",
"print('Eve_Bases: ',' '.join(Eve_Bases))\n",
"Eve_Measurement = Measurement(qubitsSentByAlice,Eve_Bases)\n",
"print('Eve_Measurement: ',' '.join(map(str, Eve_Measurement)))\n",
"qubitsSentByAlice = Eve_Measurement"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Bob_Bases: R R R R R R R D D R R D D D D R R R R D D D R D R D R R D D R R D D R D R D D R D D R D D R R R R D\n",
"Bob_Measurement: 1 0 1 0 0 0 0 - + 1 0 - + + - 1 1 1 0 + + - 1 + 0 - 0 0 - + 1 1 - - 0 + 1 - + 0 - + 0 - + 1 1 1 0 +\n"
]
}
],
"source": [
"Bob_Bases = createBases(bitLength)\n",
"print('Bob_Bases: ',' '.join(Bob_Bases))\n",
"Bob_Measurement = Measurement(qubitsSentByAlice, Bob_Bases)\n",
"print('Bob_Measurement: ',' '.join(map(str, Bob_Measurement)))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Locations: 1 2 5 6 7 11 13 17 20 24 26 27 29 30 32 33 34 35 36 38 40 42 44 47 48\n"
]
}
],
"source": [
"locations = checkSameBases(Alice_Bases, Bob_Bases)\n",
"print('Locations: ',' '.join(map(str, locations)))\n",
"AliceSecretKey = Alice_Measurement[locations]"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Alice_Secret_Key: 1 1 0 0 - - + 1 + 1 0 1 - 1 - - 0 + 1 - - 0 + 0 1\n",
"Bob_Secret_Key: 0 1 0 0 - - + 1 + 0 0 0 + 1 - - 0 + 1 + - 0 + 1 0\n"
]
}
],
"source": [
"BobSecretKey = Bob_Measurement[locations]\n",
"print('Alice_Secret_Key: ',' '.join(map(str, AliceSecretKey)))\n",
"print('Bob_Secret_Key: ',' '.join(map(str, BobSecretKey)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
......
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