From 8bd121aec0b518b40caa2d5ee790034f67fb90a6 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Mon, 23 Oct 2017 19:16:05 -0700 Subject: [PATCH] Example is working now --- abp/__init__.py | 1 - abp/graphstate.py | 12 ++++ examples/visualization/auto_layout.py | 52 ----------------- examples/visualization/grid_2d.py | 24 -------- .../issues/unpositioned_nodes.py | 20 ------- examples/visualization/lattice_2d.py | 45 --------------- examples/visualization/lattice_3d.py | 56 ------------------- examples/visualization/new.py | 8 --- examples/visualization/raussendorf.py | 5 +- examples/visualization/stress.py | 46 --------------- 10 files changed, 14 insertions(+), 255 deletions(-) delete mode 100644 examples/visualization/auto_layout.py delete mode 100644 examples/visualization/grid_2d.py delete mode 100644 examples/visualization/issues/unpositioned_nodes.py delete mode 100644 examples/visualization/lattice_2d.py delete mode 100644 examples/visualization/lattice_3d.py delete mode 100644 examples/visualization/new.py delete mode 100644 examples/visualization/stress.py 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