Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

57 lignes
1.6KB

  1. import numpy as np
  2. from abp import GraphState
  3. from abp import qi, clifford
  4. from anders_briegel import graphsim
  5. from tqdm import tqdm
  6. import random
  7. REPEATS = 100000
  8. LOCAL_ROTATION = 0
  9. CZ = 1
  10. MEASURE = 2
  11. def test_single_qubit_measurements():
  12. """ Various simple tests of measurements """
  13. # Test that measuring |0> in Z gives 0
  14. g = GraphState([0])
  15. assert g.measure(0, "pz") == 0, "Measuring |0> in Z gives 0"
  16. # Test that measuring |1> in Z gives 1
  17. g = GraphState([0])
  18. g.act_local_rotation(0, "px")
  19. assert g.measure(0, "pz") == 1, "Measuring |1> in Z gives 1"
  20. # Test that measuring |+> in X gives 0
  21. g = GraphState([0])
  22. g.act_local_rotation(0, "hadamard")
  23. assert g.measure(0, "px") == 0
  24. assert g.measure(0, "px") == 0, "Measuring |+> in X gives 0"
  25. g.act_local_rotation(0, "pz")
  26. assert g.measure(0, "px") == 1, "Measuring |-> in X gives 1"
  27. def test_random_outcomes():
  28. """ Testing random behaviour """
  29. ones = 0
  30. for i in range(1000):
  31. g = GraphState([0])
  32. g.act_local_rotation(0, "hadamard")
  33. ones += g.measure(0, "pz")
  34. assert 400 < ones < 600, "This is a probabilistic test!"
  35. def test_projection():
  36. """ Test that projection works correctly """
  37. g = GraphState([0])
  38. g.act_local_rotation(0, "hadamard")
  39. g.measure(0, "pz", 0)
  40. assert np.allclose(g.to_state_vector().state, qi.zero)
  41. def test_another_projection():
  42. """ This one fails at the moment """
  43. g = GraphState([0])
  44. g.act_local_rotation(0, "hadamard")
  45. g.measure(0, "pz", 1)
  46. assert np.allclose(g.to_state_vector().state, qi.one)