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.

44 lines
1.2KB

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