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.

test_graphstate.py 2.0KB

8 år sedan
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from abp import GraphState
  2. from abp import clifford
  3. from mock import simple_graph
  4. import time
  5. def test_graph_basic():
  6. """ Test that we can construct graphs, delete edges, whatever """
  7. g = simple_graph()
  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 = simple_graph()
  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 = simple_graph()
  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 = simple_graph()
  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 = simple_graph()
  60. stab = g.to_stabilizer()
  61. #TODO