Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

clifford.py 1.7KB

il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. 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": qi.sqx, "z": qi.msqz}
  36. unitaries = [compose_u(d) for d in decompositions]
  37. conjugation_table, times_table = construct_tables()
  38. sqx = 15
  39. msqz = 5
  40. if __name__ == '__main__':
  41. print find_up_to_phase(qi.sqx)
  42. print find_up_to_phase(qi.msqz)