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.

78 satır
2.0KB

  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. assert set(g.adj[0].keys()) == set([1, 2, 3])
  9. g.del_edge(0, 1)
  10. assert set(g.adj[0].keys()) == 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():
  24. """ Test that removing VOPs really works """
  25. g = demograph()
  26. g.remove_vop(0, 1)
  27. assert g.node[0]["vop"] == clifford.by_name["identity"]
  28. g.remove_vop(1, 1)
  29. assert g.node[1]["vop"] == clifford.by_name["identity"]
  30. g.remove_vop(2, 1)
  31. assert g.node[2]["vop"] == clifford.by_name["identity"]
  32. g.remove_vop(0, 1)
  33. assert g.node[0]["vop"] == clifford.by_name["identity"]
  34. def test_edgelist():
  35. """ Test making edgelists """
  36. g = demograph()
  37. el = g.edgelist()
  38. assert (0, 3) in el
  39. assert (0, 2) in el
  40. assert (100, 200) in el
  41. def test_stress(n = int(1e5)):
  42. """ Testing that making a graph of ten thousand qubits takes less than half a second"""
  43. g = GraphState(range(n+1))
  44. t = time.clock()
  45. for i in xrange(n):
  46. g.add_edge(i, i + 1)
  47. assert time.clock() - t < .5
  48. def test_cz():
  49. """ Test CZ gate """
  50. g = GraphState([0, 1])
  51. g.act_local_rotation(0, clifford.by_name["hadamard"])
  52. g.act_local_rotation(1, clifford.by_name["hadamard"])
  53. g.act_local_rotation(1, clifford.by_name["py"])
  54. assert not g.has_edge(0, 1)
  55. g.act_cz(0, 1)
  56. assert g.has_edge(0, 1)
  57. def test_stabilizer():
  58. """ Test that we can generate stabilizers okay """
  59. g = demograph()
  60. stab = g.to_stabilizer()
  61. #TODO: sux
  62. #assert len(stab.split("\n")) == g.order()