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.

43 lines
1.1KB

  1. from abp.fancy import GraphState
  2. from abp.util import xyz
  3. import numpy as np
  4. import time
  5. import itertools
  6. square_unit_cell = (
  7. ((0, 0), (0, 1)), ((0, 0), (1, 0)), ((1, 0), (1, 1)), ((0, 1), (1, 1)))
  8. funny_unit_cell = (((0, 0), (0, 1)), ((0, 0), (1, 0)),
  9. ((1, 0), (1, 1)), ((0, 1), (1, 1)), ((0, 0), (.5, .5)))
  10. def add_offset(vector, offset):
  11. """ Offset a vector in n-dimensional space """
  12. return tuple(v + o for v, o in zip(vector, offset))
  13. def offset_unit_cell(unit_cell, offset):
  14. """ Offset a unit cell """
  15. return {(add_offset(a, offset), add_offset(b, offset)) for a, b in unit_cell}
  16. def lattice(unit_cell, size):
  17. """ Generate a lattice from a unit cell """
  18. edges = set()
  19. for offset in itertools.product(*map(range, size)):
  20. edges |= offset_unit_cell(unit_cell, offset)
  21. nodes = set(itertools.chain(*edges))
  22. return nodes, edges
  23. # s = VisibleGraphState()
  24. nodes, edges = lattice(square_unit_cell, (4, 4))
  25. psi = GraphState()
  26. for node in nodes:
  27. psi.add_node(str(node), position=xyz(node[0], node[1]))
  28. psi.act_hadamard(str(node))
  29. for edge in edges:
  30. psi.act_cz(str(edge[0]), str(edge[1]))