Anders and Briegel in Python
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.7KB

  1. import clifford as lc
  2. from numpy import *
  3. from scipy.linalg import sqrtm
  4. from qi import *
  5. def identify_pauli(m):
  6. """ Given a signed Pauli matrix, name it. """
  7. for sign in (+1, -1):
  8. for pauli_label, pauli in zip("xyz", paulis):
  9. if allclose(sign * pauli, m):
  10. return sign, pauli_label
  11. def test_find_up_to_phase():
  12. """ Test that slightly suspicious function """
  13. assert lc.find_up_to_phase(id) == (0, 0)
  14. assert lc.find_up_to_phase(px) == (1, 0)
  15. assert lc.find_up_to_phase(exp(1j*pi/4.)*ha) == (4, 7)
  16. def get_action(u):
  17. """ What does this unitary operator do to the Paulis? """
  18. return [identify_pauli(u * p * u.H) for p in paulis]
  19. def format_action(action):
  20. return "".join("{}{}".format("+" if s >= 0 else "-", p) for s, p in action)
  21. def test_we_have_24_matrices():
  22. """ Check that we have 24 unique actions on the Bloch sphere """
  23. actions = set(tuple(get_action(u)) for u in lc.unitaries)
  24. assert len(set(actions)) == 24
  25. def test_we_have_all_useful_gates():
  26. """ Check that all the interesting gates are included up to a global phase """
  27. common_us = id, px, py, pz, ha, ph, sqz, msqz, sqy, msqy, sqx, msqx
  28. for u in common_us:
  29. lc.find_up_to_phase(u)
  30. def test_group():
  31. """ Test we are really in a group """
  32. matches = set()
  33. for a in lc.unitaries:
  34. for b in lc.unitaries:
  35. i, phase = lc.find_up_to_phase(a*b)
  36. matches.add(i)
  37. assert len(matches)==24
  38. def test_conjugation_table():
  39. """ Check that the table of Hermitian conjugates is okay """
  40. assert len(set(lc.conjugation_table))==24
  41. def test_times_table():
  42. """ Check the times table """
  43. assert lc.times_table[0][4]==4