Anders and Briegel in Python
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

95 lines
2.5KB

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