Anders and Briegel in Python
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stress_test.py 1.2KB

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