Anders and Briegel in Python
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

80 linhas
2.4KB

  1. from numpy import *
  2. from tqdm import tqdm
  3. import itertools as it
  4. from abp import clifford
  5. from abp import qi
  6. from nose.tools import raises
  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_clifford():
  14. """ Test that slightly suspicious function """
  15. assert clifford.find_clifford(qi.id, clifford.unitaries) == 0
  16. assert clifford.find_clifford(qi.px, clifford.unitaries) == 1
  17. @raises(IndexError)
  18. def test_find_non_clifford():
  19. """ Test that looking for a non-Clifford gate fails """
  20. clifford.find_clifford(qi.t, clifford.unitaries)
  21. def get_action(u):
  22. """ What does this unitary operator do to the Paulis? """
  23. return [identify_pauli(u.dot(p.dot(qi.hermitian_conjugate(u)))) for p in qi.paulis]
  24. def format_action(action):
  25. return "".join("{}{}".format("+" if s >= 0 else "-", p) for s, p in action)
  26. def test_we_have_24_matrices():
  27. """ Check that we have 24 unique actions on the Bloch sphere """
  28. actions = set(tuple(get_action(u)) for u in clifford.unitaries)
  29. assert len(set(actions)) == 24
  30. def test_we_have_all_useful_gates():
  31. """ Check that all the interesting gates are included up to a global phase """
  32. for name, u in qi.by_name.items():
  33. clifford.find_clifford(u, clifford.unitaries)
  34. def test_group():
  35. """ Test we are really in a group """
  36. matches = set()
  37. for a, b in tqdm(it.combinations(clifford.unitaries, 2), "Testing this is a group"):
  38. i = clifford.find_clifford(a.dot(b), clifford.unitaries)
  39. matches.add(i)
  40. assert len(matches) == 24
  41. def test_conjugation_table():
  42. """ Check that the table of Hermitian conjugates is okay """
  43. assert len(set(clifford.conjugation_table)) == 24
  44. def test_times_table():
  45. """ Check the times table """
  46. assert clifford.times_table[0][4] == 4
  47. def test_cz_table_makes_sense():
  48. """ Test the CZ table is symmetric """
  49. hadamard = clifford.by_name["hadamard"]
  50. assert all(clifford.cz_table[0, 0, 0] == [1, 0, 0])
  51. assert all(clifford.cz_table[1, 0, 0] == [0, 0, 0])
  52. assert all(
  53. clifford.cz_table[0, hadamard, hadamard] == [0, hadamard, hadamard])
  54. def test_commuters():
  55. """ Test that commutation is good """
  56. assert len(clifford.get_commuters(clifford.unitaries)) == 4