Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
864B

  1. import networkx as nx
  2. import graphstate
  3. import clifford
  4. class NXGraphState(graphstate.GraphState, nx.Graph):
  5. """ This is GraphState with NetworkX-like abilities """
  6. def __init__(self, *args, **kwargs):
  7. graphstate.GraphState.__init__(self, *args, **kwargs)
  8. def layout(self):
  9. """ Automatically lay out the graph """
  10. pos = nx.spring_layout(self, dim=3, scale=np.sqrt(self.order()))
  11. middle = np.average(pos.values(), axis=0)
  12. pos = {key: value - middle for key, value in pos.items()}
  13. for key, (x, y, z) in pos.items():
  14. self.node[key]["position"] = util.xyz(x, y, z)
  15. def add_vops(self):
  16. """ Automatically add vops if they're not present """
  17. for key in self.node:
  18. if not "vop" in self.node[key]:
  19. self.node[key]["vop"] = clifford.identity