Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3KB

  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. REPEATS = 10
  7. def test_hadamard_only_multiqubit(n=6):
  8. """ A multi qubit test with Hadamards only"""
  9. for qqq in range(REPEATS):
  10. g = GraphState(range(n))
  11. c = CircuitModel(n)
  12. for i in range(n):
  13. g.act_hadamard(i)
  14. c.act_hadamard(i)
  15. assert g.to_state_vector() == c
  16. for i in range(100):
  17. a, b = np.random.randint(0, n - 1, 2)
  18. if a != b:
  19. g.act_cz(a, b)
  20. c.act_cz(a, b)
  21. assert g.to_state_vector() == c
  22. def test_all_multiqubit(n=4):
  23. """ A multi qubit test with arbitrary local rotations """
  24. for qqq in range(REPEATS):
  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