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.

52 lines
985B

  1. from abp.graphstate import GraphState
  2. from anders_briegel import graphsim
  3. import random
  4. import difflib
  5. import re
  6. def test_1():
  7. N=10
  8. a = graphsim.GraphRegister(N)
  9. b = GraphState()
  10. for i in range(N):
  11. a.hadamard(i)
  12. b.add_vertex(i)
  13. b.act_hadamard(i)
  14. for i in range(N-1):
  15. a.cphase(i, i+1)
  16. b.act_cz(i, i+1)
  17. assert a.get_adj_list() == b.adj_list()
  18. def test_2():
  19. N=10
  20. a = graphsim.GraphRegister(N)
  21. b = GraphState()
  22. for i in range(N):
  23. b.add_vertex(i)
  24. for i in range(100):
  25. if random.random()>0.5:
  26. j = random.randint(0, N-1)
  27. a.hadamard(j)
  28. b.act_hadamard(j)
  29. else:
  30. q = random.randint(0, N-2)
  31. a.cphase(q, q+1)
  32. b.act_cz(q, q+1)
  33. aa = a.get_adj_list()
  34. bb = b.adj_list()
  35. try:
  36. assert re.sub("\\s", "", aa) == re.sub("\\s", "", bb)
  37. except AssertionError:
  38. print aa
  39. print bb