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.

46 line
1.2KB

  1. from abp import GraphState, VizClient
  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, (10, 10))
  25. psi = GraphState()
  26. v = VizClient()
  27. for node in nodes:
  28. psi.add_qubit(str(node), position=xyz(node[0], node[1]))
  29. psi.act_hadamard(str(node))
  30. v.update(psi, 0.1)
  31. for edge in edges:
  32. psi.act_cz(str(edge[0]), str(edge[1]))
  33. v.update(psi, 0.1)