Przeglądaj źródła

Starting to work on stripping out abp.js

master
Pete Shadbolt 8 lat temu
rodzic
commit
826a8b26d3
3 zmienionych plików z 36 dodań i 7 usunięć
  1. +5
    -5
      abp/static/scripts/websocket.js
  2. +8
    -2
      bin/abpserver
  3. +23
    -0
      examples/visualization/grid_2d.py

+ 5
- 5
abp/static/scripts/websocket.js Wyświetl plik

@@ -1,16 +1,16 @@
var websocket = {};

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.");
};

ws.onerror = function(err) {
websocket.ws.onerror = function(err) {
gui.serverMessage("Could not connect to server.");
};

ws.onmessage = function(evt) {
websocket.ws.onmessage = function(evt) {
json = JSON.parse(evt.data);
for (var i in json.node) {
var pos = json.node[i].position;
@@ -22,7 +22,7 @@ websocket.connect = function(update) {
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);
};
};

+ 8
- 2
bin/abpserver Wyświetl plik

@@ -12,13 +12,19 @@ import os, sys, threading
import webbrowser
import argparse
import abp
import json
from pkg_resources import resource_filename

clients = []

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):
print "Client {} connected.".format(client["id"])


+ 23
- 0
examples/visualization/grid_2d.py Wyświetl plik

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


Ładowanie…
Anuluj
Zapisz