Sfoglia il codice sorgente

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).
master
Pete Shadbolt 8 anni fa
parent
commit
95dc82cb19
3 ha cambiato i file con 31 aggiunte e 29 eliminazioni
  1. +10
    -6
      abp/fancy.py
  2. +14
    -8
      examples/stress_test.py
  3. +7
    -15
      static/scripts/graph.js

+ 10
- 6
abp/fancy.py Vedi File

@@ -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 """


+ 14
- 8
examples/stress_test.py Vedi File

@@ -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()


+ 7
- 15
static/scripts/graph.js Vedi File

@@ -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
};

Loading…
Annulla
Salva