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.

98 lignes
2.3KB

  1. from abp.graph import GraphState, DiffedGraphState
  2. from abp import clifford
  3. import time
  4. def demograph():
  5. """ A graph for testing with """
  6. g = GraphState()
  7. g.add_edge(0, 1)
  8. g.add_edge(1, 2)
  9. g.add_edge(2, 0)
  10. g.add_edge(0, 3)
  11. g.add_edge(100, 200)
  12. return g
  13. def test_graph_basic():
  14. """ Test that we can construct graphs, delete edges, whatever """
  15. g = demograph()
  16. assert g.ngbh[0] == set([1, 2, 3])
  17. g.del_edge(0, 1)
  18. assert g.ngbh[0] == set([2, 3])
  19. assert g.has_edge(1, 2)
  20. assert not g.has_edge(0, 1)
  21. def test_local_complementation():
  22. """ Test that local complementation works as expected """
  23. g = demograph()
  24. g.local_complementation(0)
  25. assert g.has_edge(0, 1)
  26. assert g.has_edge(0, 2)
  27. assert not g.has_edge(1, 2)
  28. assert g.has_edge(3, 2)
  29. assert g.has_edge(3, 1)
  30. # TODO: test VOP conditions
  31. def test_remove_vop():
  32. """ Test that removing VOPs really works """
  33. g = demograph()
  34. g.remove_vop(0, 1)
  35. assert g.vops[0] == clifford.by_name["identity"]
  36. g.remove_vop(1, 1)
  37. assert g.vops[1] == clifford.by_name["identity"]
  38. g.remove_vop(2, 1)
  39. assert g.vops[2] == clifford.by_name["identity"]
  40. g.remove_vop(0, 1)
  41. assert g.vops[0] == clifford.by_name["identity"]
  42. def test_edgelist():
  43. """ Test making edgelists """
  44. g = demograph()
  45. el = g.edgelist()
  46. assert (0, 3) in el
  47. assert (0, 2) in el
  48. assert (100, 200) in el
  49. def test_stress():
  50. """ Testing that making a graph of ten thousand qubits takes less than half a second"""
  51. g = GraphState()
  52. t = time.clock()
  53. for i in xrange(100000):
  54. g.add_edge(i, i + 1)
  55. assert time.clock() - t < .5
  56. def test_cz():
  57. """ Test CZ gate """
  58. g = GraphState()
  59. g.add_vertex(0)
  60. g.add_vertex(1)
  61. g.act_local_rotation(0, clifford.by_name["hadamard"])
  62. g.act_local_rotation(1, clifford.by_name["hadamard"])
  63. g.act_local_rotation(1, clifford.by_name["py"])
  64. print g
  65. g.act_cz(0, 1)
  66. print g
  67. def test_diff():
  68. """ Test diffing """
  69. g = DiffedGraphState()
  70. g.add_vertex(0)
  71. g.add_vertex(1)
  72. g.act_local_rotation(0, clifford.by_name["hadamard"])
  73. g.act_local_rotation(1, clifford.by_name["hadamard"])
  74. g.act_local_rotation(1, clifford.by_name["py"])
  75. print g
  76. g.act_cz(0, 1)
  77. print g.diff