Anders and Briegel in Python
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lattice_2d.py 1.2KB

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