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

6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. - Use the <kbd>Up</kbd> and <kbd>Down</kbd> arrow keys to move the grid normal to its plane.
  11. Arbitrary 3D structures can be constructed by rotating the grid.
  12. 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.
  13. ## Python package
  14. 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:
  15. :::bash
  16. $ pip install abp
  17. ## API
  18. Here's a complete example of sending a state from Python to the server:
  19. :::python
  20. import abp
  21. # Make a new graph and automatically position the nodes
  22. g = abp.NXGraphState(range(10))
  23. g.layout()
  24. # Post to the server
  25. g.push()
  26. ### Endpoints
  27. - `/<uuid>`: Displays the state using Three.js
  28. - `/<uuid>/graph`:
  29. - `GET` returns JSON representing the state
  30. - `POST` accepts JSON in the same format and overwrites the state in memory
  31. - `/<uuid>/edit`:
  32. - `POST` accepts edit commands such as `cz`, `add_node` etc.
  33. - `doc/`: Shows this page
  34. ### Data format
  35. An HTTP GET to `/<uuid>/graph` will return some JSON.
  36. $ curl https://abv.peteshadbolt.co.uk/<uuid>/graph
  37. {
  38. "adj": {
  39. "(0, 0, 1)": {
  40. "(0, 1, 1)": {},
  41. "(1, 0, 1)": {}
  42. },
  43. "(0, 0, 3)": {
  44. "(0, 1, 3)": {},
  45. "(1, 0, 3)": {}
  46. },
  47. "(0, 0, 5)": {
  48. "(0, 1, 5)": {},
  49. "(1, 0, 5)": {}
  50. },
  51. "(0, 1, 0)": {
  52. "(0, 1, 1)": {},
  53. "(1, 1, 0)": {}
  54. },
  55. "(0, 1, 1)": {
  56. "(0, 0, 1)": {},
  57. ...
  58. The top-level keys are `node` and `adj`. These model the node metadata and adjacency matrix respectively.
  59. Each `node` has
  60. - a `position` (`{x:<> y:<> z:<>}`)
  61. - a `vop` (integer, ignore for now)
  62. - and could also have a `color`, `label`, etc.
  63. `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.
  64. Here's an example of a graph `(A-B C)`:
  65. :::python
  66. {'adj': {0: {1: {}}, 1: {0: {}}, 2: {}},
  67. 'node': {
  68. 0: {'position': {'x': 0, 'y': 0, 'z': 0}, 'vop': 0},
  69. 1: {'position': {'x': 1, 'y': 0, 'z': 0}, 'vop': 0},
  70. 2: {'position': {'x': 2, 'y': 0, 'z': 0}, 'vop': 10}}}