Anders and Briegel in Python
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123 řádky
3.8KB

  1. from abp import GraphState, CircuitModel, clifford
  2. import mock
  3. import random
  4. import numpy as np
  5. from tqdm import tqdm
  6. REPEATS = 100
  7. DEPTH = 100
  8. def test_graph_basic():
  9. """ Test that we can construct graphs, delete edges, whatever """
  10. g = mock.simple_graph()
  11. assert set(g.adj[0].keys()) == set([1, 2, 3])
  12. g._del_edge(0, 1)
  13. assert set(g.adj[0].keys()) == set([2, 3])
  14. assert g.has_edge(1, 2)
  15. assert not g.has_edge(0, 1)
  16. def test_local_complementation():
  17. """ Test that local complementation works as expected """
  18. g = mock.simple_graph()
  19. g.local_complementation(0)
  20. assert g.has_edge(0, 1)
  21. assert g.has_edge(0, 2)
  22. assert not g.has_edge(1, 2)
  23. assert g.has_edge(3, 2)
  24. assert g.has_edge(3, 1)
  25. # TODO: test VOP conditions
  26. def test_remove_vop():
  27. """ Test that removing VOPs really works """
  28. g = mock.simple_graph()
  29. g.remove_vop(0, 1)
  30. assert g.node[0]["vop"] == clifford.by_name["identity"]
  31. g.remove_vop(1, 1)
  32. assert g.node[1]["vop"] == clifford.by_name["identity"]
  33. g.remove_vop(2, 1)
  34. assert g.node[2]["vop"] == clifford.by_name["identity"]
  35. g.remove_vop(0, 1)
  36. assert g.node[0]["vop"] == clifford.by_name["identity"]
  37. def test_edgelist():
  38. """ Test making edgelists """
  39. g = mock.simple_graph()
  40. el = g.edgelist()
  41. assert (0, 3) in el
  42. assert (0, 2) in el
  43. assert (100, 200) in el
  44. def test_stress(n=int(1e5)):
  45. """ Testing that making a graph of ten thousand qubits takes less than half a second"""
  46. import time
  47. g = GraphState(range(n + 1))
  48. t = time.clock()
  49. for i in xrange(n):
  50. g._add_edge(i, i + 1)
  51. assert time.clock() - t < .5
  52. def test_cz():
  53. """ Test CZ gate """
  54. g = GraphState([0, 1])
  55. g.act_local_rotation(0, clifford.by_name["hadamard"])
  56. g.act_local_rotation(1, clifford.by_name["hadamard"])
  57. g.act_local_rotation(1, clifford.by_name["py"])
  58. assert not g.has_edge(0, 1)
  59. g.act_cz(0, 1)
  60. assert g.has_edge(0, 1)
  61. def test_stabilizer():
  62. """ Test that we can generate stabilizers okay """
  63. g = mock.simple_graph()
  64. stab = g.to_stabilizer()
  65. # TODO
  66. def test_local_complementation():
  67. """ Test that local complementation works okay """
  68. pairs = (0, 1), (0, 3), (1, 3), (1, 2),
  69. psi = GraphState(range(4))
  70. psi.act_circuit([(i, "hadamard") for i in psi.node])
  71. psi.act_circuit([(pair, "cz") for pair in pairs])
  72. old_edges = psi.edgelist()
  73. old_state = psi.to_state_vector()
  74. psi.local_complementation(1)
  75. assert old_edges != psi.edgelist()
  76. assert old_state == psi.to_state_vector()
  77. def test_single_qubit():
  78. """ A multi qubit test with Hadamards only"""
  79. for repeat in tqdm(range(REPEATS), desc="Single qubit rotations against CircuitModel"):
  80. circuit = [(0, random.choice(range(24))) for i in range(DEPTH)]
  81. a = mock.circuit_to_state(mock.ABPWrapper, 1, circuit)
  82. b = mock.circuit_to_state(mock.CircuitModelWrapper, 1, circuit)
  83. assert a.to_state_vector() == b
  84. def test_graph_state_multiqubit(n=6):
  85. """ A multi qubit test with Hadamards only"""
  86. for repeat in tqdm(range(REPEATS), desc="Random graph states against the CircuitModel"):
  87. circuit = mock.random_graph_circuit(n)
  88. a = mock.circuit_to_state(mock.ABPWrapper, n, circuit)
  89. b = mock.circuit_to_state(mock.CircuitModelWrapper, n, circuit)
  90. assert a.to_state_vector() == b
  91. def test_stabilizer_state_multiqubit(n=6):
  92. """ A multi qubit test with arbitrary local rotations """
  93. for repeat in tqdm(range(REPEATS), desc="Random Clifford circuits against the CircuitModel"):
  94. circuit = mock.random_stabilizer_circuit(n)
  95. a = mock.circuit_to_state(mock.ABPWrapper, n, circuit)
  96. b = mock.circuit_to_state(mock.CircuitModelWrapper, n, circuit)
  97. assert a.to_state_vector() == b