Browse Source

Seems to be okay against anders & briegel

master
Pete Shadbolt 8 years ago
parent
commit
9854bad286
5 changed files with 46 additions and 15 deletions
  1. +5
    -2
      abp/clifford.py
  2. +4
    -6
      abp/graphstate.py
  3. +5
    -5
      tests/test_against_anders_and_briegel.py
  4. +16
    -2
      tests/test_against_circuit_model.py
  5. +16
    -0
      tests/test_graph.py

+ 5
- 2
abp/clifford.py View File

@@ -53,7 +53,7 @@ def find_cz(bond, c1, c2, commuters, state_table, ab_cz_table):

def compose_u(decomposition):
""" Get the unitary representation of a particular decomposition """
matrices = ({"x": qi.sqx, "z": qi.msqz}[c] for c in decomposition)
matrices = ({"x": qi.msqx, "z": qi.sqz}[c] for c in decomposition)
output = reduce(np.dot, matrices, np.eye(2, dtype=complex))
return qi.normalize_global_phase(output)

@@ -65,8 +65,11 @@ def get_unitaries():

def get_by_name(unitaries):
""" Get a lookup table of cliffords by name """
return {name: find_clifford(u, unitaries)
a = {name: find_clifford(u, unitaries)
for name, u in qi.by_name.items()}
b = {get_name(i): i for i in range(24)}
a.update(b)
return a


def get_conjugation_table(unitaries):


+ 4
- 6
abp/graphstate.py View File

@@ -77,13 +77,11 @@ class GraphState(object):
for i, j in it.combinations(self.ngbh[v], 2):
self.toggle_edge(i, j)

# Update VOPs: TODO check ordering and replace by
# self.act_local_rotation
self.vops[v] = clifford.times_table[
self.vops[v]][clifford.by_name["sqx"]]
msqx_h = clifford.conjugation_table[clifford.by_name["msqx"]]
sqz_h = clifford.conjugation_table[clifford.by_name["sqz"]]
self.vops[v] = clifford.times_table[self.vops[v], msqx_h]
for i in self.ngbh[v]:
self.vops[i] = clifford.times_table[
self.vops[i]][clifford.by_name["msqz"]]
self.vops[i] = clifford.times_table[self.vops[i], sqz_h]

def act_local_rotation(self, a, op):
""" Act a local rotation """


+ 5
- 5
tests/test_against_anders_and_briegel.py View File

@@ -44,7 +44,7 @@ def test_local_rotations():
compare(a, b)


def _test_cz_table():
def test_cz_table():
""" Test the CZ table """
for j in range(24):
a = graphsim.GraphRegister(2)
@@ -65,8 +65,8 @@ def _test_cz_table():



def test_1():
""" TODO: this one always succeeds """
def test_with_cphase_gates_hadamard_only():
""" Hadamrds and CPHASEs, deterministic """
N=10

a = graphsim.GraphRegister(N)
@@ -84,8 +84,8 @@ def test_1():
compare(a, b)


def test_2():
""" TODO: This one fails at the moment - EVEN THOUGH I USE THEIR TABLE!! """
def test_all():
""" Test all gates at random """
N=10

a = graphsim.GraphRegister(N)


+ 16
- 2
tests/test_against_circuit_model.py View File

@@ -6,7 +6,21 @@ import random

REPEATS = 10

def test_hadamard_only_multiqubit(n=6):
def test_single_qubit(n=1):
""" A multi qubit test with Hadamards only"""
for repeat in range(REPEATS):
g = GraphState([0])
c = CircuitModel(1)

for i in range(100):
op = random.randint(0, 23)
g.act_local_rotation(0, op)
c.act_local_rotation(0, clifford.unitaries[op])

assert g.to_state_vector() == c


def _test_hadamard_only_multiqubit(n=6):
""" A multi qubit test with Hadamards only"""
for qqq in range(REPEATS):
g = GraphState(range(n))
@@ -27,7 +41,7 @@ def test_hadamard_only_multiqubit(n=6):
assert g.to_state_vector() == c


def test_all_multiqubit(n=4):
def _test_all_multiqubit(n=4):
""" A multi qubit test with arbitrary local rotations """
g = GraphState(range(n))
c = CircuitModel(n)


+ 16
- 0
tests/test_graph.py View File

@@ -27,6 +27,22 @@ def test_local_complementation():
# TODO: test VOP conditions


#def test_remove_vop_simple():
#""" Test that removing VOPs really works """
#g = GraphState(xrange(2))
#print g
#g.remove_vop(0, 1)
#print g
#assert g.vops[0] == clifford.by_name["identity"]
#g.remove_vop(1, 1)
#assert g.vops[1] == clifford.by_name["identity"]
#g.remove_vop(2, 1)
#assert g.vops[2] == clifford.by_name["identity"]
#g.remove_vop(0, 1)
#assert g.vops[0] == clifford.by_name["identity"]



def test_remove_vop():
""" Test that removing VOPs really works """
g = demograph()


Loading…
Cancel
Save