Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.2KB

  1. from abp.graphstate import GraphState
  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. assert not g.has_edge(0, 1)
  65. g.act_cz(0, 1)
  66. assert g.has_edge(0, 1)
  67. def test_stabilizer():
  68. """ Test that we can generate stabilizers okay """
  69. g = demograph()
  70. stab = g.to_stabilizer()
  71. #TODO: sux
  72. #assert len(stab.split("\n")) == g.order()