diff --git a/abp/clifford.py b/abp/clifford.py index 9dc89e9..ac4fae5 100644 --- a/abp/clifford.py +++ b/abp/clifford.py @@ -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): diff --git a/abp/graphstate.py b/abp/graphstate.py index 0bd1434..a797c5c 100644 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -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 """ diff --git a/tests/test_against_anders_and_briegel.py b/tests/test_against_anders_and_briegel.py index ba682b7..2ab9fc7 100644 --- a/tests/test_against_anders_and_briegel.py +++ b/tests/test_against_anders_and_briegel.py @@ -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) diff --git a/tests/test_against_circuit_model.py b/tests/test_against_circuit_model.py index b18a627..3601e2d 100644 --- a/tests/test_against_circuit_model.py +++ b/tests/test_against_circuit_model.py @@ -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) diff --git a/tests/test_graph.py b/tests/test_graph.py index f0190a9..a045dda 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -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()