Anders and Briegel in Python
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

51 行
1.1KB

  1. from abp.graphstate import GraphState
  2. from abp.qi import CircuitModel
  3. from abp import clifford
  4. import numpy as np
  5. import random
  6. def test_hadamard_only_multiqubit():
  7. """ A multi qubit test with Hadamards only"""
  8. n = 4
  9. g = GraphState(range(n))
  10. c = CircuitModel(n)
  11. for i in range(n):
  12. g.act_hadamard(i)
  13. c.act_hadamard(i)
  14. assert g.to_state_vector() == c
  15. for i in range(100):
  16. a, b = np.random.randint(0, n-1, 2)
  17. if a != b:
  18. g.act_cz(a, b)
  19. c.act_cz(a, b)
  20. assert g.to_state_vector() == c
  21. def test_all_multiqubit():
  22. """ A multi qubit test with arbitrary local rotations """
  23. n = 4
  24. g = GraphState(range(n))
  25. c = CircuitModel(n)
  26. for i in range(10):
  27. qubit = np.random.randint(0, n-1)
  28. rotation = np.random.randint(0, 24-1)
  29. g.act_local_rotation(qubit, rotation)
  30. c.act_local_rotation(qubit, clifford.unitaries[rotation])
  31. assert g.to_state_vector() == c
  32. #for i in range(100):
  33. #a, b = np.random.randint(0, n-1, 2)
  34. #if a != b:
  35. #g.act_cz(a, b)
  36. #c.act_cz(a, b)
  37. assert g.to_state_vector() == c