| @@ -23,6 +23,8 @@ class GraphState(graphstate.GraphState, networkx.Graph): | |||||
| def shutdown(self): | def shutdown(self): | ||||
| """ Close the connection to the websocket """ | """ Close the connection to the websocket """ | ||||
| if not self.ws: | |||||
| return | |||||
| self.update() | self.update() | ||||
| self.ws.close() | self.ws.close() | ||||
| @@ -21,7 +21,7 @@ def client_left(client, server): | |||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||
| parser = argparse.ArgumentParser(description = "ABP websocket server") | 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() | args = parser.parse_args() | ||||
| # Change to the right working dir | # Change to the right working dir | ||||
| @@ -4,11 +4,12 @@ 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)), | |||||
| ((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): | def add_offset(vector, offset): | ||||
| """ Offset a vector in n-dimensional space """ | """ Offset a vector in n-dimensional space """ | ||||
| @@ -29,7 +30,7 @@ def lattice(unit_cell, size): | |||||
| nodes = set(itertools.chain(*edges)) | nodes = set(itertools.chain(*edges)) | ||||
| return nodes, 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): | for j in range(100): | ||||
| psi = GraphState() | psi = GraphState() | ||||
| @@ -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])) | |||||
| @@ -11,7 +11,7 @@ materials.prepare = function() { | |||||
| materials.edge = new THREE.LineBasicMaterial({ | materials.edge = new THREE.LineBasicMaterial({ | ||||
| color: "gray", | color: "gray", | ||||
| transparent: false, | transparent: false, | ||||
| linewidth: 3 | |||||
| linewidth: 2 | |||||
| }); | }); | ||||
| materials.qubit = new THREE.PointsMaterial({ | materials.qubit = new THREE.PointsMaterial({ | ||||
| size: 0.5, | size: 0.5, | ||||