Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_against_anders_and_briegel.py 2.2KB

8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. """ TODO: 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. raise
  16. def test_hadamard():
  17. """ Test hadamards """
  18. a = graphsim.GraphRegister(1)
  19. b = GraphState()
  20. b.add_node(0)
  21. compare(a, b)
  22. a.hadamard(0)
  23. b.act_hadamard(0)
  24. compare(a, b)
  25. a.hadamard(0)
  26. b.act_hadamard(0)
  27. compare(a, b)
  28. def test_local_rotations():
  29. """ Test local rotations """
  30. a = graphsim.GraphRegister(1)
  31. b = GraphState()
  32. b.add_node(0)
  33. compare(a, b)
  34. for i in range(1000):
  35. j = random.randint(0, 23)
  36. a.local_op(0, graphsim.LocCliffOp(j))
  37. b.act_local_rotation(0, j)
  38. compare(a, b)
  39. def test_cz_table():
  40. """ Test the CZ table """
  41. for j in range(24):
  42. a = graphsim.GraphRegister(2)
  43. b = GraphState()
  44. b.add_node(0)
  45. b.add_node(1)
  46. compare(a, b)
  47. a.local_op(0, graphsim.LocCliffOp(j))
  48. b.act_local_rotation(0, j)
  49. a.local_op(1, graphsim.LocCliffOp(j))
  50. b.act_local_rotation(1, j)
  51. a.cphase(0, 1)
  52. b.act_cz(0, 1)
  53. compare(a, b)
  54. def test_1():
  55. """ TODO: this one always succeeds """
  56. N=10
  57. a = graphsim.GraphRegister(N)
  58. b = GraphState()
  59. for i in range(N):
  60. a.hadamard(i)
  61. b.add_node(i)
  62. b.act_hadamard(i)
  63. for i in range(N-1):
  64. a.cphase(i, i+1)
  65. b.act_cz(i, i+1)
  66. compare(a, b)
  67. def _test_2():
  68. """ TODO: This one fails at the moment """
  69. N=10
  70. a = graphsim.GraphRegister(N)
  71. b = GraphState()
  72. for i in range(N):
  73. b.add_node(i)
  74. for i in range(100):
  75. if random.random()>0.5:
  76. j = random.randint(0, N-1)
  77. a.hadamard(j)
  78. b.act_hadamard(j)
  79. else:
  80. q = random.randint(0, N-2)
  81. a.cphase(q, q+1)
  82. b.act_cz(q, q+1)
  83. aa = a.get_adj_list()
  84. bb = b.adj_list()
  85. compare(a, b)