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.

test_against_anders_and_briegel.py 3.4KB

il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. from abp import GraphState
  2. from anders_briegel import graphsim
  3. from abp import CircuitModel
  4. from abp import clifford
  5. import random
  6. from copy import deepcopy
  7. from tqdm import tqdm
  8. REPEATS = 100
  9. def assert_equal(a, b):
  10. assert a.to_json() == b.to_json()
  11. def test_hadamard():
  12. """ Test hadamards """
  13. a = graphsim.GraphRegister(1)
  14. b = GraphState()
  15. b.add_node(0)
  16. assert_equal(a, b)
  17. a.hadamard(0)
  18. b.act_hadamard(0)
  19. assert_equal(a, b)
  20. a.hadamard(0)
  21. b.act_hadamard(0)
  22. assert_equal(a, b)
  23. def test_local_rotations():
  24. """ Test local rotations """
  25. a = graphsim.GraphRegister(1)
  26. b = GraphState()
  27. b.add_node(0)
  28. assert_equal(a, b)
  29. for i in range(1000):
  30. j = random.randint(0, 23)
  31. a.local_op(0, graphsim.LocCliffOp(j))
  32. b.act_local_rotation(0, j)
  33. assert_equal(a, b)
  34. def test_cz_table(N=10):
  35. """ Test the CZ table """
  36. clifford.use_old_cz()
  37. for i in range(24):
  38. for j in range(24):
  39. a = graphsim.GraphRegister(2)
  40. b = GraphState()
  41. b.add_nodes([0, 1])
  42. a.local_op(0, graphsim.LocCliffOp(i))
  43. b.act_local_rotation(0, i)
  44. a.local_op(1, graphsim.LocCliffOp(j))
  45. b.act_local_rotation(1, j)
  46. a.cphase(0, 1)
  47. b.act_cz(0, 1)
  48. assert_equal(a, b)
  49. for i in range(24):
  50. for j in range(24):
  51. a = graphsim.GraphRegister(2)
  52. b = GraphState()
  53. b.add_nodes([0, 1])
  54. a.local_op(0, graphsim.LocCliffOp(10))
  55. b.act_local_rotation(0, 10)
  56. a.cphase(0, 1)
  57. b.act_cz(0, 1)
  58. a.local_op(0, graphsim.LocCliffOp(i))
  59. b.act_local_rotation(0, i)
  60. a.local_op(1, graphsim.LocCliffOp(j))
  61. b.act_local_rotation(1, j)
  62. a.cphase(0, 1)
  63. b.act_cz(0, 1)
  64. assert_equal(a, b)
  65. def test_with_cphase_gates_hadamard_only(N=10):
  66. """ Hadamrds and CPHASEs, deterministic """
  67. a = graphsim.GraphRegister(N)
  68. b = GraphState()
  69. for i in range(N):
  70. a.hadamard(i)
  71. b.add_node(i)
  72. b.act_hadamard(i)
  73. for i in range(N-1):
  74. a.cphase(i, i+1)
  75. b.act_cz(i, i+1)
  76. assert_equal(a, b)
  77. def test_cz_hadamard(N=3):
  78. """ Test CZs and Hadamards at random """
  79. clifford.use_old_cz()
  80. a = graphsim.GraphRegister(N)
  81. b = GraphState(range(N))
  82. previous_state, previous_cz = None, None
  83. for i in tqdm(range(REPEATS), desc="Testing CZ and Hadamard against A&B"):
  84. if random.random()>0.5:
  85. j = random.randint(0, N-1)
  86. a.hadamard(j)
  87. b.act_hadamard(j)
  88. else:
  89. q = random.randint(0, N-2)
  90. if a!=b:
  91. a.cphase(q, q+1)
  92. b.act_cz(q, q+1)
  93. assert_equal(a, b)
  94. def test_all(N=5):
  95. """ Test everything"""
  96. clifford.use_old_cz()
  97. a = graphsim.GraphRegister(N)
  98. b = GraphState(range(N))
  99. previous_state, previous_cz = None, None
  100. for i in tqdm(range(REPEATS), desc="Testing all gates against Anders and Briegel"):
  101. if random.random()>0.5:
  102. j = random.randint(0, N-1)
  103. u = random.randint(0, 23)
  104. a.local_op(j, graphsim.LocCliffOp(u))
  105. b.act_local_rotation(j, u)
  106. else:
  107. q = random.randint(0, N-2)
  108. if a!=b:
  109. a.cphase(q, q+1)
  110. b.act_cz(q, q+1)
  111. assert_equal(a, b)