Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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