Anders and Briegel in Python
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

stress_test.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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]))