Browse Source

Still sketching

master
Pete Shadbolt 7 years ago
parent
commit
15f3e54821
2 changed files with 24 additions and 11 deletions
  1. +7
    -4
      abp/fancy.py
  2. +17
    -7
      abp/lattices.py

+ 7
- 4
abp/fancy.py View File

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


+ 17
- 7
abp/lattices.py View File

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


Loading…
Cancel
Save