From 23fec825835b228d36102eb13bc64c8622e6c482 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Fri, 20 May 2016 17:12:37 +0100 Subject: [PATCH] Preparing to implement measurement --- abp/fancy.py | 4 ++-- abp/graphstate.py | 3 ++- static/scripts/websocket.js | 3 +++ tests/test_graph.py | 17 ----------------- tests/test_measurement.py | 12 ++++++++++-- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/abp/fancy.py b/abp/fancy.py index 9f8de33..6fc4f36 100644 --- a/abp/fancy.py +++ b/abp/fancy.py @@ -34,8 +34,8 @@ class GraphState(graphstate.GraphState, networkx.Graph): if not all(("position" in node) for node in self.node.values()): self.layout() - if not all(("vop" in node) for node in self.node.values()): - self.add_vops() + #if not all(("vop" in node) for node in self.node.values()): + #self.add_vops() # Send data to browser and rate-limit self.ws.send(json.dumps(self.to_json())) diff --git a/abp/graphstate.py b/abp/graphstate.py index b2da20a..1abefee 100644 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -5,6 +5,7 @@ Provides an extremely basic graph structure, based on neighbour lists import itertools as it import json import qi, clifford, util +import random class GraphState(object): @@ -104,7 +105,7 @@ class GraphState(object): def measure_z(self, node, force=None): """ Measure the graph in the Z-basis """ - res = force if force else np.random.choice([0, 1]) + res = force if force!=None else random.choice([0, 1]) # Disconnect for neighbour in self.adj[node]: diff --git a/static/scripts/websocket.js b/static/scripts/websocket.js index d2a08a0..e40c1b6 100644 --- a/static/scripts/websocket.js +++ b/static/scripts/websocket.js @@ -15,6 +15,9 @@ websocket.connect = function(update) { for (var i in json.node) { var pos = json.node[i].position; json.node[i].position = new THREE.Vector3(pos.x, pos.y, pos.z); + if (json.node[i].vop === undefined){ + json.node[i].vop = 0; + } } update(json); }; diff --git a/tests/test_graph.py b/tests/test_graph.py index 8a587fb..1550281 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -7,7 +7,6 @@ import time def test_graph_basic(): """ Test that we can construct graphs, delete edges, whatever """ g = demograph() - print g.adj[0].keys() assert set(g.adj[0].keys()) == set([1, 2, 3]) g.del_edge(0, 1) assert set(g.adj[0].keys()) == set([2, 3]) @@ -28,22 +27,6 @@ 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() diff --git a/tests/test_measurement.py b/tests/test_measurement.py index 35cb98a..57c2132 100644 --- a/tests/test_measurement.py +++ b/tests/test_measurement.py @@ -1,6 +1,14 @@ from abp import GraphState def test_z_measurement(): - #TODO - pass + g = GraphState(0) + assert g.measure_z(0, 0) == 0 + assert g.measure_z(0, 1) == 1 + assert not all(g.measure_z(0) == 0 for i in range(100)) + + g.act_hadamard(0) + print g + assert all(g.measure_z(0) == 1 for i in range(100)) + +