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.

68 lignes
2.6KB

  1. from abp import GraphState, clifford
  2. from anders_briegel import graphsim
  3. import numpy as np
  4. from tqdm import tqdm
  5. import dummy
  6. import itertools as it
  7. from config import *
  8. N = 10
  9. m = {1: graphsim.lco_X, 2: graphsim.lco_Y, 3: graphsim.lco_Z}
  10. def test_2qubit():
  11. """ Relentless testing of measurements """
  12. clifford.use_old_cz()
  13. for measurement in (3, 2, 1):
  14. for outcome in (0, 1):
  15. a, b = dummy.bell()
  16. a.measure(0, str(measurement), outcome)
  17. b.measure(0, m[measurement], None, outcome)
  18. assert a == b, (measurement, outcome)
  19. def test_multiqubit():
  20. """ Relentless testing of measurements """
  21. for measurement in (3,2,1,):
  22. for i in tqdm(range(REPEATS), "Testing measurement {}".format(measurement)):
  23. for outcome in (0, 1):
  24. a, b = dummy.clean_random_state(N)
  25. a.measure(0, str(measurement), outcome)
  26. b.measure(0, m[measurement], None, outcome)
  27. assert a == b, (measurement, outcome)
  28. def test_multiqubit2():
  29. """ Relentless testing of measurements """
  30. for measurement in (3,2,1):
  31. for i in tqdm(range(REPEATS), "Testing {} measurement".format(measurement)):
  32. for outcome in (0, 1):
  33. for rotation in range(24):
  34. a, b = dummy.clean_random_state(N)
  35. assert a == b
  36. a.act_local_rotation(0, str(rotation))
  37. b.local_op(0, graphsim.LocCliffOp(rotation))
  38. #print "{} ------------------".format(rotation)
  39. #print "pjs b4:", a.to_json()
  40. #print "a&b b4:", b.to_json()
  41. oa = a.measure(0, str(measurement), outcome)
  42. ob = b.measure(0, m[measurement], None, outcome)
  43. assert oa == ob, (oa, ob, rotation)
  44. #print "pjs af:", a.to_json()
  45. #print "a&b af:", b.to_json()
  46. assert a == b, (measurement, outcome, rotation)
  47. #print
  48. def test_multiqubit3():
  49. """ More measurement """
  50. for i in tqdm(range(REPEATS), "Testing messy measurement"):
  51. for measurement, outcome in it.product((3,2,1), (0,1)):
  52. a, b = dummy.messy_random_state(N)
  53. assert a == b
  54. oa = a.measure(0, str(measurement), outcome)
  55. ob = b.measure(0, m[measurement], None, outcome)
  56. assert oa == ob, (oa, ob, rotation)
  57. assert a == b, (measurement, outcome)