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.

67 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 test_find_up_to_phase():
  18. """ Test that slightly suspicious function """
  19. assert lc.find_up_to_phase(lc.id) == (0, 0)
  20. assert lc.find_up_to_phase(lc.px) == (1, 0)
  21. assert lc.find_up_to_phase(exp(1j*pi/4.)*lc.ha) == (4, 7)
  22. def get_action(u):
  23. """ What does this unitary operator do to the Paulis? """
  24. return [identify_pauli(u * p * u.H) for p in paulis]
  25. def format_action(action):
  26. return "".join("{}{}".format("+" if s >= 0 else "-", p) for s, p in action)
  27. def test_we_have_24_matrices():
  28. """ Check that we have 24 unique actions on the Bloch sphere """
  29. actions = set(tuple(get_action(u)) for u in lc.unitaries)
  30. assert len(set(actions)) == 24
  31. def test_we_have_all_useful_gates():
  32. """ Check that all the interesting gates are included up to a global phase """
  33. common_us = lc.id, lc.px, lc.py, lc.pz, lc.ha, lc.ph, sqz, msqz, sqy, msqy, sqx, msqx
  34. for u in common_us:
  35. lc.find_up_to_phase(u)
  36. def test_group():
  37. """ Test we are really in a group """
  38. matches = set()
  39. for a in lc.unitaries:
  40. for b in lc.unitaries:
  41. i, phase = lc.find_up_to_phase(a*b)
  42. matches.add(i)
  43. assert len(matches)==24
  44. def test_conjugation_table():
  45. """ Check that the table of Hermitian conjugates is okay """
  46. assert len(set(lc.conjugation_table))==24
  47. def test_times_table():
  48. """ Check the times table """
  49. assert lc.times_table[0][4]==4