Anders and Briegel in Python
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

41 行
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. funny_unit_cell = (((0, 0), (0, 1)), ((0, 0), (1, 0)),
  7. ((1, 0), (1, 1)), ((0, 1), (1, 1)), ((0, 0), (.5, .5)))
  8. def add_offset(vector, offset):
  9. """ Offset a vector in n-dimensional space """
  10. return tuple(v + o for v, o in zip(vector, offset))
  11. def offset_unit_cell(unit_cell, offset):
  12. """ Offset a unit cell """
  13. return {(add_offset(a, offset), add_offset(b, offset)) for a, b in unit_cell}
  14. def lattice(unit_cell, size):
  15. """ Generate a lattice from a unit cell """
  16. edges = set()
  17. for offset in itertools.product(*map(range, size)):
  18. edges |= offset_unit_cell(unit_cell, offset)
  19. nodes = set(itertools.chain(*edges))
  20. return nodes, edges
  21. # s = VisibleGraphState()
  22. nodes, edges = lattice(funny_unit_cell, (10, 10))
  23. psi = GraphState()
  24. for node in nodes:
  25. psi.add_node(str(node), position=xyz(node[0], node[1]))
  26. psi.act_hadamard(str(node))
  27. for edge in edges:
  28. psi.act_cz(str(edge[0]), str(edge[1]))