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.

108 lignes
2.2KB

  1. from abp.graphstate import GraphState
  2. from anders_briegel import graphsim
  3. import random
  4. import difflib
  5. import re
  6. def compare(a, b):
  7. """ Sketchy as you like. Remove this abomination """
  8. aa = a.get_adj_list()
  9. bb = b.adj_list()
  10. try:
  11. assert re.sub("\\s", "", aa) == re.sub("\\s", "", bb)
  12. except AssertionError:
  13. print aa
  14. print bb
  15. def test_hadamard():
  16. """ Test hadamards """
  17. a = graphsim.GraphRegister(1)
  18. b = GraphState()
  19. b.add_vertex(0)
  20. compare(a, b)
  21. a.hadamard(0)
  22. b.act_hadamard(0)
  23. compare(a, b)
  24. a.hadamard(0)
  25. b.act_hadamard(0)
  26. compare(a, b)
  27. def test_local_rotations():
  28. """ Test local rotations """
  29. a = graphsim.GraphRegister(1)
  30. b = GraphState()
  31. b.add_vertex(0)
  32. compare(a, b)
  33. for i in range(1000):
  34. j = random.randint(0, 23)
  35. a.local_op(0, graphsim.LocCliffOp(j))
  36. b.act_local_rotation(0, j)
  37. compare(a, b)
  38. def test_cz_table():
  39. """ Test the CZ table """
  40. for j in range(24):
  41. a = graphsim.GraphRegister(2)
  42. b = GraphState()
  43. b.add_vertex(0)
  44. b.add_vertex(1)
  45. compare(a, b)
  46. #a.local_op(0, graphsim.LocCliffOp(j))
  47. #b.act_local_rotation(0, j)
  48. a.local_op(1, graphsim.LocCliffOp(j))
  49. b.act_local_rotation(1, j)
  50. a.cphase(0, 1)
  51. b.act_cz(0, 1)
  52. compare(a, b)
  53. def _test_1():
  54. """ TODO: this one always succeeds """
  55. N=10
  56. a = graphsim.GraphRegister(N)
  57. b = GraphState()
  58. for i in range(N):
  59. a.hadamard(i)
  60. b.add_vertex(i)
  61. b.act_hadamard(i)
  62. for i in range(N-1):
  63. a.cphase(i, i+1)
  64. b.act_cz(i, i+1)
  65. compare(a, b)
  66. def _test_2():
  67. """ TODO: This one fails at the moment """
  68. N=10
  69. a = graphsim.GraphRegister(N)
  70. b = GraphState()
  71. for i in range(N):
  72. b.add_vertex(i)
  73. for i in range(100):
  74. if random.random()>0.5:
  75. j = random.randint(0, N-1)
  76. a.hadamard(j)
  77. b.act_hadamard(j)
  78. else:
  79. q = random.randint(0, N-2)
  80. a.cphase(q, q+1)
  81. b.act_cz(q, q+1)
  82. aa = a.get_adj_list()
  83. bb = b.adj_list()
  84. compare(a, b)