Kaynağa Gözat

Repair missing VOPs

master
Pete Shadbolt 8 yıl önce
ebeveyn
işleme
35ddc3397a
3 değiştirilmiş dosya ile 12 ekleme ve 2 silme
  1. +10
    -0
      abp/fancy.py
  2. +1
    -1
      examples/lattice_demo.py
  3. +1
    -1
      examples/mix_graph_and_networkx.py

+ 10
- 0
abp/fancy.py Dosyayı Görüntüle

@@ -4,6 +4,7 @@ import numpy as np
import websocket
from socket import error as socket_error
import graphstate
import clifford
import util

class GraphState(graphstate.GraphState, networkx.Graph):
@@ -33,6 +34,9 @@ class GraphState(graphstate.GraphState, networkx.Graph):
if not all(("position" in node) for node in self.node.values()):
self.layout()

if not all(("vop" in node) for node in self.node.values()):
self.add_vops()

# Send data to browser and rate-limit
self.ws.send(json.dumps(self.to_json()))
time.sleep(delay)
@@ -45,4 +49,10 @@ class GraphState(graphstate.GraphState, networkx.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.by_name["identity"]


+ 1
- 1
examples/lattice_demo.py Dosyayı Görüntüle

@@ -30,7 +30,7 @@ def lattice(unit_cell, size):
return nodes, edges

# s = VisibleGraphState()
nodes, edges = lattice(square_unit_cell, (4, 4))
nodes, edges = lattice(square_unit_cell, (10, 10))

psi = GraphState()
for node in nodes:


+ 1
- 1
examples/mix_graph_and_networkx.py Dosyayı Görüntüle

@@ -1,6 +1,6 @@
from abp.fancy import GraphState

g = GraphState()
n = 10
n = 100
g.add_nodes_from(range(n))
g.add_edges_from([i, i+1] for i in range(n-1))

Yükleniyor…
İptal
Kaydet