from blueqat import Circuit
import random
n = 10
def constant0(c):
return c
def constant1(c):
return c.x[n]
def balance(c):
r = random.randint(0, n - 1)
return c.cx[r, n]
def distinguish(oracle):
c = Circuit(n + 1).x[n].h[:]
res = oracle(c).h[:].m[:n].run(shots=100)
if res['0' * (n+1)]:
print('constant')
else:
print('balance')
distinguish(constant0)
distinguish(constant1)
distinguish(balance)
constant constant balance