Anders and Briegel in Python
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

59 řádky
1.9KB

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