Bläddra i källkod

Magical networkx integration :sparkling_heart:

master
Pete Shadbolt 8 år sedan
förälder
incheckning
513e09b681
4 ändrade filer med 22 tillägg och 4 borttagningar
  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 Visa fil

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

+ 5
- 4
abp/graphstate.py Visa fil

@@ -6,9 +6,12 @@ import itertools as it
import clifford
import json
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=[]):
self.adj, self.node = {}, {}
@@ -196,5 +199,3 @@ class GraphState(object):
""" Check equality between graphs """
return self.adj == other.adj and self.node == other.node




+ 2
- 0
abp/util.py Visa fil

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

+ 14
- 0
tests/test_nxgraphstate.py Visa fil

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


Laddar…
Avbryt
Spara