Anders and Briegel in Python
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

60 linhas
1.7KB

  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), vop="hadamard")
  6. g.act_circuit([("hadamard", i) for i in range(n)])
  7. g.act_circuit([("cz", (i, i+1)) 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], vop="hadamard")
  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], vop="hadamard")
  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], vop="hadamard")
  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], vop="hadamard")
  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