Anders and Briegel in Python
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

54 rindas
1.3KB

  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_node(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]))