Skip to content

Commit 94e70de

Browse files
committed
superdense coding
1 parent 8245d07 commit 94e70de

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ Scheme for `n=2`:
3939
Scheme for `n=3`:
4040

4141
![Quantum Fourier Transform](./circuit_diagrams/05_qft.png)
42+
43+
### Superdense Coding
44+
45+
> Task. Transmit two bits of classical information between Alice and Bob using only one qubit.
46+
47+
![Superdense Coding](./circuit_diagrams/e1_superdense_coding.png)
11.1 KB
Loading

e1_superdense_coding.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'''
2+
Superdense Coding
3+
4+
Task. Transmit two bits of classical information between
5+
Alice and Bob using only one qubit.
6+
7+
'''
8+
from qiskit import IBMQ, BasicAer
9+
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
10+
11+
qr = QuantumRegister(2) # Initialize qubits
12+
cr = ClassicalRegister(2) # Initialize bits for record measurements
13+
circuit = QuantumCircuit(qr, cr)
14+
15+
# Create Bell state - Alice and Bob share an entagle qubit pair
16+
circuit.h(qr[0])
17+
circuit.cx(qr[0], qr[1])
18+
19+
circuit.barrier()
20+
21+
# Apply Quantum operations
22+
# I x I -> Alice will get 00
23+
# X x I -> Alice will get 01
24+
# Z x I -> Alice will get 10
25+
# (XZ) x I -> Alice will get 11
26+
circuit.x(qr[0])
27+
circuit.z(qr[0])
28+
29+
circuit.barrier()
30+
31+
# Apply Hadamard to qubit 0 - Take qubit 0 out of superposition
32+
circuit.cx(qr[0], qr[1])
33+
circuit.h(qr[0])
34+
35+
circuit.barrier()
36+
37+
# Measurement
38+
circuit.measure(qr, cr)
39+
40+
# Run our circuit with local simulator
41+
backend = BasicAer.get_backend('qasm_simulator')
42+
shots = 1024
43+
results = execute(circuit, backend=backend, shots=shots).result()
44+
answer = results.get_counts()
45+
print(answer)
46+
# Measurement is 11

0 commit comments

Comments
 (0)