Simulate graph states in the browser
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

doc.md 2.8KB

il y a 7 ans
il y a 7 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # ABP server
  2. This server does a few things:
  3. - Keeps a graph state in memory using a data structure that is compatible with `abp`
  4. - Serves a JSON representation of that object
  5. - Accepts updates to that object via POST requests
  6. - Displays a 3D representation of the state
  7. - Randomly updates the state every five seconds
  8. ## Using the interface
  9. Sessions are identified by a UUID such as `oranges-arkansas-mexico-fish`. You can share this URL with other people to share your screen and edit collaboratively.
  10. - Click on the grid to make a new node
  11. - Ctrl-click a node to act a Hadamard gate
  12. - Select a node, then shift-click another node to act a CZ gate
  13. - Press space to rotate the grid
  14. ## Python package
  15. 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/).
  16. ## API
  17. We expose an API so that you can programmatically read and write states to/from the server and simulate mouse clicks.
  18. ### Endpoints
  19. - `/<uuid>`: Displays the state using Three.js
  20. - `/<uuid>/graph`:
  21. - `GET` returns JSON representing the state
  22. - `POST` accepts JSON in the same format and overwrites the state in memory
  23. - `/<uuid>/edit`:
  24. - `POST` accepts edit commands such as `cz`, `add_node` etc.
  25. - `doc/`: Shows this page
  26. ### Data format
  27. If you do an HTTPS GET against `/<uuid>/graph`, you will receive some JSON.
  28. :::bash
  29. $ curl https://abv.peteshadbolt.co.uk/<uuid>/graph
  30. outputs
  31. :::python
  32. {"node":
  33. {"30":
  34. {"position":
  35. {"y": 3.245091885135617, "x": -1.0335390368621762, "z": 0.12485495696298532}, "vop": 0}, "28":
  36. {"position":
  37. {"y": 0.1811335599620998, "x": 3.7102305790943295, "z": 0.3375519427305571}, "vop": 0}, "29":
  38. {"position":
  39. {"y": -1.834182888403804, "x": 1.5968911365745622, "z": 2.8585980299131886
  40. ...
  41. The top-level keys are `node` and `adj`. These model the node metadata and adjacency matrix respectively.
  42. Each `node` has
  43. - a `position` (`{x:<> y:<> z:<>}`)
  44. - a `vop` (integer, ignore for now)
  45. - and could also have a `color`, `label`, etc.
  46. `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.
  47. Here's an example of a graph `(A-B C)`:
  48. :::python
  49. {'adj': {0: {1: {}}, 1: {0: {}}, 2: {}},
  50. 'node': {
  51. 0: {'position': {'x': 0, 'y': 0, 'z': 0}, 'vop': 0},
  52. 1: {'position': {'x': 1, 'y': 0, 'z': 0}, 'vop': 0},
  53. 2: {'position': {'x': 2, 'y': 0, 'z': 0}, 'vop': 10}}}