Anders and Briegel in Python
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

21 Zeilen
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)