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.3KB

  1. """
  2. Mock graphs used for testing
  3. """
  4. import numpy as np
  5. from abp import GraphState, clifford
  6. from anders_briegel import graphsim
  7. # We always run with A&B's CZ table when we are testing
  8. clifford.use_old_cz()
  9. class AndersWrapper(graphsim.GraphRegister):
  10. """ A wrapper for A&B to make the interface identical and enable equality testing """
  11. def __init__(self, nodes):
  12. assert list(nodes) == range(len(nodes))
  13. super(AndersWrapper, self).__init__(len(nodes))
  14. def act_local_rotation(qubit, operation):
  15. super(AndersWrapper, self).local_op(
  16. qubit, graphsim.LocCliffOp(operation))
  17. def act_cz(a, b):
  18. super(AndersWrapper, self).cphase(a, b)
  19. def measure(qubit, basis, force):
  20. basis = clifford.by_name[basis]
  21. basis = {1: graphsim.lco_X,
  22. 2: graphsim.lco_Y,
  23. 3: graphsim.lco_Z}[clifford.by_name[basis]]
  24. super(AndersWrapper, self).measure(qubit, basis, None, force)
  25. def __str__(self):
  26. return "A wrapped A&B state ({})".format(super(AndersWrapper, self).__str__())
  27. def __repr__(self):
  28. return self.__str__()
  29. class PeteWrapper(GraphState):
  30. """ A wrapper for abp, just to ensure determinism """
  31. def random_graph_state(N=10):
  32. """ A random Graph state. """
  33. for base in PeteWrapper, AndersWrapper:
  34. g = base(range(N))
  35. for i in range(N):
  36. g.act_hadamard(i)
  37. for i in range(10):
  38. j, k = np.random.choice(range(N), 2, replace=False)
  39. g.act_cz(j, k)
  40. yield g
  41. def random_stabilizer_state(N=10):
  42. a, b = random_state()
  43. for i in range(N):
  44. j = np.random.choice(range(N))
  45. k = np.random.choice(range(24))
  46. a.act_local_rotation(j, k)
  47. b.local_op(j, graphsim.LocCliffOp(k))
  48. return a, b
  49. def bell():
  50. a = GraphState(range(2))
  51. b = graphsim.GraphRegister(2)
  52. a.act_hadamard(0)
  53. a.act_hadamard(1)
  54. b.hadamard(0)
  55. b.hadamard(1)
  56. a.act_cz(0, 1)
  57. b.cphase(0, 1)
  58. return a, b
  59. def onequbit():
  60. a = GraphState(range(1))
  61. b = graphsim.GraphRegister(1)
  62. return a, b
  63. def demograph():
  64. """ A graph for testing with """
  65. g = GraphState([0, 1, 2, 3, 100, 200])
  66. g.add_edge(0, 1)
  67. g.add_edge(1, 2)
  68. g.add_edge(2, 0)
  69. g.add_edge(0, 3)
  70. g.add_edge(100, 200)
  71. return g