diff --git a/abp/graphstate.py b/abp/graphstate.py index 87e65a5..91d2c35 100644 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -144,10 +144,12 @@ class GraphState(object): def toggle_edges(self, a, b): """ Toggle edges between vertex sets a and b """ + # TODO: i'm pretty sure this is just a single-line it.combinations or equiv done = set() for i, j in it.product(a, b): - if i == j and not (i, j) in done: - done.add((i, j), (j, i)) + if i != j and not (i, j) in done: + done.add((i, j)) + done.add((j, i)) self.toggle_edge(i, j) def measure_x(self, node, result): @@ -156,9 +158,11 @@ class GraphState(object): return 0 # Pick a vertex - friend = next(self.adj[node].iterkeys()) + #friend = next(self.adj[node].iterkeys()) + # TODO this is enforced determinism for testing purposes + friend = sorted(self.adj[node].keys())[0] - # TODO: yuk yuk yuk + # Update the VOPs. TODO: pretty ugly if result: # Do a z on all ngb(vb) \ ngb(v) \ {v}, and some other stuff self.act_local_rotation(node, "pz") @@ -171,7 +175,7 @@ class GraphState(object): for n in set(self.adj[node]) - set(self.adj[friend]) - {friend}: self.act_local_rotation(n, "pz") - # TODO: Yuk. Just awful! + # Toggle the edges. TODO: Yuk. Just awful! a = set(self.adj[node].keys()) b = set(self.adj[friend].keys()) self.toggle_edges(a, b) diff --git a/tests/dummy.py b/tests/dummy.py index 878aa07..2d9ef3d 100644 --- a/tests/dummy.py +++ b/tests/dummy.py @@ -1,5 +1,6 @@ from abp import GraphState, clifford from anders_briegel import graphsim +import numpy as np def random_state(N=10, messy=True): """ A state to test on """ diff --git a/tests/test_measurement_against_anders_and_briegel.py b/tests/test_measurement_against_anders_and_briegel.py index c4633b9..12f95aa 100644 --- a/tests/test_measurement_against_anders_and_briegel.py +++ b/tests/test_measurement_against_anders_and_briegel.py @@ -4,7 +4,7 @@ import numpy as np from tqdm import tqdm import dummy -N = 2 +N = 10 REPEATS = 10 m = {1: graphsim.lco_X, 2: graphsim.lco_Y, 3: graphsim.lco_Z} @@ -21,13 +21,25 @@ def _test_multiqubit_measurement_pz(): #assert a.to_json() == b.to_json(), a -def test_multiqubit_pz(): - for measurement in (3, 2,): +def test_2qubit(): + """ Relentless testing of measurements """ + for measurement in (3, 2, 1): for outcome in (0, 1): a, b = dummy.bell() a.measure(0, str(measurement), outcome) b.measure(0, m[measurement], None, outcome) - print a.to_json() - print b.to_json() + assert a == b, "FUCK" + #print a.to_json() + #print b.to_json() assert a == b, (measurement, outcome) +def test_multiqubit(): + """ Relentless testing of measurements """ + for measurement in (1,): + for i in tqdm(range(1000), "Testing {} measurement".format(measurement)): + for outcome in (0, 1): + a, b = dummy.random_state(N, messy=False) + a.measure(0, str(measurement), outcome) + b.measure(0, m[measurement], None, outcome) + assert a == b, (measurement, outcome) +