Anders and Briegel in Python
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

52 строки
1.7KB

  1. """
  2. Implements a simple Stabilizer object.
  3. """
  4. import itertools as it
  5. from abp import clifford
  6. I = clifford.identity
  7. X = clifford.px
  8. Z = clifford.pz
  9. class Stabilizer(object):
  10. def __init__(self, g):
  11. """ Construct a Stabilizer from a Graphstate """
  12. self.tableau = {i:{j: I for j in g.node} for i in g.node}
  13. self.phases = {i: 1 for i in g.node}
  14. for a, b in it.product(g.node, g.node):
  15. if a == b:
  16. self.tableau[a][b] = X
  17. elif a in g.adj[b]:
  18. self.tableau[a][b] = Z
  19. self.conjugate(a, b, g.node[b]["vop"])
  20. def conjugate(self, a, b, vop):
  21. """ Do a little conjugation """
  22. op, phase = clifford.conjugate(self.tableau[a][b], vop)
  23. self.tableau[a][b] = op
  24. self.phases[a] *= phase
  25. def to_dictionary(self):
  26. """ For comparison with old A&B code """
  27. m = {1: 0, 1j:1, -1: 2, -1j: 3}
  28. return {"paulis": self.tableau,
  29. "phases": {key: m[value] for key, value in self.phases.items()}}
  30. def __str__(self):
  31. """ Represent as a string """
  32. keys = map(str, self.tableau.keys())
  33. w = max(len(k) for k in keys)
  34. keys = [k.ljust(w) for k in keys]
  35. s = " {}\n".format(" ".join(map(str, keys)))
  36. s += " " + "-"*len(keys)*(w+2) + "\n"
  37. for i in sorted(self.phases):
  38. sign = self.phases[i]
  39. sign = {1: " ", -1: " -", 1j: " i", -1j: "-i"}[sign]
  40. row = (self.tableau[i][j] for j in sorted(self.phases))
  41. row = (" XYZ"[i].ljust(w) for i in row)
  42. row = " ".join(row)
  43. s += "{} {}\n".format(sign, row)
  44. return s