Anders and Briegel in Python
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.

index.rst 6.5KB

il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. .. abp documentation master file, created by
  2. sphinx-quickstart on Sun Jul 24 18:12:02 2016.
  3. You can adapt this file completely to your liking, but it should at least
  4. contain the root `toctree` directive.
  5. ``abp``
  6. ===============================
  7. This is the documentation for ``abp``. It's a work in progress.
  8. .. toctree::
  9. :hidden:
  10. :maxdepth: 2
  11. modules
  12. ``abp`` is a Python port of Anders and Briegel' s `method <https://arxiv.org/abs/quant-ph/0504117>`_ for fast simulation of Clifford circuits.
  13. That means that you can make quantum states of thousands of qubits, perform any sequence of Clifford operations, and measure in any of :math:`\{\sigma_x, \sigma_y, \sigma_z\}`.
  14. Installing
  15. ----------------------------
  16. You can install from ``pip``:
  17. .. code-block:: bash
  18. $ pip install --user abp==0.4.26
  19. Alternatively, clone from the `github repo <https://github.com/peteshadbolt/abp>`_ and run ``setup.py``:
  20. .. code-block:: bash
  21. $ git clone https://github.com/peteshadbolt/abp
  22. $ cd abp
  23. $ python setup.py install --user
  24. If you want to modify and test ``abp`` without having to re-install, switch into ``develop`` mode:
  25. .. code-block:: bash
  26. $ python setup.py develop --user
  27. Quickstart
  28. ----------------------------
  29. Let's make a new ``GraphState`` object with a register of three qubits:
  30. >>> from abp import GraphState
  31. >>> g = GraphState(3)
  32. All the qubits are initialized by default in the :math:`|+\rangle` state::
  33. >>> print g.to_state_vector()
  34. |000❭: √1/8 + i √0
  35. |100❭: √1/8 + i √0
  36. |010❭: √1/8 + i √0
  37. |110❭: √1/8 + i √0
  38. |001❭: √1/8 + i √0
  39. |101❭: √1/8 + i √0
  40. |011❭: √1/8 + i √0
  41. |111❭: √1/8 + i √0
  42. We can also check the stabilizer tableau::
  43. >>> print g.to_stabilizer()
  44. 0 1 2
  45. ---------
  46. X
  47. X
  48. X
  49. Or look directly at the vertex operators and neighbour lists::
  50. >>> print g
  51. 0: IA -
  52. 1: IA -
  53. 2: IA -
  54. This representation might be unfamiliar. Each row shows the index of the qubit, then the **vertex operator**, then a list of neighbouring qubits. To understand vertex operators, read the original paper by Anders and Briegel.
  55. Let's act a Hadamard gate on the zeroth qubit -- this will evolve qubit ``0`` to the :math:`H|+\rangle = |1\rangle` state::
  56. >>> g.act_hadamard(0)
  57. >>> print g.to_state_vector()
  58. |000❭: √1/4 + i √0
  59. |010❭: √1/4 + i √0
  60. |001❭: √1/4 + i √0
  61. |011❭: √1/4 + i √0
  62. >>> print g
  63. 0: YC -
  64. 1: IA -
  65. 2: IA -
  66. And now run some CZ gates::
  67. >>> g.act_cz(0,1)
  68. >>> g.act_cz(1,2)
  69. >>> print g
  70. 0: YC -
  71. 1: IA (2,)
  72. 2: IA (1,)
  73. >>> print g.to_state_vector()
  74. |000❭: √1/4 + i √0
  75. |010❭: √1/4 + i √0
  76. |001❭: √1/4 + i √0
  77. |011❭: -√1/4 + i √0
  78. Tidy up a bit::
  79. >>> g.del_node(0)
  80. >>> g.act_hadamard(0)
  81. >>> print g.to_state_vector()
  82. |00❭: √1/2 + i √0
  83. |11❭: √1/2 + i √0
  84. Cool, we made a Bell state. Incidentally, those those state vectors and stabilizers are genuine Python objects, not just stringy representations of the state::
  85. >>> g = abp.GraphState(2)
  86. >>> g.act_cz(0, 1)
  87. >>> g.act_hadamard(0)
  88. >>> psi = g.to_state_vector()
  89. >>> print psi
  90. |00❭: √1/2 + i √0
  91. |11❭: √1/2 + i √0
  92. ``psi`` is a state vector -- i.e. it is an exponentially large vector of complex numbers. We can still run gates on it::
  93. >>> psi.act_cnot(0, 1)
  94. >>> psi.act_hadamard(0)
  95. >>> print psi
  96. |00❭: √1 + i √0
  97. But these operations will be very slow. Let's have a look at the stabilizer tableau::
  98. >>> tab = g.to_stabilizer()
  99. >>> print tab
  100. 0 1
  101. ------
  102. Z Z
  103. X X
  104. >>> print tab.tableau
  105. {0: {0: 3, 1: 3}, 1: {0: 1, 1: 1}}
  106. >>> print tab[0, 0]
  107. 3
  108. Quantum mechanics is nondeterminstic. However, it's often useful to get determinstic behaviour for testing purposes. You can force ``abp`` to behave determinstically by setting::
  109. >>> abp.DETERMINSTIC = True
  110. Visualization
  111. ----------------------
  112. ``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.
  113. First, run ``abpserver -v`` in a terminal:
  114. .. code-block:: bash
  115. $ abpserver -v
  116. Listening on port 5000 for clients..
  117. 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::
  118. >>> from abp import GraphState, VizClient
  119. >>> g = GraphState(10)
  120. >>> g.act_circuit([("hadamard", i) for i in range(10)])
  121. >>> g.act_circuit([("cz", (i, i+1)) for i in range(9)])
  122. >>> v = VizClient()
  123. >>> v.update(g)
  124. And you should see a 3D visualization of the state. You can call ``update()`` in a loop to see an animation.
  125. 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::
  126. >>> g.add_qubit(0, position={"x": 0, "y":0, "z":0}, vop="identity")
  127. >>> g.add_qubit(0, position={"x": 1, "y":0, "z":0}, vop="identity")
  128. There's a utility function in ``abp.util`` to construct those dictionaries::
  129. >>> from abp.util import xyz
  130. >>> g.add_qubit(0, position=xyz(0, 0, 0), vop="identity")
  131. >>> g.add_qubit(1, position=xyz(0, 0, 1), vop="identity")
  132. Note that if **any** nodes are missing a ``position`` attribute, ``abp`` will revert to automatic layout for **all** qubits.
  133. GraphState API
  134. -------------------------
  135. The ``abp.GraphState`` class is the main interface to ``abp``.
  136. .. autoclass:: abp.GraphState
  137. :special-members: __init__
  138. :members:
  139. .. _clifford:
  140. The Clifford group
  141. ----------------------
  142. .. automodule:: abp.clifford
  143. |
  144. The ``clifford`` module provides a few useful functions:
  145. .. autofunction:: abp.clifford.use_old_cz
  146. :noindex:
  147. Testing
  148. ----------------------
  149. ``abp`` has a bunch of tests. It tests against all sorts of things, including the circuit model, Anders & Briegels' original code, Scott Aaronson's ``chp``, and common sense. You can run all the tests using ``nose``::
  150. $ nosetests
  151. ...
  152. 53 tests run in 39.5 seconds (53 tests passed)
  153. Currently I use some reference implementations of ``chp`` and ``graphsim`` which you won't have installed, so some tests will be skipped. That's expected.
  154. Reference
  155. ----------------------------
  156. More detailed docs are available here:
  157. * :ref:`genindex`
  158. * :ref:`modindex`
  159. * :ref:`search`