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

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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. from config import *
  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_random_outcomes():
  25. """ Testing random behaviour """
  26. ones = 0
  27. for i in range(1000):
  28. g = GraphState([0])
  29. g.act_local_rotation(0, "hadamard")
  30. ones += g.measure(0, "pz")
  31. assert 400 < ones < 600, "This is a probabilistic test!"
  32. def test_projection():
  33. """ Test that projection works correctly """
  34. g = GraphState([0])
  35. g.act_local_rotation(0, "hadamard")
  36. g.measure(0, "pz", 0)
  37. assert np.allclose(g.to_state_vector().state, qi.zero)
  38. # Now project onto |1>
  39. g = GraphState([0])
  40. g.act_local_rotation(0, "hadamard")
  41. g.measure(0, "pz", 1)
  42. assert np.allclose(g.to_state_vector().state, qi.one)