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

30 行
552B

  1. import chp
  2. from abp import qi
  3. import numpy as np
  4. n = 10
  5. def get_chp_state():
  6. """ Convert CHP to CircuitModel """
  7. output = qi.CircuitModel(n)
  8. ket = chp.get_ket()
  9. nonzero = np.sqrt(len(ket))
  10. for key, phase in ket.items():
  11. output.state[key] = np.exp(1j*phase*np.pi/2)/nonzero
  12. return output
  13. def test1():
  14. chp.init(5)
  15. chp.act_hadamard(0)
  16. chp.act_cnot(0, 1)
  17. yy = qi.CircuitModel(n)
  18. yy.act_hadamard(0)
  19. yy.act_hadamard(1)
  20. yy.act_cz(0, 1)
  21. yy.act_hadamard(1)
  22. assert yy == get_chp_state()