From f0b3c8a2a36901ccdc9d89f53959e8c3217d6ca4 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Mon, 23 Oct 2017 19:28:12 -0700 Subject: [PATCH] Fxing up documents --- abp/graphstate.py | 12 +++++++++- doc/_static/.nothing | 0 doc/abp.rst | 2 -- doc/abp.static.rst | 10 -------- doc/index | 1 - doc/index.rst | 34 ++++++++++----------------- examples/visualization/raussendorf.py | 2 +- 7 files changed, 24 insertions(+), 37 deletions(-) create mode 100644 doc/_static/.nothing delete mode 100644 doc/abp.static.rst delete mode 120000 doc/index diff --git a/abp/graphstate.py b/abp/graphstate.py index 2ce95e6..2ef246e 100755 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -494,7 +494,7 @@ class GraphState(object): g.adj = self.adj.copy() return g - def show(self): + def push(self): """ Shares the state on the server and displays browser """ if self.url == None: self.url = requests.get("https://abv.peteshadbolt.co.uk/").url @@ -502,5 +502,15 @@ class GraphState(object): data = json.dumps(self.to_json(stringify=True)) print("Shared state to {}".format(self.url)) return requests.post("{}/graph".format(self.url), data=data) + + def pull(self, url=None): + """ Loads the state from the server """ + if url: + self.url = url + + response = requests.get("{}/graph".format(self.url)) + self.from_json(json.loads(response.content)) + + diff --git a/doc/_static/.nothing b/doc/_static/.nothing new file mode 100644 index 0000000..e69de29 diff --git a/doc/abp.rst b/doc/abp.rst index 0137109..502eed2 100644 --- a/doc/abp.rst +++ b/doc/abp.rst @@ -6,8 +6,6 @@ Subpackages .. toctree:: - abp.static - Submodules ---------- diff --git a/doc/abp.static.rst b/doc/abp.static.rst deleted file mode 100644 index 958cfb1..0000000 --- a/doc/abp.static.rst +++ /dev/null @@ -1,10 +0,0 @@ -abp.static package -================== - -Module contents ---------------- - -.. automodule:: abp.static - :members: - :undoc-members: - :show-inheritance: diff --git a/doc/index b/doc/index deleted file mode 120000 index e0128f2..0000000 --- a/doc/index +++ /dev/null @@ -1 +0,0 @@ -_build/html/index.html \ No newline at end of file diff --git a/doc/index.rst b/doc/index.rst index b46a514..fb04dd7 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -153,27 +153,9 @@ Quantum mechanics is nondeterminstic. However, it's often useful to get determin Visualization ---------------------- -``abp`` comes with a tool to visualize graph states in a WebGL compatible web browser (Chrome, Firefox, Safari etc). It uses a client-server architecture. +You can visualize states in 3D using the tool at `https://abv.peteshadbolt.co.uk/`. At some point I will merge the code for that server into this repo. -First, run ``abpserver -v`` in a terminal: - -.. code-block:: bash - - $ abpserver -v - Listening on port 5000 for clients.. - -This ought to pop open a browser window at ``http://localhost:5001/``. You can run ``abpserver --help`` for help. Now use an instance of ``abp.VizClient`` to show the state in the browser:: - - >>> from abp import GraphState, VizClient - >>> g = GraphState(10) - >>> g.act_circuit([(i, "hadamard") for i in range(10)]) - >>> g.act_circuit([((i, i+1), "cz") for i in range(9)]) - >>> v = VizClient() - >>> v.update(g) - -And you should see a 3D visualization of the state. You can call ``update()`` in a loop to see an animation. - -By default, the graph is automatically laid out in 3D using the Fruchterman-Reingold force-directed algorithm (i.e. springs). If you want to specify geometry, give each node a position attribute:: +In order to visualize states you must give each node a position attribute:: >>> g.add_qubit(0, position={"x": 0, "y":0, "z":0}, vop="identity") >>> g.add_qubit(0, position={"x": 1, "y":0, "z":0}, vop="identity") @@ -182,10 +164,18 @@ There's a utility function in ``abp.util`` to construct those dictionaries:: >>> from abp.util import xyz >>> g.add_qubit(0, position=xyz(0, 0, 0), vop="identity") - >>> g.add_qubit(1, position=xyz(0, 0, 1), vop="identity") + >>> g.add_qubit(1, position=xyz(1, 0, 0), vop="identity") + +Then it's really easy to get a 3D picture of the state:: + + >>> g.push() + Shared state to https://abv.peteshadbolt.co.uk/lamp-moon-india-leopard -Note that if **any** nodes are missing a ``position`` attribute, ``abp`` will revert to automatic layout for **all** qubits. +That's a secret URL that you can use to collaboratively edit and view graph states in the browser. There are only a few billion such URLs so it should not be considered extremely secure. If you want, you can also load an existing state:: + >>> g = GraphState() + >>> g.pull("https://abv.peteshadbolt.co.uk/lamp-moon-india-leopard") + >>> g.show() GraphState API ------------------------- diff --git a/examples/visualization/raussendorf.py b/examples/visualization/raussendorf.py index dfab927..dd1eaab 100644 --- a/examples/visualization/raussendorf.py +++ b/examples/visualization/raussendorf.py @@ -52,5 +52,5 @@ for node in nodes: for edge in edges: psi.act_cz(edge[0], edge[1]) -psi.show() +psi.push()