From 95dc82cb1953632e1f8b7a892f964f92ff67dc9f Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Tue, 5 Jul 2016 21:53:25 +0100 Subject: [PATCH] Buttery smooth :cow: :bread: 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). --- abp/fancy.py | 16 ++++++++++------ examples/stress_test.py | 22 ++++++++++++++-------- static/scripts/graph.js | 22 +++++++--------------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/abp/fancy.py b/abp/fancy.py index cdc4813..9df3209 100644 --- a/abp/fancy.py +++ b/abp/fancy.py @@ -1,4 +1,5 @@ import time, atexit, json +import sys import networkx import numpy as np import websocket @@ -34,13 +35,16 @@ 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() - # 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): """ Automatically lay out the graph """ diff --git a/examples/stress_test.py b/examples/stress_test.py index 8c73c89..e9d7ce0 100644 --- a/examples/stress_test.py +++ b/examples/stress_test.py @@ -4,6 +4,8 @@ import numpy as np import time 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)), ((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)) 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() diff --git a/static/scripts/graph.js b/static/scripts/graph.js index fc0bdfa..98bd51b 100644 --- a/static/scripts/graph.js +++ b/static/scripts/graph.js @@ -18,8 +18,8 @@ graph.center = function() { graph.update = function(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(); geometry.colors = []; @@ -48,19 +48,11 @@ graph.update = function(newState) { } 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(); - 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 -};