Quantum Teleportation Part III

Posted by on January 2, 2025

Believe it or not, even with their strict limitations, the fairly simplistic functions from the last post are sufficient building blocks to demonstrate a simple quantum circuit. Now we just have to declare the necessary quantum gates and initialize the three input qubits and we are ready to actually “build” the circuit.

This is the matrix definition of the quantum gates needed (see the drawing in the first post, “I” is needed to expand the circuit to more bits as all the gates have either a one or two bit input):

X=[[0,1],[1,0]]
Z=[[1,0],[0,-1]]
I=[[1,0],[0,1]]
H=[[1/sqrt(2),1/sqrt(2)],[1/sqrt(2),-1/sqrt(2)]]
CNOT=[[1,0,0,0],[0,1,0,0],[0,0,0,1],[0,0,1,0]]

The usual suspects (aka “Alice” and “Bob”) can now start doing their qubit dance routine. Let us give Alice a nice little qubit, then initialize the inputs with it (other inputs are zeroed):

#Alice qubit
q=[[-1/sqrt(2)],[-1/sqrt(2)]]
print("Alice qubit:",q)

#Initialize inputs
q=[q[0],[0],[0],[0],q[1],[0],[0],[0]]

Creating the circuit:

#Build circuit
U=kron(I,kron(H,I))
U=mult(kron(I,CNOT),U)
U=mult(kron(CNOT,I),U)
U=mult(kron(H,kron(I,I)),U)

Running the circuit on the three inputs:

#Apply circuit
q=mult(U,q)

Alice now measures her qubits, the result will be made available to Bob:

#Alice measurements
b0=qbit(0,M(q))
q=qbitset(0,b0,q)
b1=qbit(1,M(q))
q=qbitset(1,b1,q)
print("Alice measurements:",b0,b1)

Bob now, based on the measurements from Alice, can do some operations on his entangled qubit (using a small one qubit input circuit, finally turning his qubit into something matching the one Alice started with):

#Bob qubit
r=[[0],[0]]
for i in range(len(q)):
  if i&1==1:
    r[1][0]+=q[i][0]
  else:
    r[0][0]+=q[i][0]

#Conditionally apply X and/or Z
if b1==1:
  r=mult(X,r)
if b0==1:
  r=mult(Z,r)
print("Bob qubit:",r)

Comments are closed.