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.

new.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from numpy import *
  2. from scipy.linalg import sqrtm
  3. # Some two-qubit matrices
  4. i = matrix(eye(2, dtype=complex))
  5. px = matrix([[0, 1], [1, 0]], dtype=complex)
  6. py = matrix([[0, -1j], [1j, 0]], dtype=complex)
  7. pz = matrix([[1, 0], [0, -1]], dtype=complex)
  8. h = matrix([[1, 1], [1, -1]], dtype=complex) / sqrt(2)
  9. p = matrix([[1, 0], [0, 1j]], dtype=complex)
  10. paulis = (px, py, pz)
  11. def identify_pauli(m):
  12. """ Given a signed Pauli matrix, name it. """
  13. for sign in (+1, -1):
  14. for pauli_label, pauli in zip("xyz", paulis):
  15. if allclose(sign * pauli, m):
  16. return sign, pauli_label
  17. def get_action(u):
  18. """ What does this unitary operator do to the Paulis? """
  19. return [identify_pauli(u * p * u.H) for p in paulis]
  20. def format_action(action):
  21. return "".join("{}{}".format("+" if s>=0 else "-", p) for s, p in action)
  22. #permuters = (i, h*p*h*pz, p*h*p*h, px*p, p*h, p*p*h*pz)
  23. permuters = (i, h, p, h*p, h*p*h, h*p*h*p)
  24. signs = (i, px, py, pz)
  25. unitaries = []
  26. actions = []
  27. for perm in permuters:
  28. for sign in signs:
  29. action = format_action(get_action(sign*perm))
  30. actions.append(action)
  31. unitaries.append(perm*sign)
  32. #print (perm*sign).round(2).reshape(1,4)[0],
  33. print action,
  34. print
  35. assert len(set(actions)) == 24
  36. sqy = sqrtm(1j*py)
  37. msqy = sqrtm(-1j*py)
  38. sqz = sqrtm(1j*pz)
  39. msqz = sqrtm(-1j*pz)
  40. sqx = sqrtm(1j*px)
  41. msqx = sqrtm(-1j*px)
  42. for m in i, px, py, pz, h, p, sqz, msqz, sqy, msqy, sqx, msqx:
  43. if any([allclose(u, m) for u in unitaries]):
  44. print "found it"
  45. else:
  46. if any([allclose(exp(1j*pi*phi/4.)*u, m) for phi in range(8) for u in unitaries]):
  47. print "found up to global phase"
  48. else:
  49. print "lost"