Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

62 lignes
1.8KB

  1. """
  2. This is a sketch of a consistent language for defining resource states and lattices.
  3. """
  4. import networkx as nx
  5. from abp.fancy import GraphState
  6. def union(*graphs):
  7. """ Assumes that all graphs are completely independent and uniquely labelled """
  8. output = nx.Graph()
  9. output.node = dict(i for g in graphs for i in g.node.items())
  10. output.adj = dict(i for g in graphs for i in g.adj.items())
  11. return output
  12. def relabel(g, label):
  13. """ Shorthand relabel """
  14. return nx.relabel_nodes(g, lambda x: (label, x))
  15. def fuse(psi, na, nb):
  16. """ Deterministic fusion for testing purposes """
  17. neighbors_a, neighbors_b = psi.neighbors(na), psi.neighbors(nb)
  18. new_edges = ((i, j) for i in neighbors_a for j in neighbors_b if i != j)
  19. psi.add_edges_from(new_edges)
  20. psi.remove_nodes_from((na, nb))
  21. return psi
  22. def ghz(label):
  23. """ A 3-GHZ state """
  24. psi = nx.Graph(((0, 1), (1, 2)))
  25. return relabel(psi, label)
  26. def microcluster(label):
  27. """ A microcluster """
  28. psi = union(ghz(0), ghz(1), ghz(2))
  29. psi = fuse(psi, (0, 1), (1, 0))
  30. psi = fuse(psi, (1, 2), (2, 1))
  31. return relabel(psi, label)
  32. def unit_cell(label):
  33. """ A simple ring-like unit cell """
  34. psi = union(microcluster(0), microcluster(1), microcluster(2), microcluster(3))
  35. psi = fuse(psi, (0, (0, 2)), (1, (2, 2)))
  36. psi = fuse(psi, (1, (0, 2)), (2, (2, 2)))
  37. psi = fuse(psi, (2, (0, 2)), (3, (2, 2)))
  38. psi = fuse(psi, (3, (0, 2)), (0, (2, 2)))
  39. return relabel(psi, label)
  40. def position(node):
  41. print node
  42. return {}
  43. def annotate(g, f):
  44. """ Annotate a graph """
  45. for node in g.nodes():
  46. g.node[node].update(f(node))
  47. if __name__ == '__main__':
  48. psi = union(unit_cell((0, 0)), unit_cell((2, 0)))
  49. annotate(psi, position)
  50. g = GraphState(psi)