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.

преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. from nose.tools import raises
  8. def identify_pauli(m):
  9. """ Given a signed Pauli matrix, name it. """
  10. for sign in (+1, -1):
  11. for pauli_label, pauli in zip("xyz", qi.paulis):
  12. if allclose(sign * pauli, m):
  13. return sign, pauli_label
  14. def test_find_clifford():
  15. """ Test that slightly suspicious function """
  16. assert clifford.find_clifford(qi.id, clifford.unitaries) == 0
  17. assert clifford.find_clifford(qi.px, clifford.unitaries) == 1
  18. @raises(IndexError)
  19. def test_find_non_clifford():
  20. """ Test that looking for a non-Clifford gate fails """
  21. clifford.find_clifford(qi.t, clifford.unitaries)
  22. def get_action(u):
  23. """ What does this unitary operator do to the Paulis? """
  24. return [identify_pauli(u.dot(p.dot(qi.hermitian_conjugate(u)))) for p in qi.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 clifford.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. for name, u in qi.by_name.items():
  34. clifford.find_clifford(u, clifford.unitaries)
  35. def test_group():
  36. """ Test we are really in a group """
  37. matches = set()
  38. for a, b in tqdm(it.combinations(clifford.unitaries, 2), "Testing this is a group"):
  39. i = clifford.find_clifford(a.dot(b), clifford.unitaries)
  40. matches.add(i)
  41. assert len(matches) == 24
  42. def test_conjugation_table():
  43. """ Check that the table of Hermitian conjugates is okay """
  44. assert len(set(clifford.conjugation_table)) == 24
  45. def test_times_table():
  46. """ Check the times table """
  47. assert clifford.times_table[0][4] == 4
  48. def test_cz_table_makes_sense():
  49. """ Test the CZ table is symmetric """
  50. hadamard = clifford.by_name["hadamard"]
  51. assert all(clifford.cz_table[0, 0, 0] == [1, 0, 0])
  52. assert all(clifford.cz_table[1, 0, 0] == [0, 0, 0])
  53. assert all(
  54. clifford.cz_table[0, hadamard, hadamard] == [0, hadamard, hadamard])
  55. def test_commuters():
  56. """ Test that commutation is good """
  57. assert len(clifford.get_commuters(clifford.unitaries)) == 4