Anders and Briegel in Python
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

49 wiersze
1.2KB

  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(n=4):
  22. """ A multi qubit test with arbitrary local rotations """
  23. for j in range(100):
  24. n = 4
  25. g = GraphState(range(n))
  26. c = CircuitModel(n)
  27. for i in range(10):
  28. qubit = np.random.randint(0, n - 1)
  29. rotation = np.random.randint(0, 24 - 1)
  30. g.act_local_rotation(qubit, rotation)
  31. c.act_local_rotation(qubit, clifford.unitaries[rotation])
  32. assert g.to_state_vector() == c
  33. for i in range(1):
  34. a, b = np.random.randint(0, n-1, 2)
  35. if a != b:
  36. g.act_cz(a, b)
  37. c.act_cz(a, b)
  38. assert g.to_state_vector() == c