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.

49 lines
1.4KB

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