Looks like nondeterminism in `next(d.iterkeys())` was breaking consistency with A&B. Next up: switching determinism on or off.master
| @@ -144,10 +144,12 @@ class GraphState(object): | |||||
| def toggle_edges(self, a, b): | def toggle_edges(self, a, b): | ||||
| """ Toggle edges between vertex sets a and 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() | done = set() | ||||
| for i, j in it.product(a, b): | 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) | self.toggle_edge(i, j) | ||||
| def measure_x(self, node, result): | def measure_x(self, node, result): | ||||
| @@ -156,9 +158,11 @@ class GraphState(object): | |||||
| return 0 | return 0 | ||||
| # Pick a vertex | # 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: | if result: | ||||
| # Do a z on all ngb(vb) \ ngb(v) \ {v}, and some other stuff | # Do a z on all ngb(vb) \ ngb(v) \ {v}, and some other stuff | ||||
| self.act_local_rotation(node, "pz") | 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}: | for n in set(self.adj[node]) - set(self.adj[friend]) - {friend}: | ||||
| self.act_local_rotation(n, "pz") | self.act_local_rotation(n, "pz") | ||||
| # TODO: Yuk. Just awful! | |||||
| # Toggle the edges. TODO: Yuk. Just awful! | |||||
| a = set(self.adj[node].keys()) | a = set(self.adj[node].keys()) | ||||
| b = set(self.adj[friend].keys()) | b = set(self.adj[friend].keys()) | ||||
| self.toggle_edges(a, b) | self.toggle_edges(a, b) | ||||
| @@ -1,5 +1,6 @@ | |||||
| from abp import GraphState, clifford | from abp import GraphState, clifford | ||||
| from anders_briegel import graphsim | from anders_briegel import graphsim | ||||
| import numpy as np | |||||
| def random_state(N=10, messy=True): | def random_state(N=10, messy=True): | ||||
| """ A state to test on """ | """ A state to test on """ | ||||
| @@ -4,7 +4,7 @@ import numpy as np | |||||
| from tqdm import tqdm | from tqdm import tqdm | ||||
| import dummy | import dummy | ||||
| N = 2 | |||||
| N = 10 | |||||
| REPEATS = 10 | REPEATS = 10 | ||||
| m = {1: graphsim.lco_X, 2: graphsim.lco_Y, 3: graphsim.lco_Z} | 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 | #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): | for outcome in (0, 1): | ||||
| a, b = dummy.bell() | a, b = dummy.bell() | ||||
| a.measure(0, str(measurement), outcome) | a.measure(0, str(measurement), outcome) | ||||
| b.measure(0, m[measurement], None, 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) | 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) | |||||