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.

abp.py 2.2KB

il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from clifford import *
  2. """
  3. Porting Anders and Briegel to Python
  4. """
  5. stab_rep = {None: "-", 0: "I", 1: "X", 2: "Y", 3:"Z"}
  6. class Stabilizer(object):
  7. def __init__(self, graph):
  8. n = graph.nqubits
  9. self.paulis = [[None for i in range(n)] for j in range(n)]
  10. self.rowsigns = [None for i in range(n)]
  11. for i in range(n):
  12. self.rowsigns[i] = 0 % 4
  13. for j in range(n):
  14. if i == j:
  15. self.paulis[i][j] = lco_x
  16. elif j in graph.vertices[i].neighbors:
  17. self.paulis[i][j] = lco_z
  18. else:
  19. self.paulis[i][j] = lco_id
  20. self.conjugate(i, j, graph.vertices[j].vertex_operator)
  21. def conjugate(self, i, j, vertex_operator):
  22. self.rowsigns[j] = self.rowsigns[j] + \
  23. self.paulis[i][j].conjugate(vertex_operator)
  24. def __str__(self):
  25. return "\n".join(" ".join(stab_rep[x] for x in row) for row in self.paulis)
  26. class Vertex(object):
  27. def __init__(self, index):
  28. self.index = index
  29. self.vertex_operator = lco_h
  30. self.neighbors = set()
  31. def edgelist(self):
  32. return [set((self.index, n)) for n in self.neighbors]
  33. def __str__(self):
  34. return "{}".format(", ".join(map(str, self.neighbors)))
  35. class GraphRegister(object):
  36. def __init__(self, n):
  37. self.nqubits = n
  38. self.vertices = [Vertex(i) for i in xrange(n)]
  39. def add_edge(self, v1, v2):
  40. self.vertices[v1].neighbors.add(v2)
  41. self.vertices[v2].neighbors.add(v1)
  42. def del_edge(self, v1, v2):
  43. self.vertices[v1].neighbors.remove(v2)
  44. self.vertices[v2].neighbors.remove(v1)
  45. def toggle_edge(self, v1, v2):
  46. if v2 in self.vertices[v1].neighbors:
  47. self.del_edge(v1, v2)
  48. else:
  49. self.add_edge(v1, v2)
  50. def edgelist(self):
  51. return map(tuple, frozenset(frozenset((v.index, n))
  52. for v in self.vertices
  53. for n in v.neighbors))
  54. def __str__(self, ):
  55. return "graph:\n"+"\n".join(str(v) for v in self.vertices if len(v.neighbors) > 0)
  56. if __name__ == '__main__':
  57. g = GraphRegister(10)
  58. g.toggle_edge(0, 1)
  59. print g