diff --git a/abp/fancy.py b/abp/fancy.py index 9df3209..d340412 100644 --- a/abp/fancy.py +++ b/abp/fancy.py @@ -23,6 +23,8 @@ class GraphState(graphstate.GraphState, networkx.Graph): def shutdown(self): """ Close the connection to the websocket """ + if not self.ws: + return self.update() self.ws.close() diff --git a/abp/server.py b/abp/server.py index 8964415..e450444 100644 --- a/abp/server.py +++ b/abp/server.py @@ -21,7 +21,7 @@ def client_left(client, server): if __name__ == '__main__': parser = argparse.ArgumentParser(description = "ABP websocket server") - parser.add_argument("-v", action="store_true", help="Launch browser") + parser.add_argument("-v", action="store_false", help="Launch browser") args = parser.parse_args() # Change to the right working dir diff --git a/examples/stress_test.py b/examples/stress_test.py index e9d7ce0..e239c5f 100644 --- a/examples/stress_test.py +++ b/examples/stress_test.py @@ -4,11 +4,12 @@ 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))) - +threedee_unit_cell = ( + (( 0, 0, 0), (0, 1, 0)), + (( 0, 0, 0), (1, 0, 0)), + (( 1, 0, 0), (1, 1, 0)), + (( 0, 1, 0), (1, 1, 0))) + ) def add_offset(vector, offset): """ Offset a vector in n-dimensional space """ @@ -29,7 +30,7 @@ def lattice(unit_cell, size): nodes = set(itertools.chain(*edges)) return nodes, edges -nodes, edges = lattice(funny_unit_cell, (4, 4)) +nodes, edges = lattice(threedee_unit_cell, (4, 4, 4)) for j in range(100): psi = GraphState() diff --git a/examples/threedee.py b/examples/threedee.py new file mode 100644 index 0000000..bcbc178 --- /dev/null +++ b/examples/threedee.py @@ -0,0 +1,53 @@ +from abp.fancy import GraphState +from abp.util import xyz +import numpy as np +import time +import itertools + +threedee_unit_cell = ( + (( 0, 0, 0), (0, 1, 0)), + (( 0, 0, 0), (1, 0, 0)), + (( 1, 0, 0), (1, 1, 0)), + (( 0, 1, 0), (1, 1, 0)), + + (( 0, 0, 1), (0, 1, 1)), + (( 0, 0, 1), (1, 0, 1)), + (( 1, 0, 1), (1, 1, 1)), + (( 0, 1, 1), (1, 1, 1)), + + (( 0, 0, 0), (0, 0, 1)), + (( 0, 1, 0), (0, 1, 1)), + (( 1, 0, 0), (1, 0, 1)), + (( 1, 1, 0), (1, 1, 1)) + ) + +def add_offset(vector, offset): + """ Offset a vector in n-dimensional space """ + return tuple(v + o for v, o in zip(vector, offset)) + + +def offset_unit_cell(unit_cell, offset): + """ Offset a unit cell """ + return {(add_offset(a, offset), add_offset(b, offset)) for a, b in unit_cell} + + +def lattice(unit_cell, size): + """ Generate a lattice from a unit cell """ + edges = set() + for offset in itertools.product(*map(range, size)): + edges |= offset_unit_cell(unit_cell, offset) + + nodes = set(itertools.chain(*edges)) + return nodes, edges + +nodes, edges = lattice(threedee_unit_cell, (4, 4, 4)) + +psi = GraphState() +for node in nodes: + psi.add_node(str(node), position=xyz(*node)) + psi.act_hadamard(str(node)) + +for edge in edges: + psi.act_cz(str(edge[0]), str(edge[1])) + + diff --git a/static/scripts/materials.js b/static/scripts/materials.js index d9e2cf2..1d6ad4a 100644 --- a/static/scripts/materials.js +++ b/static/scripts/materials.js @@ -11,7 +11,7 @@ materials.prepare = function() { materials.edge = new THREE.LineBasicMaterial({ color: "gray", transparent: false, - linewidth: 3 + linewidth: 2 }); materials.qubit = new THREE.PointsMaterial({ size: 0.5,