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.

60 lines
1.8KB

  1. from numpy import *
  2. from scipy.linalg import sqrtm
  3. from tqdm import tqdm
  4. import itertools as it
  5. from abp import clifford
  6. from abp import qi
  7. def identify_pauli(m):
  8. """ Given a signed Pauli matrix, name it. """
  9. for sign in (+1, -1):
  10. for pauli_label, pauli in zip("xyz", qi.paulis):
  11. if allclose(sign * pauli, m):
  12. return sign, pauli_label
  13. def _test_find():
  14. """ Test that slightly suspicious function """
  15. assert lc.find(id, lc.unitaries) == 0
  16. assert lc.find(px, lc.unitaries) == 1
  17. assert lc.find(exp(1j*pi/4.)*ha, lc.unitaries) == 4
  18. def get_action(u):
  19. """ What does this unitary operator do to the Paulis? """
  20. return [identify_pauli(u.dot(p.dot(qi.hermitian_conjugate(u)))) for p in qi.paulis]
  21. def format_action(action):
  22. return "".join("{}{}".format("+" if s >= 0 else "-", p) for s, p in action)
  23. def test_we_have_24_matrices():
  24. """ Check that we have 24 unique actions on the Bloch sphere """
  25. actions = set(tuple(get_action(u)) for u in clifford.unitaries)
  26. assert len(set(actions)) == 24
  27. def test_we_have_all_useful_gates():
  28. """ Check that all the interesting gates are included up to a global phase """
  29. for name, u in qi.by_name.items():
  30. clifford.find_clifford(u, clifford.unitaries)
  31. def _test_group():
  32. """ Test we are really in a group """
  33. matches = set()
  34. for a, b in tqdm(it.combinations(clifford.unitaries, 2), "Testing this is a group"):
  35. i, phase = clifford.find_clifford(a.dot(b), clifford.unitaries)
  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(clifford.conjugation_table))==24
  41. def test_times_table():
  42. """ Check the times table """
  43. assert clifford.times_table[0][4]==4