Made sure that `graph.js` dumps old graphs after use, and ensured that `examples/stress_test` shuts down the connection after use (don't create millions of clients).master
@@ -1,4 +1,5 @@ | |||||
import time, atexit, json | import time, atexit, json | ||||
import sys | |||||
import networkx | import networkx | ||||
import numpy as np | import numpy as np | ||||
import websocket | import websocket | ||||
@@ -34,13 +35,16 @@ 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() | |||||
# Send data to browser and rate-limit | # Send data to browser and rate-limit | ||||
self.ws.send(json.dumps(self.to_json(), default = str)) | |||||
self.ws.recv() | |||||
time.sleep(delay) | |||||
try: | |||||
self.ws.send(json.dumps(self.to_json(), default = str)) | |||||
self.ws.recv() | |||||
time.sleep(delay) | |||||
except websocket._exceptions.WebSocketTimeoutException: | |||||
print "Timed out ... you might be pushing a bit hard" | |||||
sys.exit(0) | |||||
#self.ws.close() | |||||
#self.connect_to_server() | |||||
def layout(self, dim=3): | def layout(self, dim=3): | ||||
""" Automatically lay out the graph """ | """ Automatically lay out the graph """ | ||||
@@ -4,6 +4,8 @@ import numpy as np | |||||
import time | import time | ||||
import itertools | import itertools | ||||
square_unit_cell = ( | |||||
((0, 0), (0, 1)), ((0, 0), (1, 0)), ((1, 0), (1, 1)), ((0, 1), (1, 1))) | |||||
funny_unit_cell = (((0, 0), (0, 1)), ((0, 0), (1, 0)), | funny_unit_cell = (((0, 0), (0, 1)), ((0, 0), (1, 0)), | ||||
((1, 0), (1, 1)), ((0, 1), (1, 1)), ((0, 0), (.5, .5))) | ((1, 0), (1, 1)), ((0, 1), (1, 1)), ((0, 0), (.5, .5))) | ||||
@@ -27,14 +29,18 @@ def lattice(unit_cell, size): | |||||
nodes = set(itertools.chain(*edges)) | nodes = set(itertools.chain(*edges)) | ||||
return nodes, edges | return nodes, edges | ||||
# s = VisibleGraphState() | |||||
nodes, edges = lattice(funny_unit_cell, (10, 10)) | |||||
nodes, edges = lattice(funny_unit_cell, (4, 4)) | |||||
psi = GraphState() | |||||
for node in nodes: | |||||
psi.add_node(str(node), position=xyz(node[0], node[1])) | |||||
psi.act_hadamard(str(node)) | |||||
for j in range(100): | |||||
psi = GraphState() | |||||
for node in nodes: | |||||
psi.add_node(str(node), position=xyz(node[0], node[1], 0)) | |||||
psi.act_hadamard(str(node)) | |||||
psi.update(0) | |||||
for edge in edges: | |||||
psi.act_cz(str(edge[0]), str(edge[1])) | |||||
for edge in edges: | |||||
psi.act_cz(str(edge[0]), str(edge[1])) | |||||
psi.update(0) | |||||
psi.shutdown() | |||||
@@ -18,8 +18,8 @@ graph.center = function() { | |||||
graph.update = function(newState) { | graph.update = function(newState) { | ||||
if (newState){abj.update(newState);} | if (newState){abj.update(newState);} | ||||
if (graph.object){gui.scene.remove(graph.object);} | |||||
graph.object = null; | |||||
var gs = gui.scene.getObjectByName("graphstate"); | |||||
if (gs){ gui.scene.remove(gs); } | |||||
var geometry = new THREE.Geometry(); | var geometry = new THREE.Geometry(); | ||||
geometry.colors = []; | geometry.colors = []; | ||||
@@ -48,19 +48,11 @@ graph.update = function(newState) { | |||||
} | } | ||||
var particles = new THREE.Points(geometry, materials.qubit); | var particles = new THREE.Points(geometry, materials.qubit); | ||||
graph.object = new THREE.Object3D(); | |||||
graph.object.name = "graphstate"; | |||||
graph.object.add(particles); | |||||
graph.object.add(edges); | |||||
gui.scene.add(graph.object); | |||||
var object = new THREE.Object3D(); | |||||
object.name = "graphstate"; | |||||
object.add(particles); | |||||
object.add(edges); | |||||
gui.scene.add(object); | |||||
gui.render(); | gui.render(); | ||||
geometry = null; | |||||
edges=null; | |||||
particles = null; | |||||
graph.object = null; | |||||
}; | }; | ||||
graph.test = function(command) { | |||||
//Act the command | |||||
//Send it back to the server, ultimately thru to python | |||||
}; |