Anders and Briegel in Python
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

52 lines
1.6KB

  1. import networkx as nx
  2. from abp.fancy import GraphState
  3. def union(*graphs):
  4. """ Assumes that all graphs are completely independent and uniquely labelled """
  5. output = nx.Graph()
  6. output.node = dict(i for g in graphs for i in g.node.items())
  7. output.adj = dict(i for g in graphs for i in g.adj.items())
  8. return output
  9. def relabel(g, label):
  10. """ Shorthand relabel """
  11. return nx.relabel_nodes(g, lambda x: (label, x))
  12. def fuse(psi, na, nb):
  13. """ Deterministic fusion for testing purposes """
  14. neighbors_a, neighbors_b = psi.neighbors(na), psi.neighbors(nb)
  15. new_edges = ((i, j) for i in neighbors_a for j in neighbors_b if i != j)
  16. psi.add_edges_from(new_edges)
  17. psi.remove_nodes_from((na, nb))
  18. return psi
  19. def ghz(label):
  20. """ A 3-GHZ state """
  21. psi = nx.Graph(((0, 1), (1, 2)))
  22. return relabel(psi, label)
  23. def microcluster(label):
  24. """ A microcluster """
  25. psi = union(ghz(0), ghz(1), ghz(2))
  26. psi = fuse(psi, (0, 1), (1, 0))
  27. psi = fuse(psi, (1, 2), (2, 1))
  28. return relabel(psi, label)
  29. def unit_cell(label):
  30. """ A simple ring-like unit cell """
  31. psi = union(microcluster(0), microcluster(1), microcluster(2), microcluster(3))
  32. psi = fuse(psi, (0, (0, 2)), (1, (2, 2)))
  33. psi = fuse(psi, (1, (0, 2)), (2, (2, 2)))
  34. psi = fuse(psi, (2, (0, 2)), (3, (2, 2)))
  35. psi = fuse(psi, (3, (0, 2)), (0, (2, 2)))
  36. return psi
  37. if __name__ == '__main__':
  38. #print ghz(0).nodes()
  39. #print ghz(1).nodes()
  40. #print fuse(ghz(0), ghz(1), (0, 2), (1, 0)).adj
  41. #print microcluster("pete").nodes()
  42. g = GraphState()
  43. g.from_nx(unit_cell("pete"))