diff --git a/abp/__init__.py b/abp/__init__.py index 93593a4..48827db 100644 --- a/abp/__init__.py +++ b/abp/__init__.py @@ -1,7 +1,6 @@ # Alias some stuff to make imports cleaner from abp.graphstate import GraphState from abp.nxgraphstate import NXGraphState -from abp.vizclient import VizClient from abp.qi import CircuitModel DETERMINISTIC = False diff --git a/abp/graphstate.py b/abp/graphstate.py index a206075..2ce95e6 100755 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -9,6 +9,7 @@ import json, random from . import qi, clifford, util import abp from .stabilizer import Stabilizer +import requests class GraphState(object): @@ -26,6 +27,7 @@ class GraphState(object): """ self.adj, self.node = {}, {} + self.url = None try: # Cloning from a networkx graph self.adj = data.adj.copy() @@ -492,3 +494,13 @@ class GraphState(object): g.adj = self.adj.copy() return g + def show(self): + """ Shares the state on the server and displays browser """ + if self.url == None: + self.url = requests.get("https://abv.peteshadbolt.co.uk/").url + + data = json.dumps(self.to_json(stringify=True)) + print("Shared state to {}".format(self.url)) + return requests.post("{}/graph".format(self.url), data=data) + + diff --git a/examples/visualization/auto_layout.py b/examples/visualization/auto_layout.py deleted file mode 100644 index 17732c9..0000000 --- a/examples/visualization/auto_layout.py +++ /dev/null @@ -1,52 +0,0 @@ -from abp import GraphState, VizClient -from abp.util import xyz -import numpy as np -import time -import itertools -import networkx as nx - -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(*list(map(range, size))): - edges |= offset_unit_cell(unit_cell, offset) - - nodes = set(itertools.chain(*edges)) - return nodes, edges - -nodes, edges = lattice(threedee_unit_cell, (3, 3, 3)) - -psi = GraphState(nodes) - -for a, b in edges: - psi.act_cz(a, b) - -v = VizClient() -v.update(psi) diff --git a/examples/visualization/grid_2d.py b/examples/visualization/grid_2d.py deleted file mode 100644 index 59c8bfc..0000000 --- a/examples/visualization/grid_2d.py +++ /dev/null @@ -1,24 +0,0 @@ -from abp import GraphState, VizClient -from abp.util import xyz -import itertools - -def grid_2d(width, height): - """ Make a 2D grid """ - psi = GraphState() - grid = list(itertools.product(list(range(width)), list(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