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.

47 lines
1.6KB

  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. from qi import *
  10. from functools import reduce
  11. from util import cache_to_disk
  12. def find_up_to_phase(u):
  13. """ Find the index of a given u within a list of unitaries, up to a global phase """
  14. for i, t in enumerate(unitaries):
  15. for phase in range(8):
  16. if np.allclose(t, np.exp(1j * phase * np.pi / 4.) * u):
  17. return i, phase
  18. raise IndexError
  19. def compose_u(decomposition):
  20. """ Get the unitary representation of a particular decomposition """
  21. us = (elements[c] for c in decomposition)
  22. return np.matrix(reduce(np.dot, us), dtype=complex)
  23. @cache_to_disk("tables.pkl")
  24. def construct_tables():
  25. """ Constructs / caches multiplication and conjugation tables """
  26. conjugation_table = [find_up_to_phase(u.H)[0]
  27. for i, u in enumerate(unitaries)]
  28. times_table = [[find_up_to_phase(u * v)[0] for v in unitaries]
  29. for u in tqdm(unitaries)]
  30. return conjugation_table, times_table
  31. # Various useful tables
  32. decompositions = ("xxxx", "xx", "zzxx", "zz", "zxx", "z", "zzz", "xxz",
  33. "xzx", "xzxxx", "xzzzx", "xxxzx", "xzz", "zzx", "xxx", "x",
  34. "zzzx", "xxzx", "zx", "zxxx", "xxxz", "xzzz", "xz", "xzxx")
  35. elements = {"x": sqx, "z": msqz}
  36. unitaries = [compose_u(d) for d in decompositions]
  37. conjugation_table, times_table = construct_tables()