Anders and Briegel in Python
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. from abp import GraphState, clifford
  2. from abp.fancy import GraphState as Fancy
  3. from anders_briegel import graphsim
  4. import random
  5. import numpy as np
  6. from tqdm import tqdm
  7. import time
  8. import itertools as it
  9. import sys
  10. REPEATS = 100000
  11. N=9
  12. def compare(A, B):
  13. keys_same = set(A["node"].keys()) == set(B["node"].keys())
  14. vops_same = all(A["node"][i]["vop"] == B["node"][i]["vop"] for i in A["node"].keys())
  15. edges_same = A["adj"] == B["adj"]
  16. if keys_same and vops_same and edges_same:
  17. return True
  18. sys.exit(0)
  19. print "doing a state vector check"
  20. alice = GraphState(range(N))
  21. alice.node = A["node"]
  22. alice.adj = A["adj"]
  23. bob = GraphState(range(N))
  24. bob.node = B["node"]
  25. bob.adj = B["adj"]
  26. if alice.to_state_vector() == bob.to_state_vector():
  27. return True
  28. return False
  29. if __name__ == '__main__':
  30. clifford.use_old_cz()
  31. a = graphsim.GraphRegister(N)
  32. b = Fancy(range(N))
  33. # Keep comparing until fail
  34. while compare(a.to_json(), b.to_json()):
  35. if random.random()>0.5:
  36. j = np.random.randint(0, N)
  37. u = random.randint(0, 23)
  38. print "> Acting U{} on {}".format(u, j)
  39. a.local_op(j, graphsim.LocCliffOp(u))
  40. b.act_local_rotation(j, u)
  41. print "Done"
  42. else:
  43. i, j= np.random.randint(0, N, 2)
  44. if i!=j:
  45. print "> Acting CZ on {} & {}".format(i, j)
  46. a.cphase(i, j)
  47. b.act_cz(i, j)
  48. print "Done"
  49. #b.update(delay=0.1)
  50. # Show the diff
  51. A = a.to_json()["node"]
  52. B = b.to_json()["node"]
  53. for i in range(N):
  54. if A[i]["vop"] != B[i]["vop"]:
  55. print "{}/ them: {}, me: {}".format(i, A[i]["vop"], B[i]["vop"])
  56. # Now construct unitaries
  57. A = a.to_json()
  58. B = b.to_json()
  59. alice = GraphState(range(N))
  60. alice.node = A["node"]
  61. alice.adj = A["adj"]
  62. bob = GraphState(range(N))
  63. bob.node = B["node"]
  64. bob.adj = B["adj"]
  65. print alice.to_state_vector() == bob.to_state_vector()
  66. b.layout()