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.

40 lines
1.1KB

  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. # Operators
  9. id = np.matrix(np.eye(2, dtype=complex))
  10. px = np.matrix([[0, 1], [1, 0]], dtype=complex)
  11. py = np.matrix([[0, -1j], [1j, 0]], dtype=complex)
  12. pz = np.matrix([[1, 0], [0, -1]], dtype=complex)
  13. ha = np.matrix([[1, 1], [1, -1]], dtype=complex) / np.sqrt(2)
  14. ph = np.matrix([[1, 0], [0, 1j]], dtype=complex)
  15. sqy = sqrtm(1j * py)
  16. msqy = np.matrix(sqrtm(-1j * py))
  17. sqz = np.matrix(sqrtm(1j * pz))
  18. msqz = np.matrix(sqrtm(-1j * pz))
  19. sqx = np.matrix(sqrtm(1j * px))
  20. msqx = np.matrix(sqrtm(-1j * px))
  21. paulis = (px, py, pz)
  22. # CZ gate
  23. cz = np.matrix(np.eye(4), dtype=complex)
  24. cz[3,3]=-1
  25. # States
  26. plus = np.matrix([[1],[1]], dtype=complex) / np.sqrt(2)
  27. bond = cz * np.kron(plus, plus)
  28. nobond = np.kron(plus, plus)
  29. # Labelling stuff
  30. common_us = id, px, py, pz, ha, ph, sqz, msqz, sqy, msqy, sqx, msqx
  31. names = "identity", "px", "py", "pz", "hadamard", "phase", "sqz", "msqz", "sqy", "msqy", "sqx", "msqx"
  32. by_name = dict(zip(names, common_us))