Anders and Briegel in Python
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

test_graph.py 2.2KB

8年前
8年前
8年前
8年前
8年前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_node(0)
  60. g.add_node(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()