Pete Shadbolt 8 роки тому
джерело
коміт
4438ca80c3
4 змінених файлів з 99 додано та 35 видалено
  1. +8
    -11
      abp/graphstate.py
  2. +21
    -0
      scripts/try_stabilizing.py
  3. +49
    -23
      tests/test_against_anders_and_briegel.py
  4. +21
    -1
      tests/test_against_circuit_model.py

+ 8
- 11
abp/graphstate.py Переглянути файл

@@ -167,17 +167,14 @@ class GraphState(object):

def to_stabilizer(self):
""" Get the stabilizer of this graph """
# TODO: VOPs are not implemented yet
output = ""
for a in self.adj:
for b in self.adj:
if a == b:
output += " X "
elif a in self.adj[b]:
output += " Z "
else:
output += " I "
output += "\n"
output = {a:{} for a in self.node}
for a, b in it.product(self.node, self.node):
if a == b:
output[a][b] = "X"
elif a in self.adj[b]:
output[a][b] = "Z"
else:
output[a][b] = "I"
return output

def adj_list(self):


+ 21
- 0
scripts/try_stabilizing.py Переглянути файл

@@ -0,0 +1,21 @@
import abp
import numpy as np
from anders_briegel import graphsim

def wah():
N = 10
a = graphsim.GraphRegister(N)

for i in range(1000):
if np.random.random()>0.5:
j = np.random.randint(0, N-1)
a.hadamard(j)
else:
q = np.random.randint(0, N-2)
a.cphase(q, q+1)

a.print_stabilizer()


u = abp.GraphState(xrange(2))
print u.to_stabilizer()

+ 49
- 23
tests/test_against_anders_and_briegel.py Переглянути файл

@@ -1,5 +1,6 @@
from abp import GraphState
from anders_briegel import graphsim
from abp import CircuitModel
from abp import clifford
import random
import difflib
@@ -16,6 +17,13 @@ def compare(a, b):
print bb
raise

def isequal(a, b):
""" TODO: Sketchy as you like. Remove this abomination """
aa = a.get_adj_list()
bb = b.adj_list()
return re.sub("\\s", "", aa) == re.sub("\\s", "", bb)


def test_hadamard():
""" Test hadamards """
a = graphsim.GraphRegister(1)
@@ -50,23 +58,45 @@ def test_cz_table(N=10):

clifford.use_old_cz()

for j in range(24):
a = graphsim.GraphRegister(2)
b = GraphState()
b.add_node(0)
b.add_node(1)
compare(a, b)
for i in range(24):
for j in range(24):

a.local_op(0, graphsim.LocCliffOp(j))
b.act_local_rotation(0, j)
a = graphsim.GraphRegister(2)
b = GraphState()
b.add_nodes([0, 1])

a.local_op(1, graphsim.LocCliffOp(j))
b.act_local_rotation(1, j)
a.local_op(0, graphsim.LocCliffOp(i))
b.act_local_rotation(0, i)
a.local_op(1, graphsim.LocCliffOp(j))
b.act_local_rotation(1, j)

a.cphase(0, 1)
b.act_cz(0, 1)
compare(a, b)
a.cphase(0, 1)
b.act_cz(0, 1)

compare(a, b)

for i in range(24):
for j in range(24):

a = graphsim.GraphRegister(2)
b = GraphState()
b.add_nodes([0, 1])

a.local_op(0, graphsim.LocCliffOp(10))
b.act_local_rotation(0, 10)

a.cphase(0, 1)
b.act_cz(0, 1)

a.local_op(0, graphsim.LocCliffOp(i))
b.act_local_rotation(0, i)
a.local_op(1, graphsim.LocCliffOp(j))
b.act_local_rotation(1, j)

a.cphase(0, 1)
b.act_cz(0, 1)

compare(a, b)


def test_with_cphase_gates_hadamard_only(N=10):
@@ -87,18 +117,16 @@ def test_with_cphase_gates_hadamard_only(N=10):
compare(a, b)


def test_all(N=10):
def test_all(N=3):
""" Test all gates at random """
#TODO: Currently fails. Why???

clifford.use_old_cz()

a = graphsim.GraphRegister(N)
b = GraphState()

for i in range(N):
b.add_node(i)
b = GraphState(range(N))

for i in range(100):
for i in range(1000):
if random.random()>0.5:
j = random.randint(0, N-1)
a.hadamard(j)
@@ -107,9 +135,7 @@ def test_all(N=10):
q = random.randint(0, N-2)
a.cphase(q, q+1)
b.act_cz(q, q+1)

aa = a.get_adj_list()
bb = b.adj_list()
compare(a, b)
compare(a, b)
#print b



+ 21
- 1
tests/test_against_circuit_model.py Переглянути файл

@@ -7,7 +7,7 @@ from tqdm import tqdm

REPEATS = 1

def test_single_qubit(n=1):
def test_single_qubit():
""" A multi qubit test with Hadamards only"""
for repeat in tqdm(range(REPEATS), desc="Testing against circuit model"):
g = GraphState([0])
@@ -66,3 +66,23 @@ def test_all_multiqubit(n=4):
assert g.to_state_vector() == c

assert g.to_state_vector() == c

def test_all(n=4):
""" A multi qubit test with arbitrary local rotations """
g = GraphState(range(n))
c = CircuitModel(n)
for step in tqdm(xrange(1000), "Testing a deep circuit against the circuit model"):
if random.random()>0.5:
qubit = np.random.randint(0, n - 1)
rotation = np.random.randint(0, 24 - 1)
g.act_local_rotation(qubit, rotation)
c.act_local_rotation(qubit, clifford.unitaries[rotation])
else:
a, b = np.random.randint(0, n - 1, 2)
if a != b:
g.act_cz(a, b)
c.act_cz(a, b)
assert g.to_state_vector() == c
print g.to_state_vector()
print c


Завантаження…
Відмінити
Зберегти