Anders and Briegel in Python
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

70 líneas
2.4KB

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