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
2.1KB

  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 os
  10. from functools import reduce
  11. import cPickle
  12. import qi
  13. # TODO: make this more efficient / shorter
  14. def find(needle, haystack):
  15. """ Find the index of a given u within a list of unitaries, up to a global phase """
  16. for i, t in enumerate(haystack):
  17. for phase in range(8):
  18. if np.allclose(t, np.exp(1j * phase * np.pi / 4.) * needle):
  19. return i
  20. raise IndexError
  21. def compose_u(decomposition):
  22. """ Get the unitary representation of a particular decomposition """
  23. us = ({"x": qi.sqx, "z": qi.msqz}[c] for c in decomposition)
  24. return np.matrix(reduce(np.dot, us), dtype=complex)
  25. def name_of(vop):
  26. """ Get the formatted name of a VOP """
  27. return "%s" % get_name[vop] if vop in get_name else "VOP%d" % vop
  28. def construct_tables(filename="tables.cache"):
  29. """ Constructs / caches multiplication and conjugation tables """
  30. if os.path.exists(filename):
  31. return cPickle.load(open(filename, "r"))
  32. by_name = {name: find(u, unitaries) for name, u in qi.by_name.items()}
  33. get_name = {v:k for k, v in by_name.items()}
  34. conjugation_table = [find(u.H, unitaries)
  35. for i, u in enumerate(unitaries)]
  36. times_table = [[find(u * v, unitaries) for v in unitaries]
  37. for u in tqdm(unitaries)]
  38. cz_table = None
  39. output = by_name, get_name, conjugation_table, times_table, cz_table
  40. with open(filename, "w") as f:
  41. cPickle.dump(output, f)
  42. return output
  43. decompositions = ("xxxx", "xx", "zzxx", "zz", "zxx", "z", "zzz", "xxz",
  44. "xzx", "xzxxx", "xzzzx", "xxxzx", "xzz", "zzx", "xxx", "x",
  45. "zzzx", "xxzx", "zx", "zxxx", "xxxz", "xzzz", "xz", "xzxx")
  46. unitaries = [compose_u(d) for d in decompositions]
  47. by_name, get_name, conjugation_table, times_table, cz_table = construct_tables()