Anders and Briegel in Python
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

61 行
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_up_to_phase(u):
  15. """ Find the index of a given u within a list of unitaries, up to a global phase """
  16. for i, t in enumerate(unitaries):
  17. for phase in range(8):
  18. if np.allclose(t, np.exp(1j * phase * np.pi / 4.) * u):
  19. return i, phase
  20. raise IndexError
  21. def compose_u(decomposition):
  22. """ Get the unitary representation of a particular decomposition """
  23. us = (elements[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_up_to_phase(u)[0] for name, u in qi.by_name.items()}
  33. get_name = {v:k for k, v in by_name.items()}
  34. conjugation_table = [find_up_to_phase(u.H)[0]
  35. for i, u in enumerate(unitaries)]
  36. times_table = [[find_up_to_phase(u * v)[0] 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. elements = {"x": qi.sqx, "z": qi.msqz}
  47. unitaries = [compose_u(d) for d in decompositions]
  48. by_name, get_name, conjugation_table, times_table, cz_table = construct_tables()