Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

80 lignes
2.0KB

  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():
  24. """ Test that removing VOPs really works """
  25. g = demograph()
  26. g.remove_vop(0, 1)
  27. assert g.vops[0] == clifford.by_name["identity"]
  28. g.remove_vop(1, 1)
  29. assert g.vops[1] == clifford.by_name["identity"]
  30. g.remove_vop(2, 1)
  31. assert g.vops[2] == clifford.by_name["identity"]
  32. g.remove_vop(0, 1)
  33. assert g.vops[0] == 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.add_node(0)
  52. g.add_node(1)
  53. g.act_local_rotation(0, clifford.by_name["hadamard"])
  54. g.act_local_rotation(1, clifford.by_name["hadamard"])
  55. g.act_local_rotation(1, clifford.by_name["py"])
  56. assert not g.has_edge(0, 1)
  57. g.act_cz(0, 1)
  58. assert g.has_edge(0, 1)
  59. def test_stabilizer():
  60. """ Test that we can generate stabilizers okay """
  61. g = demograph()
  62. stab = g.to_stabilizer()
  63. #TODO: sux
  64. #assert len(stab.split("\n")) == g.order()