소스 검색

Now working without fancy.py.

master
Pete Shadbolt 8 년 전
부모
커밋
89b603e00c
4개의 변경된 파일46개의 추가작업 그리고 7개의 파일을 삭제
  1. +1
    -0
      abp/__init__.py
  2. +2
    -7
      abp/nxgraphstate.py
  3. +35
    -0
      abp/vizclient.py
  4. +8
    -0
      examples/visualization/new.py

+ 1
- 0
abp/__init__.py 파일 보기

@@ -1,6 +1,7 @@
# 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

+ 2
- 7
abp/nxgraphstate.py 파일 보기

@@ -1,6 +1,8 @@
import networkx as nx
import numpy as np
import graphstate
import clifford
import util

class NXGraphState(graphstate.GraphState, nx.Graph):
""" This is GraphState with NetworkX-like abilities """
@@ -15,10 +17,3 @@ class NXGraphState(graphstate.GraphState, nx.Graph):
for key, (x, y, z) in pos.items():
self.node[key]["position"] = util.xyz(x, y, z)

def add_vops(self):
""" Automatically add vops if they're not present """
for key in self.node:
if not "vop" in self.node[key]:
self.node[key]["vop"] = clifford.identity


+ 35
- 0
abp/vizclient.py 파일 보기

@@ -0,0 +1,35 @@
import time, atexit, json
import networkx as nx
import numpy as np
import websocket
from socket import error as socket_error
import clifford
import util
import nxgraphstate

class VizClient(object):
def __init__(self, uri = "ws://localhost:5000"):
self.ws = websocket.create_connection(uri, timeout=0.1)
atexit.register(self.shutdown)

def shutdown(self):
""" Close the connection to the websocket """
self.ws.close()

def update(self, graph, delay = 0.5):
""" Call this function when you are ready to send data to the browser """
g = nxgraphstate.NXGraphState(graph)

# Automatically perform layout if position is not provided
if not all(("position" in node) for node in g.node.values()):
g.layout()

# Send data to browser and rate-limit
try:
self.ws.send(json.dumps(g.to_json(stringify=True)))
self.ws.recv()
except websocket._exceptions.WebSocketTimeoutException:
print "Timed out ... you might be pushing a bit hard"
time.sleep(delay)



+ 8
- 0
examples/visualization/new.py 파일 보기

@@ -0,0 +1,8 @@
from abp import GraphState, VizClient
from abp.util import xyz

v = VizClient()
g = GraphState(5)
for i in range(5):
g.node[i]["position"] = xyz(i, 0, 0)
v.update(g)

불러오는 중...
취소
저장