Anders and Briegel in Python
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

test_clifford.py 1.8KB

hace 8 años
hace 8 años
hace 8 años
hace 8 años
hace 8 años
hace 8 años
hace 8 años
hace 8 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import clifford as lc
  2. from numpy import *
  3. from scipy.linalg import sqrtm
  4. from qi import *
  5. from tqdm import tqdm
  6. import itertools as it
  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", paulis):
  11. if allclose(sign * pauli, m):
  12. return sign, pauli_label
  13. def _test_find_up_to_phase():
  14. """ Test that slightly suspicious function """
  15. assert lc.find_up_to_phase(id) == (0, 0)
  16. assert lc.find_up_to_phase(px) == (1, 0)
  17. assert lc.find_up_to_phase(exp(1j*pi/4.)*ha) == (4, 7)
  18. def get_action(u):
  19. """ What does this unitary operator do to the Paulis? """
  20. return [identify_pauli(u * p * u.H) for p in 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 lc.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. common_us = id, px, py, pz, ha, ph, sqz, msqz, sqy, msqy, sqx, msqx
  30. for u in common_us:
  31. lc.find_up_to_phase(u)
  32. def test_group():
  33. """ Test we are really in a group """
  34. matches = set()
  35. for a, b in tqdm(it.combinations(lc.unitaries, 2), "Testing this is a group"):
  36. i, phase = lc.find_up_to_phase(a*b)
  37. matches.add(i)
  38. assert len(matches)==24
  39. def test_conjugation_table():
  40. """ Check that the table of Hermitian conjugates is okay """
  41. assert len(set(lc.conjugation_table))==24
  42. def test_times_table():
  43. """ Check the times table """
  44. assert lc.times_table[0][4]==4