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.

45 lines
1.3KB

  1. import networkx as nx
  2. from abp.fancy import GraphState
  3. def fast_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(a, b, na, nb):
  13. """ Deterministic fusion for testing purposes """
  14. psi = fast_union((a, b))
  15. neighbors_a, neighbors_b = psi.neighbors(na), psi.neighbors(nb)
  16. new_edges = ((i, j) for i in neighbors_a for j in neighbors_b if i != j)
  17. psi.add_edges_from(new_edges)
  18. psi.remove_nodes_from((na, nb))
  19. return psi
  20. def ghz(label):
  21. """ A 3-GHZ state """
  22. psi = nx.Graph(((0, 1), (1, 2)))
  23. return relabel(psi, label)
  24. def microcluster(label):
  25. """ A microcluster """
  26. psi = fuse(ghz(0), ghz(1), (0, 1), (1, 0))
  27. psi = fuse(psi, ghz(2), (1, 2), (2, 1))
  28. return relabel(psi, label)
  29. if __name__ == '__main__':
  30. print ghz(0).nodes()
  31. print ghz(1).nodes()
  32. print fuse(ghz(0), ghz(1), (0, 2), (1, 0)).adj
  33. print microcluster("pete").nodes()
  34. g = GraphState()
  35. g.from_nx(microcluster("pete"))
  36. print g.to_stabilizer()