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

lattice_3d.py 1.3KB

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