Anders and Briegel in Python
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

55 Zeilen
1.4KB

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