Anders and Briegel in Python
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

61 líneas
1.8KB

  1. from __future__ import absolute_import
  2. from __future__ import print_function
  3. from abp import GraphState
  4. from abp.util import xyz
  5. import numpy as np
  6. import time
  7. import itertools
  8. import networkx as nx
  9. from six.moves import map
  10. from six.moves import zip
  11. raussendorf_unit_cell = (
  12. ((1, 0, 0), (1, 1, 0)), ((0, 1, 0), (1, 1, 0)),
  13. ((1, 2, 0), (1, 1, 0)), ((2, 1, 0), (1, 1, 0)),
  14. ((1, 2, 2), (1, 1, 2)), ((0, 1, 2), (1, 1, 2)),
  15. ((1, 0, 2), (1, 1, 2)), ((2, 1, 2), (1, 1, 2)),
  16. ((0, 1, 0), (0, 1, 1)), ((0, 0, 1), (0, 1, 1)),
  17. ((0, 1, 2), (0, 1, 1)), ((0, 2, 1), (0, 1, 1)),
  18. ((2, 1, 0), (2, 1, 1)), ((2, 0, 1), (2, 1, 1)),
  19. ((2, 1, 2), (2, 1, 1)), ((2, 2, 1), (2, 1, 1)),
  20. ((1, 0, 0), (1, 0, 1)), ((0, 0, 1), (1, 0, 1)),
  21. ((1, 0, 2), (1, 0, 1)), ((2, 0, 1), (1, 0, 1)),
  22. ((1, 2, 0), (1, 2, 1)), ((0, 2, 1), (1, 2, 1)),
  23. ((1, 2, 2), (1, 2, 1)), ((2, 2, 1), (1, 2, 1)))
  24. def add_offset(vector, offset):
  25. """ Offset a vector in n-dimensional space """
  26. return tuple(v + o*2 for v, o in zip(vector, offset))
  27. def offset_unit_cell(unit_cell, offset):
  28. """ Offset a unit cell """
  29. return {(add_offset(a, offset), add_offset(b, offset))
  30. for a, b in unit_cell}
  31. def lattice(unit_cell, size):
  32. """ Generate a lattice from a unit cell """
  33. edges = set()
  34. for offset in itertools.product(*list(map(range, size))):
  35. edges |= offset_unit_cell(unit_cell, offset)
  36. nodes = set(itertools.chain(*edges))
  37. return nodes, edges
  38. nodes, edges = lattice(raussendorf_unit_cell, (2, 2, 3))
  39. psi = GraphState()
  40. for node in nodes:
  41. x, y, z = node
  42. color = "red" if (x+y+z) % 2 > 0 else "black"
  43. psi.add_qubit(node, position=xyz(*node), color=color)
  44. psi.act_hadamard(node)
  45. for edge in edges:
  46. psi.act_cz(edge[0], edge[1])
  47. psi.push()