From 15f3e548213fafa22966fbb1c482bb7937da2ce5 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Fri, 19 Aug 2016 12:18:18 +0100 Subject: [PATCH] Still sketching --- abp/fancy.py | 11 +++++++---- abp/lattices.py | 24 +++++++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/abp/fancy.py b/abp/fancy.py index 3d7a2c3..25b1f87 100644 --- a/abp/fancy.py +++ b/abp/fancy.py @@ -1,6 +1,6 @@ import time, atexit, json import sys -import networkx +import networkx as nx import numpy as np import websocket from socket import error as socket_error @@ -8,9 +8,12 @@ import graphstate import clifford import util -class GraphState(graphstate.GraphState, networkx.Graph): +class GraphState(graphstate.GraphState, nx.Graph): def __init__(self, *args, **kwargs): - graphstate.GraphState.__init__(self, *args, **kwargs) + if type(args[0])==nx.Graph: + self.from_nx(args[0]) + else: + graphstate.GraphState.__init__(self, *args, **kwargs) self.connect_to_server() def connect_to_server(self, uri = "ws://localhost:5000"): @@ -59,7 +62,7 @@ class GraphState(graphstate.GraphState, networkx.Graph): def layout(self): """ Automatically lay out the graph """ - pos = networkx.spring_layout(self, dim=3, scale=np.sqrt(self.order())) + pos = nx.spring_layout(self, dim=3, scale=np.sqrt(self.order())) middle = np.average(pos.values(), axis=0) pos = {key: value - middle for key, value in pos.items()} for key, (x, y, z) in pos.items(): diff --git a/abp/lattices.py b/abp/lattices.py index 70d3c45..a1b4bb7 100644 --- a/abp/lattices.py +++ b/abp/lattices.py @@ -1,3 +1,7 @@ +""" +This is a sketch of a consistent language for defining resource states and lattices. +""" + import networkx as nx from abp.fancy import GraphState @@ -39,13 +43,19 @@ def unit_cell(label): psi = fuse(psi, (1, (0, 2)), (2, (2, 2))) psi = fuse(psi, (2, (0, 2)), (3, (2, 2))) psi = fuse(psi, (3, (0, 2)), (0, (2, 2))) - return psi + return relabel(psi, label) + +def position(node): + print node + return {} + +def annotate(g, f): + """ Annotate a graph """ + for node in g.nodes(): + g.node[node].update(f(node)) if __name__ == '__main__': - #print ghz(0).nodes() - #print ghz(1).nodes() - #print fuse(ghz(0), ghz(1), (0, 2), (1, 0)).adj - #print microcluster("pete").nodes() - g = GraphState() - g.from_nx(unit_cell("pete")) + psi = union(unit_cell((0, 0)), unit_cell((2, 0))) + annotate(psi, position) + g = GraphState(psi)