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.

100 lignes
2.0KB

  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_1():
  28. """ Test local rotations """
  29. a = graphsim.GraphRegister(1)
  30. b = GraphState()
  31. b.add_vertex(0)
  32. compare(a, b)
  33. a.local_op(0, graphsim.LocCliffOp(10))
  34. b.act_local_rotation(0, 10)
  35. compare(a, b)
  36. a.local_op(0, graphsim.LocCliffOp(10))
  37. b.act_local_rotation(0, 10)
  38. compare(a, b)
  39. def test_local_2():
  40. """ Test local rotations """
  41. a = graphsim.GraphRegister(1)
  42. b = GraphState()
  43. b.add_vertex(0)
  44. compare(a, b)
  45. for i in range(1000):
  46. j = random.randint(0, 23)
  47. a.local_op(0, graphsim.LocCliffOp(j))
  48. b.act_local_rotation(0, j)
  49. compare(a, b)
  50. def test_1():
  51. N=10
  52. a = graphsim.GraphRegister(N)
  53. b = GraphState()
  54. for i in range(N):
  55. a.hadamard(i)
  56. b.add_vertex(i)
  57. b.act_hadamard(i)
  58. for i in range(N-1):
  59. a.cphase(i, i+1)
  60. b.act_cz(i, i+1)
  61. compare(a, b)
  62. def _test_2():
  63. N=10
  64. a = graphsim.GraphRegister(N)
  65. b = GraphState()
  66. for i in range(N):
  67. b.add_vertex(i)
  68. for i in range(100):
  69. if random.random()>0.5:
  70. j = random.randint(0, N-1)
  71. a.hadamard(j)
  72. b.act_hadamard(j)
  73. else:
  74. q = random.randint(0, N-2)
  75. a.cphase(q, q+1)
  76. b.act_cz(q, q+1)
  77. aa = a.get_adj_list()
  78. bb = b.adj_list()
  79. compare(a, b)