Browse Source

Magical networkx integration :sparkling_heart:

master
Pete Shadbolt 8 years ago
parent
commit
513e09b681
4 changed files with 22 additions and 4 deletions
  1. +1
    -0
      .agignore
  2. +5
    -4
      abp/graphstate.py
  3. +2
    -0
      abp/util.py
  4. +14
    -0
      tests/test_nxgraphstate.py

+ 1
- 0
.agignore View File

@@ -0,0 +1 @@
static/scripts/three.js

+ 5
- 4
abp/graphstate.py View File

@@ -6,9 +6,12 @@ import itertools as it
import clifford import clifford
import json import json
import qi import qi
import networkx as nx
try:
from networkx import Graph as NXGraph
except ImportError:
NXGraph = object


class GraphState(object):
class GraphState(NXGraph):


def __init__(self, nodes=[]): def __init__(self, nodes=[]):
self.adj, self.node = {}, {} self.adj, self.node = {}, {}
@@ -196,5 +199,3 @@ class GraphState(object):
""" Check equality between graphs """ """ Check equality between graphs """
return self.adj == other.adj and self.node == other.node return self.adj == other.adj and self.node == other.node





+ 2
- 0
abp/util.py View File

@@ -0,0 +1,2 @@
def xyz(x, y, z=0):
return {"x": x, "y": y, "z": z}

+ 14
- 0
tests/test_nxgraphstate.py View File

@@ -0,0 +1,14 @@
from abp.graphstate import GraphState
from abp.util import xyz
import networkx as nx

def simple_test():
g = GraphState()
g.add_node(0, xyz(0, 0, 0))
g.add_node(1, xyz(0, 0, 0))
g.act_hadamard(0)
g.act_hadamard(1)
g.act_cz(0, 1)
print g.node[0]["position"]
print nx.to_edgelist(g)


Loading…
Cancel
Save