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.

wtf.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from abp import clifford, qi
  2. import numpy as np
  3. import itertools as it
  4. def conj_hack(operator, unitary):
  5. """ TODO: make this meaningful / legible """
  6. assert operator in set(xrange(4))
  7. op = clifford.times_table[unitary, operator]
  8. op = clifford.times_table[op, clifford.conjugation_table[unitary]]
  9. is_id_or_operator = (unitary % 4 == 0) or (unitary % 4 == operator)
  10. is_non_pauli = (unitary >= 4) and (unitary <= 15)
  11. phase = ((-1, 1), (1, -1))[is_id_or_operator][is_non_pauli]
  12. if operator == 0:
  13. phase = 1
  14. return op, phase
  15. def conj(operator, unitary):
  16. """ Better """
  17. matrices = ({"x": qi.msqx, "z": qi.sqz}[c] for c in clifford.decompositions[unitary])
  18. unitary = reduce(np.dot, matrices, np.eye(2, dtype=complex))
  19. operator = qi.operators[operator]
  20. new_operator = reduce(np.dot, (unitary, operator, qi.hermitian_conjugate(unitary)))
  21. for i, o in enumerate(qi.operators):
  22. if np.allclose(o, new_operator):
  23. return i, 1
  24. elif np.allclose(o, -new_operator):
  25. return i, -1
  26. raise IndexError
  27. for operator, unitary in it.product(range(4), range(24)):
  28. assert conj(operator, unitary) == conj_hack(operator, unitary)
  29. #new = np.dot(u, np.dot(o, qi.hermitian_conjugate(u)))
  30. #which = clifford.find_clifford(new, clifford.unitaries[:4])
  31. #assert which in xrange(4)
  32. #whichm = [qi.id, qi.px, qi.py, qi.pz][which]
  33. #if np.allclose(new, whichm):
  34. #return which, 1
  35. #elif np.allclose(new, -whichm):
  36. #return which, -1
  37. #else:
  38. #raise IndexError