superdense with cirq
This commit is contained in:
parent
e912506375
commit
5f63a19532
24
02_cirq.py
24
02_cirq.py
@ -1,13 +1,26 @@
|
||||
import cirq
|
||||
|
||||
def main():
|
||||
|
||||
def superdense():
|
||||
# Pick a qubit.
|
||||
qubit = cirq.GridQubit(0, 0)
|
||||
q1 = cirq.GridQubit(0, 0)
|
||||
q2 = cirq.GridQubit(1, 0)
|
||||
|
||||
# Create a circuit
|
||||
circuit = cirq.Circuit.from_ops(
|
||||
cirq.X(qubit)**0.5, # Square root of NOT.
|
||||
cirq.measure(qubit, key='m') # Measurement.
|
||||
cirq.H(q1),
|
||||
cirq.CNOT(q1, q2), # Alice prepares the Bell state,
|
||||
# #################### Alice sends q2 to Bob,
|
||||
# Uncomment below lines depending on what you want to send
|
||||
# cirq.I(q1), # Alice wants to send 00 with superdense coding
|
||||
# cirq.X(q1), # Alice wants to send 01 with superdense coding
|
||||
cirq.Z(q1), # Alice wants to send 10 with superdense coding
|
||||
# cirq.X(q1), cirq.Z(q1), # Alice wants to send 11 with superdense coding
|
||||
# ################# Some time later...
|
||||
cirq.CNOT(q1, q2),
|
||||
cirq.H(q1), # Bob reverses the encoding
|
||||
cirq.measure(q1, key='q1'), # Measurement.
|
||||
cirq.measure(q2, key='q2') # Measurement.
|
||||
)
|
||||
print("Circuit:")
|
||||
print(circuit)
|
||||
@ -18,5 +31,6 @@ def main():
|
||||
print("Results:")
|
||||
print(result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
superdense()
|
||||
|
Loading…
Reference in New Issue
Block a user