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.

43 lines
1.2KB

  1. from graph import *
  2. import viz
  3. import itertools as it
  4. import clifford
  5. #def cphase(a, b):
  6. #""" Act a controlled-phase gate on two qubits """
  7. #if g
  8. def remove_vop(g, vops, a, b):
  9. """ Reduces VOP[a] to the identity, avoiding (if possible) the use of vertex b as a swapping partner """
  10. free_neighbours = g[a] - {b}
  11. c = b if len(free_neighbours) == 0 else free_neighbours.pop()
  12. d = clifford.decompositions[a]
  13. for v in reversed(d):
  14. target = a if v == clifford.by_name["msqx"] else b
  15. local_complementation(g, vops, target)
  16. def local_complementation(g, vops, v):
  17. """ As defined in LISTING 1 of Anders & Briegel """
  18. for i, j in it.combinations(g[v], 2):
  19. toggle_edge(g, i, j)
  20. # Update VOPs
  21. vops[v] = clifford.times_table[vops[v]][clifford.by_name["sqx"]]
  22. for i in g[v]:
  23. vops[i] = clifford.times_table[vops[i]][clifford.by_name["msqz"]]
  24. if __name__ == '__main__':
  25. g, vops = graph()
  26. add_edge(g, 0, 1)
  27. add_edge(g, 1, 2)
  28. add_edge(g, 0, 2)
  29. add_edge(g, 0, 3)
  30. add_edge(g, 6, 7)
  31. pos = viz.draw(g, vops, "out.pdf")
  32. local_complementation(g, vops, 0)
  33. viz.draw(g, vops, "out2.pdf", pos)