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.

41 lines
1.1KB

  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, avoid):
  9. """ Reduces VOP[a] to the identity, avoiding (if possible) the use of vertex b as a swapping partner """
  10. others = g[a] - {avoid}
  11. swap_qubit = others.pop() if others else avoid
  12. for v in reversed(clifford.decompositions[vops[a]]):
  13. local_complementation(g, vops, a if v == "x" else swap_qubit)
  14. def local_complementation(g, vops, v):
  15. """ As defined in LISTING 1 of Anders & Briegel """
  16. for i, j in it.combinations(g[v], 2):
  17. toggle_edge(g, i, j)
  18. # Update VOPs
  19. vops[v] = clifford.times_table[vops[v]][clifford.by_name["sqx"]]
  20. for i in g[v]:
  21. vops[i] = clifford.times_table[vops[i]][clifford.by_name["msqz"]]
  22. if __name__ == '__main__':
  23. g, vops = graph()
  24. add_edge(g, 0, 1)
  25. add_edge(g, 1, 2)
  26. add_edge(g, 0, 2)
  27. add_edge(g, 0, 3)
  28. add_edge(g, 6, 7)
  29. pos = viz.draw(g, vops, "out.pdf")
  30. remove_vop(g, vops, 0, 1)
  31. remove_vop(g, vops, 1, 2)
  32. viz.draw(g, vops, "out2.pdf", pos)