Anders and Briegel in Python
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_graph.py 1.6KB

8 년 전
8 년 전
8 년 전
8 년 전
8 년 전
8 년 전
8 년 전
8 년 전
8 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from abp.graph 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