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.

71 lignes
1.8KB

  1. import numpy as np
  2. from abp import qi
  3. def test_init():
  4. """ Can you initialize some qubits """
  5. psi = qi.CircuitModel(5)
  6. assert psi.d == 32
  7. def test_single_qubit_stuff():
  8. """ Try some sensible single-qubit things """
  9. psi = qi.CircuitModel(2)
  10. psi.act_local_rotation(0, qi.px)
  11. assert np.allclose(psi.state[1], 1)
  12. psi.act_local_rotation(0, qi.px)
  13. assert np.allclose(psi.state[0], 1)
  14. psi.act_local_rotation(0, qi.pz)
  15. def test_more_single_qubit_stuff():
  16. """ Try some sensible single-qubit things """
  17. psi = qi.CircuitModel(2)
  18. psi.act_local_rotation(0, qi.px)
  19. psi.act_local_rotation(1, qi.px)
  20. psi.act_cz(0, 1)
  21. def test_equality():
  22. """ Test that equality succeeds / fails as desired """
  23. a = qi.CircuitModel(2)
  24. b = qi.CircuitModel(2)
  25. assert a == b
  26. a.act_local_rotation(0, qi.px)
  27. assert a != b
  28. def test_hadamard():
  29. """ What does CZ do ? """
  30. psi = qi.CircuitModel(3)
  31. psi.act_hadamard(0)
  32. psi.act_hadamard(1)
  33. assert np.allclose(psi.state, np.array([[1,1,1,1,0,0,0,0]]).T/2.)
  34. psi.act_hadamard(1)
  35. psi.act_hadamard(0)
  36. psi.act_hadamard(2)
  37. assert np.allclose(psi.state, qi.ir2*np.array([[1,0,0,0,1,0,0,0]]).T)
  38. def test_cz():
  39. """ What does CZ do ? """
  40. psi = qi.CircuitModel(2)
  41. psi.act_hadamard(0)
  42. psi.act_hadamard(1)
  43. psi.act_cz(0, 1)
  44. assert np.allclose(psi.state, qi.bond)
  45. def test_local_rotation():
  46. """ Do local rotations work okay? ? """
  47. psi = qi.CircuitModel(2)
  48. psi.act_local_rotation(0, qi.ha)
  49. psi.act_local_rotation(0, qi.ha)
  50. assert np.allclose(psi.state[0], 1)
  51. psi.act_local_rotation(0, qi.ha)
  52. psi.act_local_rotation(1, qi.ha)
  53. psi.act_local_rotation(0, qi.ha)
  54. psi.act_local_rotation(1, qi.ha)
  55. assert np.allclose(psi.state[0], 1)