Simulate graph states in the browser
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 7 gadiem
pirms 7 gadiem
pirms 7 gadiem
pirms 7 gadiem
pirms 7 gadiem
pirms 7 gadiem
pirms 7 gadiem
pirms 7 gadiem
pirms 7 gadiem
pirms 7 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Graph state server
  2. Graph states 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 Ctrl and click on a qubit to act a Hadamard gate
  7. - Click on a qubit to view its properties
  8. - Select a qubit, then shift-click another node to act a CZ gate
  9. - Press space 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/).
  14. ## API
  15. Here's a complete example of sending a state from Python to the server:
  16. :::python
  17. import requests, json, abp
  18. # Make a new graph and position the nodes
  19. g = abp.NXGraphState(range(10))
  20. g.layout()
  21. # Serialize
  22. data = json.dumps(test_graph().to_json())
  23. # Post to the server
  24. URL = "https://abv.peteshadbolt.co.uk/oranges-arkansas-mexico-fish"
  25. requests.post("{}/graph".format(URL), data=data)
  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. :::bash
  37. $ curl https://abv.peteshadbolt.co.uk/<uuid>/graph
  38. outputs
  39. :::python
  40. {
  41. "adj": {
  42. "(0, 0, 1)": {
  43. "(0, 1, 1)": {},
  44. "(1, 0, 1)": {}
  45. },
  46. "(0, 0, 3)": {
  47. "(0, 1, 3)": {},
  48. "(1, 0, 3)": {}
  49. },
  50. "(0, 0, 5)": {
  51. "(0, 1, 5)": {},
  52. "(1, 0, 5)": {}
  53. },
  54. "(0, 1, 0)": {
  55. "(0, 1, 1)": {},
  56. "(1, 1, 0)": {}
  57. },
  58. "(0, 1, 1)": {
  59. "(0, 0, 1)": {},
  60. ...
  61. The top-level keys are `node` and `adj`. These model the node metadata and adjacency matrix respectively.
  62. Each `node` has
  63. - a `position` (`{x:<> y:<> z:<>}`)
  64. - a `vop` (integer, ignore for now)
  65. - and could also have a `color`, `label`, etc.
  66. `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.
  67. Here's an example of a graph `(A-B C)`:
  68. :::python
  69. {'adj': {0: {1: {}}, 1: {0: {}}, 2: {}},
  70. 'node': {
  71. 0: {'position': {'x': 0, 'y': 0, 'z': 0}, 'vop': 0},
  72. 1: {'position': {'x': 1, 'y': 0, 'z': 0}, 'vop': 0},
  73. 2: {'position': {'x': 2, 'y': 0, 'z': 0}, 'vop': 10}}}