diff --git a/abp/clifford.py b/abp/clifford.py index fec40bc..fd40aef 100644 --- a/abp/clifford.py +++ b/abp/clifford.py @@ -105,7 +105,6 @@ def get_cz_table(unitaries): """ Compute the lookup table for the CZ (A&B eq. 9) """ # Get a cached state table and a list of gates which commute with CZ commuters = get_commuters(unitaries) - print commuters state_table = get_state_table(unitaries) # And now build the CZ table diff --git a/abp/graphstate.py b/abp/graphstate.py index f088b99..c9e99fe 100644 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -10,12 +10,20 @@ try: from networkx import Graph as NXGraph except ImportError: NXGraph = object +try: + import websocket + from socket import error as socket_error + import time, atexit +except ImportError: + websocket = None class GraphState(NXGraph): - def __init__(self, nodes=[]): + def __init__(self, nodes=[], connect_to_server=True): self.adj, self.node = {}, {} self.add_nodes(nodes) + if connect_to_server: + self.connect_to_server() def add_node(self, v, **kwargs): """ Add a node """ @@ -198,3 +206,27 @@ class GraphState(NXGraph): """ Check equality between graphs """ return self.adj == other.adj and self.node == other.node + def connect_to_server(self, uri = "ws://localhost:5000"): + """ Attempt to connect to the websocket server """ + if not websocket: + return + try: + self.ws = websocket.create_connection(uri) + atexit.register(self.shutdown) + except socket_error: + #print "Could not establish connection to server ({}).".format(uri) + self.ws = None + + + def shutdown(self): + """ Close the connection to the websocket """ + self.update() + self.ws.close() + + def update(self, delay = 0.5): + """ Call this function when you are ready to send data to the browser """ + if not self.ws: + return + data = json.dumps(self.to_json()) + self.ws.send(data) + time.sleep(delay) diff --git a/abp/viz.py b/abp/viz.py deleted file mode 100644 index 8d2b335..0000000 --- a/abp/viz.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -Allows us to visualize the state in a browser -""" - -import atexit, json, time -from graphstate import GraphState -from websocket import create_connection - -class VisibleGraphState(GraphState): - - """ Overloads the graph state with methods for sending to the browser over a websocket """ - - def __init__(self, *args, **kwargs): - """ Constructor """ - GraphState.__init__(self, *args, **kwargs) - self.ws = create_connection("ws://localhost:5000") - atexit.register(self.shutdown) - - def shutdown(self): - """ The client should shut down automatically on close """ - self.update() - self.ws.close() - - def update(self, delay = 0.5): - """ Call this function when you are ready to send data to the browser """ - data = json.dumps(self.to_json()) - self.ws.send(data) - time.sleep(delay) - diff --git a/examples/lattice_demo.py b/examples/lattice_demo.py index a6ab817..8c2425e 100644 --- a/examples/lattice_demo.py +++ b/examples/lattice_demo.py @@ -1,4 +1,4 @@ -from abp.viz import VisibleGraphState +from abp.graphstate import GraphState from abp.util import xyz import numpy as np import time @@ -32,7 +32,7 @@ def lattice(unit_cell, size): # s = VisibleGraphState() nodes, edges = lattice(square_unit_cell, (4, 4)) -psi = VisibleGraphState() +psi = GraphState() for node in nodes: psi.add_node(str(node), position=xyz(node[0], node[1])) psi.act_hadamard(str(node)) diff --git a/static/scripts/.gitignore b/static/scripts/.gitignore new file mode 100644 index 0000000..46210cf --- /dev/null +++ b/static/scripts/.gitignore @@ -0,0 +1 @@ +qcengine diff --git a/static/scripts/anders_briegel.js b/static/scripts/anders_briegel.js index c0f68e7..6331741 100644 --- a/static/scripts/anders_briegel.js +++ b/static/scripts/anders_briegel.js @@ -3,6 +3,7 @@ abj.node = {}; abj.adj = {}; abj.add_node = function(node, meta) { + if (meta === undefined){meta = {};} abj.adj[node] = {}; abj.node[node] = {}; abj.node[node].vop = tables.clifford.hadamard; @@ -143,3 +144,4 @@ abj.order = function(){ return Object.keys(abj.node).length; }; + diff --git a/static/scripts/tables.js b/static/scripts/tables.js index b6e692a..ebd754c 100644 --- a/static/scripts/tables.js +++ b/static/scripts/tables.js @@ -4,4 +4,5 @@ var tables = { times_table : [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], [1, 0, 3, 2, 6, 7, 4, 5, 11, 10, 9, 8, 13, 12, 15, 14, 19, 18, 17, 16, 22, 23, 20, 21], [2, 3, 0, 1, 5, 4, 7, 6, 10, 11, 8, 9, 15, 14, 13, 12, 17, 16, 19, 18, 23, 22, 21, 20], [3, 2, 1, 0, 7, 6, 5, 4, 9, 8, 11, 10, 14, 15, 12, 13, 18, 19, 16, 17, 21, 20, 23, 22], [4, 5, 6, 7, 0, 1, 2, 3, 20, 21, 22, 23, 16, 17, 18, 19, 12, 13, 14, 15, 8, 9, 10, 11], [5, 4, 7, 6, 2, 3, 0, 1, 23, 22, 21, 20, 17, 16, 19, 18, 15, 14, 13, 12, 10, 11, 8, 9], [6, 7, 4, 5, 1, 0, 3, 2, 22, 23, 20, 21, 19, 18, 17, 16, 13, 12, 15, 14, 11, 10, 9, 8], [7, 6, 5, 4, 3, 2, 1, 0, 21, 20, 23, 22, 18, 19, 16, 17, 14, 15, 12, 13, 9, 8, 11, 10], [8, 9, 10, 11, 16, 17, 18, 19, 0, 1, 2, 3, 20, 21, 22, 23, 4, 5, 6, 7, 12, 13, 14, 15], [9, 8, 11, 10, 18, 19, 16, 17, 3, 2, 1, 0, 21, 20, 23, 22, 7, 6, 5, 4, 14, 15, 12, 13], [10, 11, 8, 9, 17, 16, 19, 18, 2, 3, 0, 1, 23, 22, 21, 20, 5, 4, 7, 6, 15, 14, 13, 12], [11, 10, 9, 8, 19, 18, 17, 16, 1, 0, 3, 2, 22, 23, 20, 21, 6, 7, 4, 5, 13, 12, 15, 14], [12, 13, 14, 15, 20, 21, 22, 23, 16, 17, 18, 19, 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7], [13, 12, 15, 14, 22, 23, 20, 21, 19, 18, 17, 16, 1, 0, 3, 2, 11, 10, 9, 8, 6, 7, 4, 5], [14, 15, 12, 13, 21, 20, 23, 22, 18, 19, 16, 17, 3, 2, 1, 0, 9, 8, 11, 10, 7, 6, 5, 4], [15, 14, 13, 12, 23, 22, 21, 20, 17, 16, 19, 18, 2, 3, 0, 1, 10, 11, 8, 9, 5, 4, 7, 6], [16, 17, 18, 19, 8, 9, 10, 11, 12, 13, 14, 15, 4, 5, 6, 7, 20, 21, 22, 23, 0, 1, 2, 3], [17, 16, 19, 18, 10, 11, 8, 9, 15, 14, 13, 12, 5, 4, 7, 6, 23, 22, 21, 20, 2, 3, 0, 1], [18, 19, 16, 17, 9, 8, 11, 10, 14, 15, 12, 13, 7, 6, 5, 4, 21, 20, 23, 22, 3, 2, 1, 0], [19, 18, 17, 16, 11, 10, 9, 8, 13, 12, 15, 14, 6, 7, 4, 5, 22, 23, 20, 21, 1, 0, 3, 2], [20, 21, 22, 23, 12, 13, 14, 15, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 16, 17, 18, 19], [21, 20, 23, 22, 14, 15, 12, 13, 7, 6, 5, 4, 9, 8, 11, 10, 3, 2, 1, 0, 18, 19, 16, 17], [22, 23, 20, 21, 13, 12, 15, 14, 6, 7, 4, 5, 11, 10, 9, 8, 1, 0, 3, 2, 19, 18, 17, 16], [23, 22, 21, 20, 15, 14, 13, 12, 5, 4, 7, 6, 10, 11, 8, 9, 2, 3, 0, 1, 17, 16, 19, 18]], cz_table : [[[[1, 0, 0], [1, 0, 0], [1, 0, 3], [1, 0, 3], [1, 0, 5], [1, 0, 5], [1, 0, 6], [1, 0, 6], [0, 3, 8], [0, 3, 8], [0, 0, 10], [0, 0, 10], [1, 0, 3], [1, 0, 3], [1, 0, 0], [1, 0, 0], [1, 0, 6], [1, 0, 6], [1, 0, 5], [1, 0, 5], [0, 0, 10], [0, 0, 10], [0, 3, 8], [0, 3, 8]], [[1, 0, 0], [1, 0, 0], [1, 0, 3], [1, 0, 3], [1, 0, 5], [1, 0, 5], [1, 0, 6], [1, 0, 6], [0, 2, 8], [0, 2, 8], [0, 0, 10], [0, 0, 10], [1, 0, 3], [1, 0, 3], [1, 0, 0], [1, 0, 0], [1, 0, 6], [1, 0, 6], [1, 0, 5], [1, 0, 5], [0, 0, 10], [0, 0, 10], [0, 2, 8], [0, 2, 8]], [[1, 3, 0], [1, 3, 0], [1, 2, 0], [1, 2, 0], [1, 0, 4], [1, 2, 6], [1, 2, 5], [1, 0, 7], [0, 0, 8], [0, 0, 8], [0, 2, 10], [0, 2, 10], [1, 0, 2], [1, 0, 2], [1, 0, 1], [1, 0, 1], [1, 0, 7], [1, 0, 7], [1, 0, 4], [1, 0, 4], [0, 2, 10], [0, 2, 10], [0, 0, 8], [0, 0, 8]], [[1, 3, 0], [1, 3, 0], [1, 0, 2], [1, 3, 3], [1, 0, 4], [1, 3, 5], [1, 3, 6], [1, 0, 7], [0, 0, 8], [0, 0, 8], [0, 3, 10], [0, 3, 10], [1, 0, 2], [1, 0, 2], [1, 0, 1], [1, 0, 1], [1, 0, 7], [1, 0, 7], [1, 0, 4], [1, 0, 4], [0, 3, 10], [0, 3, 10], [0, 0, 8], [0, 0, 8]], [[1, 5, 0], [1, 5, 0], [1, 4, 0], [1, 4, 0], [1, 19, 0], [1, 4, 6], [1, 4, 5], [1, 0, 17], [0, 6, 8], [0, 6, 8], [0, 4, 10], [0, 4, 10], [1, 0, 12], [1, 0, 12], [1, 0, 14], [1, 0, 14], [1, 0, 17], [1, 0, 17], [1, 0, 19], [1, 0, 19], [0, 4, 10], [0, 4, 10], [0, 6, 8], [0, 6, 8]], [[1, 5, 0], [1, 5, 0], [1, 6, 2], [1, 5, 3], [1, 6, 4], [1, 5, 5], [1, 5, 6], [1, 0, 17], [0, 6, 8], [0, 6, 8], [0, 5, 10], [0, 5, 10], [1, 0, 12], [1, 0, 12], [1, 0, 14], [1, 0, 14], [1, 0, 17], [1, 0, 17], [1, 0, 19], [1, 0, 19], [0, 5, 10], [0, 5, 10], [0, 6, 8], [0, 6, 8]], [[1, 6, 0], [1, 6, 0], [1, 5, 2], [1, 6, 3], [1, 5, 4], [1, 6, 5], [1, 6, 6], [1, 0, 16], [0, 5, 8], [0, 5, 8], [0, 6, 10], [0, 6, 10], [1, 0, 13], [1, 0, 13], [1, 0, 15], [1, 0, 15], [1, 0, 16], [1, 0, 16], [1, 0, 18], [1, 0, 18], [0, 6, 10], [0, 6, 10], [0, 5, 8], [0, 5, 8]], [[1, 6, 0], [1, 6, 0], [1, 7, 0], [1, 7, 0], [1, 17, 0], [1, 17, 0], [1, 16, 0], [1, 16, 0], [0, 4, 8], [0, 4, 8], [0, 6, 10], [0, 6, 10], [1, 0, 13], [1, 0, 13], [1, 0, 15], [1, 0, 15], [1, 0, 16], [1, 0, 16], [1, 0, 18], [1, 0, 18], [0, 6, 10], [0, 6, 10], [0, 4, 8], [0, 4, 8]], [[0, 8, 3], [0, 8, 2], [0, 8, 0], [0, 8, 0], [0, 8, 6], [0, 8, 6], [0, 8, 5], [0, 8, 4], [0, 8, 8], [0, 8, 8], [0, 8, 10], [0, 8, 10], [0, 8, 0], [0, 8, 0], [0, 8, 2], [0, 8, 2], [0, 8, 4], [0, 8, 4], [0, 8, 6], [0, 8, 6], [0, 8, 10], [0, 8, 10], [0, 8, 8], [0, 8, 8]], [[0, 8, 3], [0, 8, 2], [0, 8, 0], [0, 8, 0], [0, 8, 6], [0, 8, 6], [0, 8, 5], [0, 8, 4], [0, 8, 8], [0, 8, 8], [0, 8, 10], [0, 8, 10], [0, 8, 0], [0, 8, 0], [0, 8, 2], [0, 8, 2], [0, 8, 4], [0, 8, 4], [0, 8, 6], [0, 8, 6], [0, 8, 10], [0, 8, 10], [0, 8, 8], [0, 8, 8]], [[0, 10, 0], [0, 10, 0], [0, 10, 2], [0, 10, 3], [0, 10, 4], [0, 10, 5], [0, 10, 6], [0, 10, 6], [0, 10, 8], [0, 10, 8], [0, 10, 10], [0, 10, 10], [0, 10, 2], [0, 10, 2], [0, 10, 0], [0, 10, 0], [0, 10, 6], [0, 10, 6], [0, 10, 4], [0, 10, 4], [0, 10, 10], [0, 10, 10], [0, 10, 8], [0, 10, 8]], [[0, 10, 0], [0, 10, 0], [0, 10, 2], [0, 10, 3], [0, 10, 4], [0, 10, 5], [0, 10, 6], [0, 10, 6], [0, 10, 8], [0, 10, 8], [0, 10, 10], [0, 10, 10], [0, 10, 2], [0, 10, 2], [0, 10, 0], [0, 10, 0], [0, 10, 6], [0, 10, 6], [0, 10, 4], [0, 10, 4], [0, 10, 10], [0, 10, 10], [0, 10, 8], [0, 10, 8]], [[1, 3, 0], [1, 3, 0], [1, 2, 0], [1, 2, 0], [1, 12, 0], [1, 12, 0], [1, 13, 0], [1, 13, 0], [0, 0, 8], [0, 0, 8], [0, 2, 10], [0, 2, 10], [1, 2, 0], [1, 0, 2], [1, 0, 1], [1, 0, 1], [1, 0, 7], [1, 0, 7], [1, 0, 4], [1, 0, 4], [0, 2, 10], [0, 2, 10], [0, 0, 8], [0, 0, 8]], [[1, 3, 0], [1, 3, 0], [1, 2, 0], [1, 2, 0], [1, 12, 0], [1, 12, 0], [1, 13, 0], [1, 13, 0], [0, 0, 8], [0, 0, 8], [0, 2, 10], [0, 2, 10], [1, 2, 0], [1, 2, 0], [1, 0, 1], [1, 0, 1], [1, 0, 7], [1, 0, 7], [1, 0, 4], [1, 0, 4], [0, 2, 10], [0, 2, 10], [0, 0, 8], [0, 0, 8]], [[1, 0, 0], [1, 0, 0], [1, 1, 0], [1, 1, 0], [1, 14, 0], [1, 14, 0], [1, 15, 0], [1, 15, 0], [0, 2, 8], [0, 2, 8], [0, 0, 10], [0, 0, 10], [1, 1, 0], [1, 1, 0], [1, 0, 0], [1, 0, 0], [1, 0, 6], [1, 0, 6], [1, 0, 5], [1, 0, 5], [0, 0, 10], [0, 0, 10], [0, 2, 8], [0, 2, 8]], [[1, 0, 0], [1, 0, 0], [1, 1, 0], [1, 1, 0], [1, 14, 0], [1, 14, 0], [1, 15, 0], [1, 15, 0], [0, 2, 8], [0, 2, 8], [0, 0, 10], [0, 0, 10], [1, 1, 0], [1, 1, 0], [1, 0, 0], [1, 0, 0], [1, 0, 6], [1, 0, 6], [1, 0, 5], [1, 0, 5], [0, 0, 10], [0, 0, 10], [0, 2, 8], [0, 2, 8]], [[1, 6, 0], [1, 6, 0], [1, 7, 0], [1, 7, 0], [1, 17, 0], [1, 17, 0], [1, 16, 0], [1, 16, 0], [0, 4, 8], [0, 4, 8], [0, 6, 10], [0, 6, 10], [1, 7, 0], [1, 7, 0], [1, 6, 0], [1, 6, 0], [1, 16, 0], [1, 0, 16], [1, 0, 18], [1, 0, 18], [0, 6, 10], [0, 6, 10], [0, 4, 8], [0, 4, 8]], [[1, 6, 0], [1, 6, 0], [1, 7, 0], [1, 7, 0], [1, 17, 0], [1, 17, 0], [1, 16, 0], [1, 16, 0], [0, 4, 8], [0, 4, 8], [0, 6, 10], [0, 6, 10], [1, 7, 0], [1, 7, 0], [1, 6, 0], [1, 6, 0], [1, 16, 0], [1, 16, 0], [1, 0, 18], [1, 0, 18], [0, 6, 10], [0, 6, 10], [0, 4, 8], [0, 4, 8]], [[1, 5, 0], [1, 5, 0], [1, 4, 0], [1, 4, 0], [1, 19, 0], [1, 19, 0], [1, 18, 0], [1, 18, 0], [0, 6, 8], [0, 6, 8], [0, 4, 10], [0, 4, 10], [1, 4, 0], [1, 4, 0], [1, 5, 0], [1, 5, 0], [1, 18, 0], [1, 18, 0], [1, 19, 0], [1, 0, 19], [0, 4, 10], [0, 4, 10], [0, 6, 8], [0, 6, 8]], [[1, 5, 0], [1, 5, 0], [1, 4, 0], [1, 4, 0], [1, 19, 0], [1, 19, 0], [1, 18, 0], [1, 18, 0], [0, 6, 8], [0, 6, 8], [0, 4, 10], [0, 4, 10], [1, 4, 0], [1, 4, 0], [1, 5, 0], [1, 5, 0], [1, 18, 0], [1, 18, 0], [1, 19, 0], [1, 19, 0], [0, 4, 10], [0, 4, 10], [0, 6, 8], [0, 6, 8]], [[0, 10, 0], [0, 10, 0], [0, 10, 2], [0, 10, 3], [0, 10, 4], [0, 10, 5], [0, 10, 6], [0, 10, 6], [0, 10, 8], [0, 10, 8], [0, 10, 10], [0, 10, 10], [0, 10, 2], [0, 10, 2], [0, 10, 0], [0, 10, 0], [0, 10, 6], [0, 10, 6], [0, 10, 4], [0, 10, 4], [0, 10, 10], [0, 10, 10], [0, 10, 8], [0, 10, 8]], [[0, 10, 0], [0, 10, 0], [0, 10, 2], [0, 10, 3], [0, 10, 4], [0, 10, 5], [0, 10, 6], [0, 10, 6], [0, 10, 8], [0, 10, 8], [0, 10, 10], [0, 10, 10], [0, 10, 2], [0, 10, 2], [0, 10, 0], [0, 10, 0], [0, 10, 6], [0, 10, 6], [0, 10, 4], [0, 10, 4], [0, 10, 10], [0, 10, 10], [0, 10, 8], [0, 10, 8]], [[0, 8, 3], [0, 8, 2], [0, 8, 0], [0, 8, 0], [0, 8, 6], [0, 8, 6], [0, 8, 5], [0, 8, 4], [0, 8, 8], [0, 8, 8], [0, 8, 10], [0, 8, 10], [0, 8, 0], [0, 8, 0], [0, 8, 2], [0, 8, 2], [0, 8, 4], [0, 8, 4], [0, 8, 6], [0, 8, 6], [0, 8, 10], [0, 8, 10], [0, 8, 8], [0, 8, 8]], [[0, 8, 3], [0, 8, 2], [0, 8, 0], [0, 8, 0], [0, 8, 6], [0, 8, 6], [0, 8, 5], [0, 8, 4], [0, 8, 8], [0, 8, 8], [0, 8, 10], [0, 8, 10], [0, 8, 0], [0, 8, 0], [0, 8, 2], [0, 8, 2], [0, 8, 4], [0, 8, 4], [0, 8, 6], [0, 8, 6], [0, 8, 10], [0, 8, 10], [0, 8, 8], [0, 8, 8]]], [[[0, 0, 0], [0, 3, 0], [0, 3, 2], [0, 0, 3], [0, 3, 4], [0, 0, 5], [0, 0, 6], [0, 3, 6], [1, 0, 8], [1, 0, 9], [1, 0, 11], [1, 0, 10], [0, 5, 2], [0, 6, 2], [0, 5, 0], [0, 6, 0], [0, 6, 6], [0, 5, 6], [0, 6, 4], [0, 5, 4], [1, 0, 21], [1, 0, 20], [1, 0, 22], [1, 0, 23]], [[0, 0, 3], [0, 2, 2], [0, 2, 0], [0, 0, 0], [0, 2, 6], [0, 0, 6], [0, 0, 5], [0, 2, 4], [1, 0, 10], [1, 0, 11], [1, 0, 9], [1, 0, 8], [0, 6, 0], [0, 4, 0], [0, 6, 2], [0, 4, 2], [0, 4, 4], [0, 6, 4], [0, 4, 6], [0, 6, 6], [1, 0, 23], [1, 0, 22], [1, 0, 20], [1, 0, 21]], [[0, 2, 3], [0, 0, 2], [0, 0, 0], [0, 2, 0], [0, 0, 6], [0, 2, 6], [0, 2, 5], [0, 0, 4], [1, 0, 11], [1, 0, 10], [1, 0, 8], [1, 0, 9], [0, 4, 0], [0, 6, 0], [0, 4, 2], [0, 6, 2], [0, 6, 4], [0, 4, 4], [0, 6, 6], [0, 4, 6], [1, 0, 22], [1, 0, 23], [1, 0, 21], [1, 0, 20]], [[0, 3, 0], [0, 0, 0], [0, 0, 2], [0, 3, 3], [0, 0, 4], [0, 3, 5], [0, 3, 6], [0, 0, 6], [1, 0, 9], [1, 0, 8], [1, 0, 10], [1, 0, 11], [0, 6, 2], [0, 5, 2], [0, 6, 0], [0, 5, 0], [0, 5, 6], [0, 6, 6], [0, 5, 4], [0, 6, 4], [1, 0, 20], [1, 0, 21], [1, 0, 23], [1, 0, 22]], [[0, 4, 3], [0, 6, 2], [0, 6, 0], [0, 4, 0], [0, 6, 6], [0, 4, 6], [0, 4, 5], [0, 6, 4], [1, 0, 21], [1, 0, 20], [1, 0, 23], [1, 0, 22], [0, 0, 0], [0, 2, 0], [0, 0, 2], [0, 2, 2], [0, 2, 4], [0, 0, 4], [0, 2, 6], [0, 0, 6], [1, 0, 8], [1, 0, 9], [1, 0, 10], [1, 0, 11]], [[0, 5, 0], [0, 6, 0], [0, 6, 2], [0, 5, 3], [0, 6, 4], [0, 5, 5], [0, 5, 6], [0, 6, 6], [1, 0, 22], [1, 0, 23], [1, 0, 20], [1, 0, 21], [0, 3, 2], [0, 0, 2], [0, 3, 0], [0, 0, 0], [0, 0, 6], [0, 3, 6], [0, 0, 4], [0, 3, 4], [1, 0, 11], [1, 0, 10], [1, 0, 9], [1, 0, 8]], [[0, 6, 0], [0, 5, 0], [0, 5, 2], [0, 6, 3], [0, 5, 4], [0, 6, 5], [0, 6, 6], [0, 5, 6], [1, 0, 23], [1, 0, 22], [1, 0, 21], [1, 0, 20], [0, 0, 2], [0, 3, 2], [0, 0, 0], [0, 3, 0], [0, 3, 6], [0, 0, 6], [0, 3, 4], [0, 0, 4], [1, 0, 10], [1, 0, 11], [1, 0, 8], [1, 0, 9]], [[0, 6, 3], [0, 4, 2], [0, 4, 0], [0, 6, 0], [0, 4, 6], [0, 6, 6], [0, 6, 5], [0, 4, 4], [1, 0, 20], [1, 0, 21], [1, 0, 22], [1, 0, 23], [0, 2, 0], [0, 0, 0], [0, 2, 2], [0, 0, 2], [0, 0, 4], [0, 2, 4], [0, 0, 6], [0, 2, 6], [1, 0, 9], [1, 0, 8], [1, 0, 11], [1, 0, 10]], [[1, 8, 0], [1, 10, 0], [1, 11, 0], [1, 9, 0], [1, 21, 0], [1, 22, 0], [1, 23, 0], [1, 20, 0], [0, 0, 0], [0, 0, 2], [0, 2, 2], [0, 2, 0], [0, 6, 6], [0, 4, 4], [0, 6, 4], [0, 4, 6], [0, 4, 2], [0, 6, 0], [0, 4, 0], [0, 6, 2], [0, 2, 4], [0, 2, 6], [0, 0, 6], [0, 0, 4]], [[1, 9, 0], [1, 11, 0], [1, 10, 0], [1, 8, 0], [1, 20, 0], [1, 23, 0], [1, 22, 0], [1, 21, 0], [0, 2, 0], [0, 2, 2], [0, 0, 2], [0, 0, 0], [0, 4, 6], [0, 6, 4], [0, 4, 4], [0, 6, 6], [0, 6, 2], [0, 4, 0], [0, 6, 0], [0, 4, 2], [0, 0, 4], [0, 0, 6], [0, 2, 6], [0, 2, 4]], [[1, 11, 0], [1, 9, 0], [1, 8, 0], [1, 10, 0], [1, 23, 0], [1, 20, 0], [1, 21, 0], [1, 22, 0], [0, 2, 2], [0, 2, 0], [0, 0, 0], [0, 0, 2], [0, 6, 4], [0, 4, 6], [0, 6, 6], [0, 4, 4], [0, 4, 0], [0, 6, 2], [0, 4, 2], [0, 6, 0], [0, 0, 6], [0, 0, 4], [0, 2, 4], [0, 2, 6]], [[1, 10, 0], [1, 8, 0], [1, 9, 0], [1, 11, 0], [1, 22, 0], [1, 21, 0], [1, 20, 0], [1, 23, 0], [0, 0, 2], [0, 0, 0], [0, 2, 0], [0, 2, 2], [0, 4, 4], [0, 6, 6], [0, 4, 6], [0, 6, 4], [0, 6, 0], [0, 4, 2], [0, 6, 2], [0, 4, 0], [0, 2, 6], [0, 2, 4], [0, 0, 4], [0, 0, 6]], [[0, 2, 5], [0, 0, 6], [0, 0, 4], [0, 2, 6], [0, 0, 0], [0, 2, 3], [0, 2, 0], [0, 0, 2], [0, 6, 6], [0, 6, 4], [0, 4, 6], [0, 4, 4], [1, 21, 0], [1, 0, 22], [1, 0, 20], [1, 0, 23], [1, 0, 8], [1, 0, 11], [1, 0, 9], [1, 0, 10], [0, 4, 2], [0, 4, 0], [0, 6, 2], [0, 6, 0]], [[0, 2, 6], [0, 0, 4], [0, 0, 6], [0, 2, 5], [0, 0, 2], [0, 2, 0], [0, 2, 3], [0, 0, 0], [0, 4, 4], [0, 4, 6], [0, 6, 4], [0, 6, 6], [1, 22, 0], [1, 20, 0], [1, 0, 22], [1, 0, 21], [1, 0, 10], [1, 0, 9], [1, 0, 11], [1, 0, 8], [0, 6, 0], [0, 6, 2], [0, 4, 0], [0, 4, 2]], [[0, 0, 5], [0, 2, 6], [0, 2, 4], [0, 0, 6], [0, 2, 0], [0, 0, 3], [0, 0, 0], [0, 2, 2], [0, 4, 6], [0, 4, 4], [0, 6, 6], [0, 6, 4], [1, 20, 0], [1, 22, 0], [1, 21, 0], [1, 0, 22], [1, 0, 9], [1, 0, 10], [1, 0, 8], [1, 0, 11], [0, 6, 2], [0, 6, 0], [0, 4, 2], [0, 4, 0]], [[0, 0, 6], [0, 2, 4], [0, 2, 6], [0, 0, 5], [0, 2, 2], [0, 0, 0], [0, 0, 3], [0, 2, 0], [0, 6, 4], [0, 6, 6], [0, 4, 4], [0, 4, 6], [1, 23, 0], [1, 21, 0], [1, 22, 0], [1, 20, 0], [1, 0, 11], [1, 0, 8], [1, 0, 10], [1, 0, 9], [0, 4, 0], [0, 4, 2], [0, 6, 0], [0, 6, 2]], [[0, 6, 6], [0, 4, 4], [0, 4, 6], [0, 6, 5], [0, 4, 2], [0, 6, 0], [0, 6, 3], [0, 4, 0], [0, 2, 4], [0, 2, 6], [0, 0, 4], [0, 0, 6], [1, 8, 0], [1, 10, 0], [1, 9, 0], [1, 11, 0], [1, 21, 0], [1, 0, 23], [1, 0, 20], [1, 0, 22], [0, 0, 0], [0, 0, 2], [0, 2, 0], [0, 2, 2]], [[0, 6, 5], [0, 4, 6], [0, 4, 4], [0, 6, 6], [0, 4, 0], [0, 6, 3], [0, 6, 0], [0, 4, 2], [0, 0, 6], [0, 0, 4], [0, 2, 6], [0, 2, 4], [1, 11, 0], [1, 9, 0], [1, 10, 0], [1, 8, 0], [1, 23, 0], [1, 20, 0], [1, 0, 23], [1, 0, 21], [0, 2, 2], [0, 2, 0], [0, 0, 2], [0, 0, 0]], [[0, 4, 6], [0, 6, 4], [0, 6, 6], [0, 4, 5], [0, 6, 2], [0, 4, 0], [0, 4, 3], [0, 6, 0], [0, 0, 4], [0, 0, 6], [0, 2, 4], [0, 2, 6], [1, 9, 0], [1, 11, 0], [1, 8, 0], [1, 10, 0], [1, 20, 0], [1, 23, 0], [1, 21, 0], [1, 0, 23], [0, 2, 0], [0, 2, 2], [0, 0, 0], [0, 0, 2]], [[0, 4, 5], [0, 6, 6], [0, 6, 4], [0, 4, 6], [0, 6, 0], [0, 4, 3], [0, 4, 0], [0, 6, 2], [0, 2, 6], [0, 2, 4], [0, 0, 6], [0, 0, 4], [1, 10, 0], [1, 8, 0], [1, 11, 0], [1, 9, 0], [1, 22, 0], [1, 21, 0], [1, 23, 0], [1, 20, 0], [0, 0, 2], [0, 0, 0], [0, 2, 2], [0, 2, 0]], [[1, 21, 0], [1, 23, 0], [1, 22, 0], [1, 20, 0], [1, 8, 0], [1, 11, 0], [1, 10, 0], [1, 9, 0], [0, 4, 2], [0, 4, 0], [0, 6, 0], [0, 6, 2], [0, 2, 4], [0, 0, 6], [0, 2, 6], [0, 0, 4], [0, 0, 0], [0, 2, 2], [0, 0, 2], [0, 2, 0], [0, 6, 6], [0, 6, 4], [0, 4, 4], [0, 4, 6]], [[1, 20, 0], [1, 22, 0], [1, 23, 0], [1, 21, 0], [1, 9, 0], [1, 10, 0], [1, 11, 0], [1, 8, 0], [0, 6, 2], [0, 6, 0], [0, 4, 0], [0, 4, 2], [0, 0, 4], [0, 2, 6], [0, 0, 6], [0, 2, 4], [0, 2, 0], [0, 0, 2], [0, 2, 2], [0, 0, 0], [0, 4, 6], [0, 4, 4], [0, 6, 4], [0, 6, 6]], [[1, 22, 0], [1, 20, 0], [1, 21, 0], [1, 23, 0], [1, 10, 0], [1, 9, 0], [1, 8, 0], [1, 11, 0], [0, 6, 0], [0, 6, 2], [0, 4, 2], [0, 4, 0], [0, 2, 6], [0, 0, 4], [0, 2, 4], [0, 0, 6], [0, 0, 2], [0, 2, 0], [0, 0, 0], [0, 2, 2], [0, 4, 4], [0, 4, 6], [0, 6, 6], [0, 6, 4]], [[1, 23, 0], [1, 21, 0], [1, 20, 0], [1, 22, 0], [1, 11, 0], [1, 8, 0], [1, 9, 0], [1, 10, 0], [0, 4, 0], [0, 4, 2], [0, 6, 2], [0, 6, 0], [0, 0, 6], [0, 2, 4], [0, 0, 4], [0, 2, 6], [0, 2, 2], [0, 0, 0], [0, 2, 0], [0, 0, 2], [0, 6, 4], [0, 6, 6], [0, 4, 6], [0, 4, 4]]]], clifford : {"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "YA": 2, "9": 9, "YC": 10, "YB": 6, "YE": 18, "YD": 14, "14": 14, "YF": 22, "16": 16, "phase": 6, "18": 18, "19": 19, "20": 20, "21": 21, "22": 22, "23": 23, "ZC": 11, "pz": 3, "px": 1, "py": 2, "XB": 5, "13": 13, "ZE": 19, "msqz": 6, "msqy": 9, "msqx": 15, "10": 10, "sqz": 5, "sqy": 11, "sqx": 14, "IA": 0, "ZD": 15, "XC": 9, "ZF": 23, "XA": 1, "XF": 21, "ZA": 3, "ZB": 7, "XE": 17, "11": 11, "XD": 13, "hadamard": 10, "IC": 8, "IB": 4, "IE": 16, "ID": 12, "identity": 0, "IF": 20, "17": 17, "15": 15, "12": 12, "8": 8} -}; \ No newline at end of file +}; + diff --git a/static/scripts/tests.js b/static/scripts/tests.js new file mode 100644 index 0000000..8b9c738 --- /dev/null +++ b/static/scripts/tests.js @@ -0,0 +1,4 @@ +QUnit.test( "Adding nodes", function( assert ) { + abj.add_node(0); + assert.ok(abj.node[0].vop === 10, JSON.stringify(abj.node)); +}); diff --git a/static/test.css b/static/test.css new file mode 100644 index 0000000..bc68398 --- /dev/null +++ b/static/test.css @@ -0,0 +1,299 @@ +/*! + * QUnit 1.23.1 + * https://qunitjs.com/ + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license + * https://jquery.org/license + * + * Date: 2016-04-12T17:29Z + */ + +/** Font Family and Sizes */ + +#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult { + font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; +} + +#qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } +#qunit-tests { font-size: smaller; } + + +/** Resets */ + +#qunit-tests, #qunit-header, #qunit-banner, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter { + margin: 0; + padding: 0; +} + + +/** Header */ + +#qunit-header { + padding: 0.5em 0 0.5em 1em; + + color: #FFFFFF; + background-color: #000000; + + font-size: 1.5em; + line-height: 1em; + font-weight: 400; + +} + +#qunit-header a { + text-decoration: none; + color: #FFFFFF; +} + +#qunit-header a:hover, +#qunit-header a:focus { + color: #FFF; +} + +#qunit-testrunner-toolbar label { + display: inline-block; + padding: 0 0.5em 0 0.1em; +} + +#qunit-banner { + height: 5px; +} + +#qunit-testrunner-toolbar { + padding: 0.5em 1em 0.5em 1em; + color: #5E740B; + background-color: #EEE; + overflow: hidden; +} + +#qunit-filteredTest { + padding: 0.5em 1em 0.5em 1em; + background-color: #F4FF77; + color: #366097; +} + +#qunit-userAgent { + padding: 0.5em 1em 0.5em 1em; + background-color: #000000; + color: #FFF; +} + +#qunit-modulefilter-container { + float: right; + padding: 0.2em; +} + +.qunit-url-config { + display: inline-block; + padding: 0.1em; +} + +.qunit-filter { + display: block; + float: right; + margin-left: 1em; +} + +/** Tests: Pass/Fail */ + +#qunit-tests { + list-style-position: inside; +} + +#qunit-tests li { + padding: 0.4em 1em 0.4em 1em; + border-bottom: 1px solid #FFF; + list-style-position: inside; +} + +#qunit-tests > li { + display: none; +} + +#qunit-tests li.running, +#qunit-tests li.pass, +#qunit-tests li.fail, +#qunit-tests li.skipped { + display: list-item; +} + +#qunit-tests.hidepass { + position: relative; +} + +#qunit-tests.hidepass li.running, +#qunit-tests.hidepass li.pass { + visibility: hidden; + position: absolute; + width: 0; + height: 0; + padding: 0; + border: 0; + margin: 0; +} + +#qunit-tests li strong { + cursor: pointer; +} + +#qunit-tests li.skipped strong { + cursor: default; +} + +#qunit-tests li a { + padding: 0.5em; + color: #C2CCD1; + text-decoration: none; +} + +#qunit-tests li p a { + padding: 0.25em; + color: #6B6464; +} +#qunit-tests li a:hover, +#qunit-tests li a:focus { + color: #000; +} + +#qunit-tests li .runtime { + float: right; + font-size: smaller; +} + +.qunit-assert-list { + margin-top: 0.5em; + padding: 0.5em; + + background-color: #FFF; + +} + +.qunit-source { + margin: 0.6em 0 0.3em; +} + +.qunit-collapsed { + display: none; +} + +#qunit-tests table { + border-collapse: collapse; + margin-top: 0.2em; +} + +#qunit-tests th { + text-align: right; + vertical-align: top; + padding: 0 0.5em 0 0; +} + +#qunit-tests td { + vertical-align: top; +} + +#qunit-tests pre { + margin: 0; + white-space: pre-wrap; + word-wrap: break-word; +} + +#qunit-tests del { + background-color: #E0F2BE; + color: #374E0C; + text-decoration: none; +} + +#qunit-tests ins { + background-color: #FFCACA; + color: #500; + text-decoration: none; +} + +/*** Test Counts */ + +#qunit-tests b.counts { color: #000; } +#qunit-tests b.passed { color: #5E740B; } +#qunit-tests b.failed { color: #710909; } + +#qunit-tests li li { + padding: 5px; + background-color: #FFF; + border-bottom: none; + list-style-position: inside; +} + +/*** Passing Styles */ + +#qunit-tests li li.pass { + color: #3C510C; + background-color: #FFF; + border-left: 10px solid #C6E746; +} + +#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } +#qunit-tests .pass .test-name { color: #366097; } + +#qunit-tests .pass .test-actual, +#qunit-tests .pass .test-expected { color: #999; } + +#qunit-banner.qunit-pass { background-color: #C6E746; } + +/*** Failing Styles */ + +#qunit-tests li li.fail { + color: #710909; + background-color: #FFF; + border-left: 10px solid #EE5757; + white-space: pre; +} + + +#qunit-tests .fail { color: #000; background-color: #EE5757; } +#qunit-tests .fail .test-name, +#qunit-tests .fail .module-name { color: #000; } + +#qunit-tests .fail .test-actual { color: #EE5757; } +#qunit-tests .fail .test-expected { color: #008000; } + +#qunit-banner.qunit-fail { background-color: #EE5757; } + +/*** Skipped tests */ + +#qunit-tests .skipped { + background-color: #EBECE9; +} + +#qunit-tests .qunit-skipped-label { + background-color: #F4FF77; + display: inline-block; + font-style: normal; + color: #366097; + line-height: 1.8em; + padding: 0 0.5em; + margin: -0.4em 0.4em -0.4em 0; +} + +/** Result */ + +#qunit-testresult { + padding: 0.5em 1em 0.5em 1em; + + color: #2B81AF; + background-color: #D2E0E6; + + border-bottom: 1px solid #FFF; +} +#qunit-testresult .module-name { + font-weight: 700; +} + +/** Fixture */ + +#qunit-fixture { + position: absolute; + top: -10000px; + left: -10000px; + width: 1000px; + height: 1000px; +} diff --git a/static/test.html b/static/test.html new file mode 100644 index 0000000..4c8a3e6 --- /dev/null +++ b/static/test.html @@ -0,0 +1,23 @@ + + + + + + Testing A&B + + + + + + + + + + + +
+
+ + + + diff --git a/tests/test_nxgraphstate.py b/tests/test_nxgraphstate.py index 3e74667..ab7eb88 100644 --- a/tests/test_nxgraphstate.py +++ b/tests/test_nxgraphstate.py @@ -9,6 +9,4 @@ def simple_test(): g.act_hadamard(0) g.act_hadamard(1) g.act_cz(0, 1) - print g.node[0]["position"] - print nx.to_edgelist(g)