@@ -34,8 +34,8 @@ class GraphState(graphstate.GraphState, networkx.Graph): | |||||
if not all(("position" in node) for node in self.node.values()): | if not all(("position" in node) for node in self.node.values()): | ||||
self.layout() | 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 | # Send data to browser and rate-limit | ||||
self.ws.send(json.dumps(self.to_json())) | self.ws.send(json.dumps(self.to_json())) | ||||
@@ -5,6 +5,7 @@ Provides an extremely basic graph structure, based on neighbour lists | |||||
import itertools as it | import itertools as it | ||||
import json | import json | ||||
import qi, clifford, util | import qi, clifford, util | ||||
import random | |||||
class GraphState(object): | class GraphState(object): | ||||
@@ -104,7 +105,7 @@ class GraphState(object): | |||||
def measure_z(self, node, force=None): | def measure_z(self, node, force=None): | ||||
""" Measure the graph in the Z-basis """ | """ 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 | # Disconnect | ||||
for neighbour in self.adj[node]: | for neighbour in self.adj[node]: | ||||
@@ -15,6 +15,9 @@ websocket.connect = function(update) { | |||||
for (var i in json.node) { | for (var i in json.node) { | ||||
var pos = json.node[i].position; | var pos = json.node[i].position; | ||||
json.node[i].position = new THREE.Vector3(pos.x, pos.y, pos.z); | 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); | update(json); | ||||
}; | }; | ||||
@@ -7,7 +7,6 @@ import time | |||||
def test_graph_basic(): | def test_graph_basic(): | ||||
""" Test that we can construct graphs, delete edges, whatever """ | """ Test that we can construct graphs, delete edges, whatever """ | ||||
g = demograph() | g = demograph() | ||||
print g.adj[0].keys() | |||||
assert set(g.adj[0].keys()) == set([1, 2, 3]) | assert set(g.adj[0].keys()) == set([1, 2, 3]) | ||||
g.del_edge(0, 1) | g.del_edge(0, 1) | ||||
assert set(g.adj[0].keys()) == set([2, 3]) | assert set(g.adj[0].keys()) == set([2, 3]) | ||||
@@ -28,22 +27,6 @@ def test_local_complementation(): | |||||
# TODO: test VOP conditions | # 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(): | def test_remove_vop(): | ||||
""" Test that removing VOPs really works """ | """ Test that removing VOPs really works """ | ||||
g = demograph() | g = demograph() | ||||
@@ -1,6 +1,14 @@ | |||||
from abp import GraphState | from abp import GraphState | ||||
def test_z_measurement(): | 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)) | |||||