Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from math import pi
from socket import socket
s = socket()
s.connect(('quantum.kelte.cc', 17171))
prog = ''
# Hadamard for the 0th qubit
prog += 'H\n'
for i in xrange(1, 8):
# Take the ith qubit
prog += 'SWAP %s\n' % i
ids = list(range(i - 1, 0, -1)) + [i] # We have 0 swapped with i
for j in xrange(len(ids)):
theta = -pi / (2 ** j) / 4
# Controlled R1 implementation (global phase changed)
prog += 'Rz %f\n' % theta
prog += 'CX %s\n' % ids[j]
prog += 'Rz %f\n' % -theta
prog += 'CX %s\n' % ids[j]
# Apply Hadamard
prog += 'H\n'
# Swap back with the 0th qubit
prog += 'SWAP %s\n' % i
# Reverse all the qubits
prog += '''SWAP 1
SWAP 6
SWAP 1
SWAP 2
SWAP 5
SWAP 2
SWAP 3
SWAP 4
SWAP 3
SWAP 7
'''
# Implement Hadamard
prog = prog.replace('H', 'Z Ry %f' % (pi / 2)).replace('\n', ' ')
s.recv(128)
s.send('%s\n' % prog.strip())
print s.recv(56).strip().decode('hex')
# ZN{Qu4NtuM_H3ll0_w0RLD_2021}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment