Anders and Briegel in Python
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

96 satır
2.5KB

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