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.

61 lignes
1.7KB

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