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.

test_measurement.py 1.1KB

il y a 8 ans
il y a 8 ans
123456789101112131415161718192021222324252627282930313233343536373839
  1. from abp import GraphState
  2. from anders_briegel import graphsim
  3. def test_measurements():
  4. # Test that measuring |0> in Z gives 0
  5. g = GraphState([0])
  6. assert g.measure(0, "pz") == 0, "Measuring |0> in Z gives 0"
  7. # Test that measuring |1> in Z gives 1
  8. g = GraphState([0])
  9. g.act_local_rotation(0, "px")
  10. assert g.measure(0, "pz") == 1, "Measuring |1> in Z gives 1"
  11. # Test that measuring |+> in X gives 0
  12. g = GraphState([0])
  13. g.act_local_rotation(0, "hadamard")
  14. assert g.measure(0, "px") == 0
  15. assert g.measure(0, "px") == 0, "Measuring |+> in X gives 0"
  16. g.act_local_rotation(0, "pz")
  17. assert g.measure(0, "px") == 1, "Measuring |-> in X gives 1"
  18. # Test random outcomes
  19. ones = 0
  20. for i in range(1000):
  21. g = GraphState([0])
  22. g.act_local_rotation(0, "hadamard")
  23. ones += g.measure(0, "pz")
  24. assert 400 < ones < 600, "This is a probabilistic test!"
  25. def test_z_measurement_against_ab():
  26. for i in range(10):
  27. a = graphsim.GraphRegister(1)
  28. b = GraphState()
  29. b.add_node(0)
  30. #print a.measure(0, graphsim.lco_Z)
  31. #print b.measure(0, "pz")