Anders and Briegel in Python
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

test_mercedes.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from abp import GraphState
  2. from abp.util import xyz
  3. from mock import simple_graph
  4. def linear_cluster(n):
  5. g = GraphState(range(n))
  6. g.act_circuit([(i, "hadamard") for i in range(n)])
  7. g.act_circuit([((i, i+1), "cz") for i in range(n-1)])
  8. return g
  9. def test_mercedes_example_1():
  10. """ Run an example provided by mercedes """
  11. g = linear_cluster(5)
  12. g.measure(3, "px")
  13. g.measure(2, "px")
  14. assert set(g.adj[0]) == {1}
  15. assert set(g.adj[1]) == {0, 4}
  16. assert set(g.adj[4]) == {1}
  17. def test_single_qubit_measurements():
  18. """ Various simple tests of measurements """
  19. # Test that measuring |0> in Z gives 0
  20. g = GraphState([0])
  21. assert g.measure_z(0) == 0, "Measuring |0> in Z gives 0"
  22. # Test that measuring |1> in Z gives 1
  23. g = GraphState([0])
  24. g.act_local_rotation(0, "px")
  25. assert g.measure_z(0) == 1, "Measuring |1> in Z gives 1"
  26. # Test that measuring |+> in X gives 0
  27. g = GraphState([0])
  28. g.act_local_rotation(0, "hadamard")
  29. assert g.measure_x(0) == 0
  30. assert g.measure_x(0) == 0, "Measuring |+> in X gives 0"
  31. g.act_local_rotation(0, "pz")
  32. assert g.measure_x(0) == 1, "Measuring |-> in X gives 1"
  33. # Test something else
  34. assert g.measure_y(0, force=0) == 0
  35. def test_is_determinate():
  36. """ Test whether asking if an outcome was random or determinate works """
  37. g = GraphState([0])
  38. assert g.measure_z(0, detail=True)["determinate"] == True
  39. assert g.measure_x(0, detail=True)["determinate"] == False
  40. def test_copy():
  41. """ Make a copy of a graph """
  42. a = simple_graph()
  43. b = a.copy()
  44. assert a == b