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.

47 lines
1.2KB

  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Exposes a few basic QI operators
  5. """
  6. import numpy as np
  7. from scipy.linalg import sqrtm
  8. def hermitian_conjugate(u):
  9. """ Shortcut to the Hermitian conjugate """
  10. return np.conjugate(np.transpose(u))
  11. # Operators
  12. id = np.array(np.eye(2, dtype=complex))
  13. px = np.array([[0, 1], [1, 0]], dtype=complex)
  14. py = np.array([[0, -1j], [1j, 0]], dtype=complex)
  15. pz = np.array([[1, 0], [0, -1]], dtype=complex)
  16. ha = np.array([[1, 1], [1, -1]], dtype=complex) / np.sqrt(2)
  17. ph = np.array([[1, 0], [0, 1j]], dtype=complex)
  18. t = np.array([[1, 0], [0, np.exp(1j*np.pi/4)]], dtype=complex)
  19. sqy = sqrtm(1j * py)
  20. msqy = np.array(sqrtm(-1j * py))
  21. sqz = np.array(sqrtm(1j * pz))
  22. msqz = np.array(sqrtm(-1j * pz))
  23. sqx = np.array(sqrtm(1j * px))
  24. msqx = np.array(sqrtm(-1j * px))
  25. paulis = (px, py, pz)
  26. # CZ gate
  27. cz = np.array(np.eye(4), dtype=complex)
  28. cz[3,3]=-1
  29. # States
  30. plus = np.array([[1],[1]], dtype=complex) / np.sqrt(2)
  31. bond = cz.dot(np.kron(plus, plus))
  32. nobond = np.kron(plus, plus)
  33. # Labelling stuff
  34. common_us = id, px, py, pz, ha, ph, sqz, msqz, sqy, msqy, sqx, msqx
  35. names = "identity", "px", "py", "pz", "hadamard", "phase", "sqz", "msqz", "sqy", "msqy", "sqx", "msqx"
  36. by_name = dict(zip(names, common_us))
  37. paulis = px, py, pz