| @@ -1,16 +1,16 @@ | |||||
| var websocket = {}; | var websocket = {}; | ||||
| websocket.connect = function(update) { | websocket.connect = function(update) { | ||||
| var ws = new WebSocket("ws://localhost:5000"); | |||||
| ws.onopen = function(evt) { | |||||
| websocket.ws = new WebSocket("ws://localhost:5000"); | |||||
| websocket.ws.onopen = function(evt) { | |||||
| gui.serverMessage("Connected to server."); | gui.serverMessage("Connected to server."); | ||||
| }; | }; | ||||
| ws.onerror = function(err) { | |||||
| websocket.ws.onerror = function(err) { | |||||
| gui.serverMessage("Could not connect to server."); | gui.serverMessage("Could not connect to server."); | ||||
| }; | }; | ||||
| ws.onmessage = function(evt) { | |||||
| websocket.ws.onmessage = function(evt) { | |||||
| json = JSON.parse(evt.data); | json = JSON.parse(evt.data); | ||||
| for (var i in json.node) { | for (var i in json.node) { | ||||
| var pos = json.node[i].position; | var pos = json.node[i].position; | ||||
| @@ -22,7 +22,7 @@ websocket.connect = function(update) { | |||||
| update(json); | update(json); | ||||
| }; | }; | ||||
| ws.onclose = function(evt) { | |||||
| websocket.ws.onclose = function(evt) { | |||||
| gui.serverMessage("No connection to server. <a href='#' onclick='javascript:websocket.connect()'>Reconnect</a>.", true); | gui.serverMessage("No connection to server. <a href='#' onclick='javascript:websocket.connect()'>Reconnect</a>.", true); | ||||
| }; | }; | ||||
| }; | }; | ||||
| @@ -12,13 +12,19 @@ import os, sys, threading | |||||
| import webbrowser | import webbrowser | ||||
| import argparse | import argparse | ||||
| import abp | import abp | ||||
| import json | |||||
| from pkg_resources import resource_filename | from pkg_resources import resource_filename | ||||
| clients = [] | clients = [] | ||||
| def new_message(client, server, message): | def new_message(client, server, message): | ||||
| print "Received update from client {}.".format(client["id"]) | |||||
| server.send_message_to_all(message) | |||||
| if message.startswith("edit"): | |||||
| edit = json.loads(message[5:]) | |||||
| print "Received update from javascript." | |||||
| print edit | |||||
| else: | |||||
| print "Received update from python {}.".format(client["id"]) | |||||
| server.send_message_to_all(message) | |||||
| def new_client(client, server): | def new_client(client, server): | ||||
| print "Client {} connected.".format(client["id"]) | print "Client {} connected.".format(client["id"]) | ||||
| @@ -0,0 +1,23 @@ | |||||
| from abp.fancy import GraphState | |||||
| from abp.util import xyz | |||||
| import itertools | |||||
| def grid_2d(width, height): | |||||
| """ Make a 2D grid """ | |||||
| psi = GraphState() | |||||
| grid = list(itertools.product(range(width), range(height))) | |||||
| for x, y in grid: | |||||
| psi.add_qubit((x, y), position=xyz(x, y, 0), vop=0) | |||||
| for x, y in grid: | |||||
| if x<width-1: psi.act_cz((x, y), (x+1, y)) | |||||
| if y<height-1: psi.act_cz((x, y), (x, y+1)) | |||||
| return psi | |||||
| if __name__ == '__main__': | |||||
| psi = grid_2d(5, 5) | |||||
| psi.update() | |||||