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.

21 lines
745B

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