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.

doc.md 3.2KB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Graph state server
  2. [Graph states](https://en.wikipedia.org/wiki/Graph_state) are a way of efficiently representing the state of a system of qubits. This tool simulates the behaviour of the graph state and shows an interactive 3D representation of the state. Interaction with the simulation is done either by clicking on things in the web browser or through an API.
  3. ## Using the interface
  4. The state is initialized as a blank canvas without any qubits.
  5. - Click on the grid to make a new qubit
  6. - Hold <kbd>Ctrl</kbd> and click on a qubit to act a Hadamard gate
  7. - Click on a qubit to view its properties
  8. - Select a qubit, then <kbd>Shift</kbd>-click another node to act a CZ gate
  9. - Press <kbd>Space</kbd> to rotate the grid
  10. Arbitrary 3D structures can be constructed by rotating the grid.
  11. The URL contains a unique ID such as `oranges-arkansas-mexico-fish`. You can share this URL with other people to share your screen and edit collaboratively.
  12. ## Python package
  13. The underlying graph state simulator is based on Anders' and Briegel's method. Full docs for the Python package are [here](https://peteshadbolt.co.uk/static/abp/). You can install it like this:
  14. :::bash
  15. $ pip install abp
  16. ## API
  17. Here's a complete example of sending a state from Python to the server:
  18. :::python
  19. import abp
  20. # Make a new graph and automatically position the nodes
  21. g = abp.NXGraphState(range(10))
  22. g.layout()
  23. # Post to the server
  24. g.push()
  25. ### Endpoints
  26. - `/<uuid>`: Displays the state using Three.js
  27. - `/<uuid>/graph`:
  28. - `GET` returns JSON representing the state
  29. - `POST` accepts JSON in the same format and overwrites the state in memory
  30. - `/<uuid>/edit`:
  31. - `POST` accepts edit commands such as `cz`, `add_node` etc.
  32. - `doc/`: Shows this page
  33. ### Data format
  34. An HTTP GET to `/<uuid>/graph` will return some JSON.
  35. $ curl https://abv.peteshadbolt.co.uk/<uuid>/graph
  36. {
  37. "adj": {
  38. "(0, 0, 1)": {
  39. "(0, 1, 1)": {},
  40. "(1, 0, 1)": {}
  41. },
  42. "(0, 0, 3)": {
  43. "(0, 1, 3)": {},
  44. "(1, 0, 3)": {}
  45. },
  46. "(0, 0, 5)": {
  47. "(0, 1, 5)": {},
  48. "(1, 0, 5)": {}
  49. },
  50. "(0, 1, 0)": {
  51. "(0, 1, 1)": {},
  52. "(1, 1, 0)": {}
  53. },
  54. "(0, 1, 1)": {
  55. "(0, 0, 1)": {},
  56. ...
  57. The top-level keys are `node` and `adj`. These model the node metadata and adjacency matrix respectively.
  58. Each `node` has
  59. - a `position` (`{x:<> y:<> z:<>}`)
  60. - a `vop` (integer, ignore for now)
  61. - and could also have a `color`, `label`, etc.
  62. `adj` uses the same data structure as `networkx` to efficiently represent sparse adjacency matrices. For each key `i` in `adj`, the value of `adj[i]` is itself a map whose keys `j` correspond to the ids of nodes connected to `i`. The value of `adj[i][j]` is a map which is usually empty but which could be used to store metadata about the edge.
  63. Here's an example of a graph `(A-B C)`:
  64. :::python
  65. {'adj': {0: {1: {}}, 1: {0: {}}, 2: {}},
  66. 'node': {
  67. 0: {'position': {'x': 0, 'y': 0, 'z': 0}, 'vop': 0},
  68. 1: {'position': {'x': 1, 'y': 0, 'z': 0}, 'vop': 0},
  69. 2: {'position': {'x': 2, 'y': 0, 'z': 0}, 'vop': 10}}}