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.

test_against_circuit_model.py 1.1KB

8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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