Simulate graph states in the browser
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.

raussendorf.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from abp 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. import requests
  8. import json
  9. raussendorf_unit_cell = (
  10. ((1, 0, 0), (1, 1, 0)), ((0, 1, 0), (1, 1, 0)),
  11. ((1, 2, 0), (1, 1, 0)), ((2, 1, 0), (1, 1, 0)),
  12. ((1, 2, 2), (1, 1, 2)), ((0, 1, 2), (1, 1, 2)),
  13. ((1, 0, 2), (1, 1, 2)), ((2, 1, 2), (1, 1, 2)),
  14. ((0, 1, 0), (0, 1, 1)), ((0, 0, 1), (0, 1, 1)),
  15. ((0, 1, 2), (0, 1, 1)), ((0, 2, 1), (0, 1, 1)),
  16. ((2, 1, 0), (2, 1, 1)), ((2, 0, 1), (2, 1, 1)),
  17. ((2, 1, 2), (2, 1, 1)), ((2, 2, 1), (2, 1, 1)),
  18. ((1, 0, 0), (1, 0, 1)), ((0, 0, 1), (1, 0, 1)),
  19. ((1, 0, 2), (1, 0, 1)), ((2, 0, 1), (1, 0, 1)),
  20. ((1, 2, 0), (1, 2, 1)), ((0, 2, 1), (1, 2, 1)),
  21. ((1, 2, 2), (1, 2, 1)), ((2, 2, 1), (1, 2, 1)))
  22. def add_offset(vector, offset):
  23. """ Offset a vector in n-dimensional space """
  24. return tuple(v + o*2 for v, o in zip(vector, offset))
  25. def offset_unit_cell(unit_cell, offset):
  26. """ Offset a unit cell """
  27. return {(add_offset(a, offset), add_offset(b, offset)) for a, b in unit_cell}
  28. def lattice(unit_cell, size):
  29. """ Generate a lattice from a unit cell """
  30. edges = set()
  31. for offset in itertools.product(*map(range, size)):
  32. edges |= offset_unit_cell(unit_cell, offset)
  33. nodes = set(itertools.chain(*edges))
  34. return nodes, edges
  35. def raussendorf(N=3):
  36. """ Generates raussendorf lattice """
  37. nodes, edges = lattice(raussendorf_unit_cell, (N, N, N))
  38. psi = GraphState()
  39. for node in nodes:
  40. x, y, z = node
  41. color = "red" if (x+y+z) % 2 > 0 else "black"
  42. print color
  43. psi.add_qubit(node, position=xyz(*node), color=color)
  44. psi.act_hadamard(node)
  45. for edge in edges:
  46. psi.act_cz(edge[0], edge[1])
  47. return psi