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.

clifford.py 1.6KB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import numpy as np
  2. from tqdm import tqdm
  3. import os
  4. from qi import *
  5. import cPickle
  6. def find_up_to_phase(u):
  7. """ Find the index of a given u within a list of unitaries, up to a global phase """
  8. global unitaries
  9. for i, t in enumerate(unitaries):
  10. for phase in range(8):
  11. if np.allclose(t, np.exp(1j*phase*np.pi/4.)*u):
  12. return i, phase
  13. raise IndexError
  14. def compose_u(decomposition):
  15. """ Get the unitary representation of a particular decomposition """
  16. us = (elements[c] for c in decomposition)
  17. return np.matrix(reduce(np.dot, us), dtype=complex)
  18. def construct_tables():
  19. """ Constructs multiplication and conjugation tables """
  20. conjugation_table = [find_up_to_phase(u.H)[0] for i, u in enumerate(unitaries)]
  21. times_table = [[find_up_to_phase(u*v)[0] for v in unitaries]
  22. for u in tqdm(unitaries, "Building times-table")]
  23. with open("tables.pkl", "w") as f:
  24. cPickle.dump((conjugation_table, times_table), f)
  25. #permutations = (id, ha, ph, ha*ph, ha*ph*ha, ha*ph*ha*ph)
  26. #signs = (id, px, py, pz)
  27. #unitaries = [p*s for p in permutations for s in signs]
  28. decompositions = \
  29. ("xxxx", "xx", "zzxx", "zz", "zxx", "z", "zzz", "xxz",
  30. "xzx", "xzxxx", "xzzzx", "xxxzx", "xzz", "zzx", "xxx", "x",
  31. "zzzx", "xxzx", "zx", "zxxx", "xxxz", "xzzz", "xz", "xzxx")
  32. elements = {"x": sqx, "z": msqz}
  33. unitaries = [compose_u(d) for d in decompositions]
  34. # Build / reload lookup tables
  35. if not os.path.exists("tables.pkl"):
  36. construct_tables()
  37. with open("tables.pkl") as f:
  38. conjugation_table, times_table = cPickle.load(f)
  39. if __name__ == '__main__':
  40. pass