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.

59 lines
1.8KB

  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. @cache_to_disk("tables.pkl")
  25. def construct_tables():
  26. """ Constructs / caches multiplication and conjugation tables """
  27. conjugation_table = [find_up_to_phase(u.H)[0]
  28. for i, u in enumerate(unitaries)]
  29. times_table = [[find_up_to_phase(u * v)[0] for v in unitaries]
  30. for u in tqdm(unitaries)]
  31. return conjugation_table, times_table
  32. # Various useful tables
  33. decompositions = ("xxxx", "xx", "zzxx", "zz", "zxx", "z", "zzz", "xxz",
  34. "xzx", "xzxxx", "xzzzx", "xxxzx", "xzz", "zzx", "xxx", "x",
  35. "zzzx", "xxzx", "zx", "zxxx", "xxxz", "xzzz", "xz", "xzxx")
  36. elements = {"x": qi.sqx, "z": qi.msqz}
  37. unitaries = [compose_u(d) for d in decompositions]
  38. conjugation_table, times_table = construct_tables()
  39. # TODO: generate these global names automatically via search
  40. sqx = 15
  41. msqz = 5
  42. if __name__ == '__main__':
  43. print find_up_to_phase(qi.sqx)
  44. print find_up_to_phase(qi.msqz)