Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lattice_3d.py 1.3KB

8 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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]))