Last active
December 5, 2020 13:21
-
-
Save GDLMadushanka/b56749b2870272b3f0765edc1aeafe45 to your computer and use it in GitHub Desktop.
Superdense coding using the second bell state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import all necessary objects and methods for quantum circuits | |
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer | |
all_pairs = ['00','01','10','11'] | |
for pair in all_pairs: | |
# Creating the circuit with two classical bits and 2 qbits | |
qc = QuantumCircuit(2,2) | |
# Creating the entangled state | |
qc.h(1) | |
qc.cx(1,0) | |
qc.x(1) | |
qc.barrier() | |
# Alice applying Z,X gates depending on the | |
# message she needs to send. | |
# Note : - Alice's qubit - q1 | |
if pair[0] == '1': | |
qc.z(1) | |
if pair[1] == '1': | |
qc.x(1) | |
qc.barrier() | |
# Bob applying CNOT and H gate | |
# Note :- Bob's operation are always the same | |
qc.x(1) | |
qc.cx(1,0) | |
qc.h(1) | |
qc.barrier() | |
# Bob measure both qubits to retrieve the message | |
qc.measure(0,0) | |
qc.measure(1,1) | |
display(qc.draw(output='mpl',reverse_bits=True)) | |
job = execute(qc,Aer.get_backend('qasm_simulator'),shots=1024) | |
counts = job.result().get_counts(qc) | |
print("Alice sent :",pair,"Bob received :",counts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment