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.

57 lines
1.9KB

  1. import clifford as lc
  2. from numpy import *
  3. from scipy.linalg import sqrtm
  4. sqy = sqrtm(1j*lc.py)
  5. msqy = sqrtm(-1j*lc.py)
  6. sqz = sqrtm(1j*lc.pz)
  7. msqz = sqrtm(-1j*lc.pz)
  8. sqx = sqrtm(1j*lc.px)
  9. msqx = sqrtm(-1j*lc.px)
  10. paulis = (lc.px, lc.py, lc.pz)
  11. def identify_pauli(m):
  12. """ Given a signed Pauli matrix, name it. """
  13. for sign in (+1, -1):
  14. for pauli_label, pauli in zip("xyz", paulis):
  15. if allclose(sign * pauli, m):
  16. return sign, pauli_label
  17. def get_action(u):
  18. """ What does this unitary operator do to the Paulis? """
  19. return [identify_pauli(u * p * u.H) for p in paulis]
  20. def format_action(action):
  21. return "".join("{}{}".format("+" if s>=0 else "-", p) for s, p in action)
  22. def test_we_have_all_useful_gates():
  23. """ Check that all the interesting gates are included up to a global phase """
  24. names = "i", "px", "py", "pz", "h", "p"
  25. unitaries = lc.i, lc.px, lc.py, lc.pz, lc.h, lc.p
  26. for name, unitary in zip(names, unitaries):
  27. foundit = False
  28. for i, clifford in enumerate(lc.unitaries):
  29. if allclose(clifford, unitary):
  30. foundit = True
  31. print "{}\t=\tlc.unitaries[{}]".format(name, i)
  32. assert foundit
  33. names = "sqrt(ix)", "sqrt(-ix)", "sqrt(iy)", "sqrt(-iy)", "sqrt(iz)", "sqrt(-iz)",
  34. unitaries = sqz, msqz, sqy, msqy, sqx, msqx
  35. for name, unitary in zip(names, unitaries):
  36. foundit = False
  37. for phase in range(8):
  38. for i, clifford in enumerate(lc.unitaries):
  39. if allclose(exp(1j*phase*pi/4.)*clifford, unitary):
  40. foundit = True
  41. print "{}\t=\texp({} . i . pi/4).lc.unitaries[{}]".format(name, phase, i)
  42. assert foundit
  43. def test_we_have_24_matrices():
  44. """ Check that we have 24 unique actions on the Bloch sphere """
  45. actions = set(tuple(get_action(u)) for u in lc.unitaries)
  46. assert len(set(actions)) == 24