Anders and Briegel in Python
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

54 wiersze
1.9KB

  1. """
  2. Enumerates the 24 elements of the local Clifford group, providing multiplication and conjugation tables
  3. permutations = (id, ha, ph, ha*ph, ha*ph*ha, ha*ph*ha*ph)
  4. signs = (id, px, py, pz)
  5. unitaries = [p*s for p in permutations for s in signs]
  6. """
  7. import numpy as np
  8. from tqdm import tqdm
  9. import qi
  10. from functools import reduce
  11. from util import cache_to_disk
  12. # TODO: make this more efficient / shorter
  13. def find_up_to_phase(u):
  14. """ Find the index of a given u within a list of unitaries, up to a global phase """
  15. for i, t in enumerate(unitaries):
  16. for phase in range(8):
  17. if np.allclose(t, np.exp(1j * phase * np.pi / 4.) * u):
  18. return i, phase
  19. raise IndexError
  20. def compose_u(decomposition):
  21. """ Get the unitary representation of a particular decomposition """
  22. us = (elements[c] for c in decomposition)
  23. return np.matrix(reduce(np.dot, us), dtype=complex)
  24. def name_of(vop):
  25. """ Get the formatted name of a VOP """
  26. return "%s" % get_name[vop] if vop in get_name else "VOP%d" % vop
  27. @cache_to_disk("clifford_tables.pkl")
  28. def construct_tables():
  29. """ Constructs / caches multiplication and conjugation tables """
  30. by_name = {name: find_up_to_phase(u)[0] for name, u in qi.by_name.items()}
  31. get_name = {v:k for k, v in by_name.items()}
  32. conjugation_table = [find_up_to_phase(u.H)[0]
  33. for i, u in enumerate(unitaries)]
  34. times_table = [[find_up_to_phase(u * v)[0] for v in unitaries]
  35. for u in tqdm(unitaries)]
  36. return by_name, get_name, conjugation_table, times_table
  37. # Various useful tables
  38. decompositions = ("xxxx", "xx", "zzxx", "zz", "zxx", "z", "zzz", "xxz",
  39. "xzx", "xzxxx", "xzzzx", "xxxzx", "xzz", "zzx", "xxx", "x",
  40. "zzzx", "xxzx", "zx", "zxxx", "xxxz", "xzzz", "xz", "xzxx")
  41. elements = {"x": qi.sqx, "z": qi.msqz}
  42. unitaries = [compose_u(d) for d in decompositions]
  43. by_name, get_name, conjugation_table, times_table = construct_tables()