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.9KB

il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. import itertools as it
  8. def test_single_qubit_measurements():
  9. """ Various simple tests of measurements """
  10. # Test that measuring |0> in Z gives 0
  11. g = GraphState([0])
  12. assert g.measure(0, "pz") == 0, "Measuring |0> in Z gives 0"
  13. # Test that measuring |1> in Z gives 1
  14. g = GraphState([0])
  15. g.act_local_rotation(0, "px")
  16. assert g.measure(0, "pz") == 1, "Measuring |1> in Z gives 1"
  17. # Test that measuring |+> in X gives 0
  18. g = GraphState([0])
  19. g.act_local_rotation(0, "hadamard")
  20. assert g.measure(0, "px") == 0
  21. assert g.measure(0, "px") == 0, "Measuring |+> in X gives 0"
  22. g.act_local_rotation(0, "pz")
  23. assert g.measure(0, "px") == 1, "Measuring |-> in X gives 1"
  24. def test_type():
  25. """ Test that the output is always an int """
  26. for r, m, f in it.product(range(24), ("px", "py", "pz"), (0, 1)):
  27. g = GraphState([0])
  28. g.act_local_rotation(0, r)
  29. assert str(g.measure(0, m)) in "01"
  30. assert str(g.measure(0, m, f)) in "01"
  31. assert g.measure(0, m, f, detail=True)["determinate"] == True
  32. def test_random_outcomes():
  33. """ Testing random behaviour """
  34. ones = 0
  35. for i in range(1000):
  36. g = GraphState([0])
  37. g.act_local_rotation(0, "hadamard")
  38. ones += g.measure(0, "pz")
  39. assert 400 < ones < 600, "This is a probabilistic test!"
  40. def test_projection():
  41. """ Test that projection works correctly """
  42. g = GraphState([0])
  43. g.act_local_rotation(0, "hadamard")
  44. g.measure(0, "pz", 0)
  45. assert np.allclose(g.to_state_vector().state, qi.zero)
  46. # Now project onto |1>
  47. g = GraphState([0])
  48. g.act_local_rotation(0, "hadamard")
  49. g.measure(0, "pz", 1)
  50. assert np.allclose(g.to_state_vector().state, qi.one)