Anders and Briegel in Python
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

lattice_3d.py 1.3KB

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. threedee_unit_cell = (
  7. (( 0, 0, 0), (0, 1, 0)),
  8. (( 0, 0, 0), (1, 0, 0)),
  9. (( 1, 0, 0), (1, 1, 0)),
  10. (( 0, 1, 0), (1, 1, 0)),
  11. (( 0, 0, 1), (0, 1, 1)),
  12. (( 0, 0, 1), (1, 0, 1)),
  13. (( 1, 0, 1), (1, 1, 1)),
  14. (( 0, 1, 1), (1, 1, 1)),
  15. (( 0, 0, 0), (0, 0, 1)),
  16. (( 0, 1, 0), (0, 1, 1)),
  17. (( 1, 0, 0), (1, 0, 1)),
  18. (( 1, 1, 0), (1, 1, 1))
  19. )
  20. def add_offset(vector, offset):
  21. """ Offset a vector in n-dimensional space """
  22. return tuple(v + o for v, o in zip(vector, offset))
  23. def offset_unit_cell(unit_cell, offset):
  24. """ Offset a unit cell """
  25. return {(add_offset(a, offset), add_offset(b, offset)) for a, b in unit_cell}
  26. def lattice(unit_cell, size):
  27. """ Generate a lattice from a unit cell """
  28. edges = set()
  29. for offset in itertools.product(*map(range, size)):
  30. edges |= offset_unit_cell(unit_cell, offset)
  31. nodes = set(itertools.chain(*edges))
  32. return nodes, edges
  33. nodes, edges = lattice(threedee_unit_cell, (4, 4, 4))
  34. psi = GraphState()
  35. for node in nodes:
  36. psi.add_node(str(node), position=xyz(*node))
  37. psi.act_hadamard(str(node))
  38. for edge in edges:
  39. psi.act_cz(str(edge[0]), str(edge[1]))
  40. psi.update(0.1)