Anders and Briegel in Python
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

44 行
1.1KB

  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_hadamard():
  8. """ What does CZ do ? """
  9. psi = qi.CircuitModel(3)
  10. psi.act_hadamard(0)
  11. psi.act_hadamard(1)
  12. assert np.allclose(psi.state, np.array([[1,1,1,1,0,0,0,0]]).T/2.)
  13. psi.act_hadamard(1)
  14. psi.act_hadamard(0)
  15. psi.act_hadamard(2)
  16. assert np.allclose(psi.state, qi.ir2*np.array([[1,0,0,0,1,0,0,0]]).T)
  17. def test_cz():
  18. """ What does CZ do ? """
  19. psi = qi.CircuitModel(2)
  20. psi.act_hadamard(0)
  21. psi.act_hadamard(1)
  22. psi.act_cz(0, 1)
  23. assert np.allclose(psi.state, qi.bond)
  24. def test_local_rotation():
  25. """ Do local rotations work okay? ? """
  26. psi = qi.CircuitModel(2)
  27. psi.act_local_rotation(0, qi.ha)
  28. psi.act_local_rotation(0, qi.ha)
  29. assert np.allclose(psi.state[0], 1)
  30. psi.act_local_rotation(0, qi.ha)
  31. psi.act_local_rotation(1, qi.ha)
  32. psi.act_local_rotation(0, qi.ha)
  33. psi.act_local_rotation(1, qi.ha)
  34. assert np.allclose(psi.state[0], 1)