Skip to content

Commit a53d8f2

Browse files
added dynamic circuit element to error correction functio
n
1 parent ff57083 commit a53d8f2

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

backend/KeyGeneration.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from qiskit import QuantumCircuit
22
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
33
from math import pi
4-
from qiskit import Aer, execute
4+
from qiskit_aer import AerSimulator
55
import random
66

77
def binaryToDecimal(binary):
@@ -16,8 +16,8 @@ def binaryToDecimal(binary):
1616
def createCircuit(numUsers, QECQubits, registers):
1717
users = QuantumRegister(numUsers, "user")
1818
ancillas = QuantumRegister(QECQubits, "ancilla")
19-
cr = ClassicalRegister(registers, 'c')
20-
qc = QuantumCircuit(users, ancillas, cr)
19+
meas = ClassicalRegister(registers, 'measure')
20+
qc = QuantumCircuit(users, ancillas, meas)
2121
return qc
2222

2323
numUsers = 3
@@ -46,6 +46,12 @@ def errorX(qc, userIn, userEn):
4646
def errorCorrection(qc, userIn, userEn, QECQubit):
4747
qc.cnot(userIn, QECQubit)
4848
qc.cnot(userEn, QECQubit)
49+
qc.barrier()
50+
51+
qc.measure(QECQubit, 2)
52+
with qc.if_test((2, 1)):
53+
qc.x(userIn)
54+
4955
return qc
5056

5157
def getPrivateKeys(userIn, userEn, QECQubit, keyLength):
@@ -57,22 +63,21 @@ def getPrivateKeys(userIn, userEn, QECQubit, keyLength):
5763

5864
qc = errorCorrection(qc, userIn, userEn, QECQubit)
5965
qc.barrier()
60-
qc.measure([userIn, userEn, QECQubit], [0,1,2])
66+
qc.measure([userIn, userEn], [0,1])
6167

6268
lstIn = []
6369
lstEn = []
6470
counts = []
6571

66-
6772
while len(lstEn) <= keyLength:
68-
backend = Aer.get_backend('qasm_simulator')
69-
job_sim = execute(qc, backend, shots = 1)
70-
result = job_sim.result()
71-
count = result.get_counts(qc)
73+
sim = AerSimulator()
74+
job = sim.run(qc, shots=1)
75+
result = job.result()
76+
count = result.get_counts()
7277
counts.append(count)
73-
if (int(list(count.keys())[0][0]) == 0):
74-
lstIn.append(list(count.keys())[0][registers-userIn-1])
75-
lstEn.append(list(count.keys())[0][registers-userEn-1])
78+
79+
lstIn.append(list(count.keys())[0][registers-userIn-1])
80+
lstEn.append(list(count.keys())[0][registers-userEn-1])
7681

7782

7883
if (len(lstIn) != 0 and len(lstEn) != 0):
@@ -84,7 +89,3 @@ def getPrivateKeys(userIn, userEn, QECQubit, keyLength):
8489
keyEn = binaryToDecimal(int("".join(lstEn)))
8590

8691
return keyIn, keyEn
87-
88-
89-
result = getPrivateKeys(0, 1, 3, 16)
90-
print(result)

0 commit comments

Comments
 (0)