Pete Shadbolt 6 лет назад
Родитель
Сommit
f0b3c8a2a3
7 измененных файлов: 24 добавлений и 37 удалений
  1. +11
    -1
      abp/graphstate.py
  2. +0
    -0
      doc/_static/.nothing
  3. +0
    -2
      doc/abp.rst
  4. +0
    -10
      doc/abp.static.rst
  5. +0
    -1
      doc/index
  6. +12
    -22
      doc/index.rst
  7. +1
    -1
      examples/visualization/raussendorf.py

+ 11
- 1
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))



+ 0
- 0
doc/_static/.nothing Просмотреть файл


+ 0
- 2
doc/abp.rst Просмотреть файл

@@ -6,8 +6,6 @@ Subpackages

.. toctree::

abp.static

Submodules
----------



+ 0
- 10
doc/abp.static.rst Просмотреть файл

@@ -1,10 +0,0 @@
abp.static package
==================

Module contents
---------------

.. automodule:: abp.static
:members:
:undoc-members:
:show-inheritance:

+ 0
- 1
doc/index Просмотреть файл

@@ -1 +0,0 @@
_build/html/index.html

+ 12
- 22
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
-------------------------


+ 1
- 1
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()


Загрузка…
Отмена
Сохранить