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.

227 lignes
6.3KB

  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.22
  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. Visualization
  109. ----------------------
  110. ``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.
  111. First, run ``abpserver -v`` in a terminal:
  112. .. code-block:: bash
  113. $ abpserver -v
  114. Listening on port 5000 for clients..
  115. This ought to pop open a browser window at ``http://localhost:5001/``. You can run ``abpserver --help`` for help. Now, in another terminal, use ``abp.fancy.GraphState`` to run a Clifford circuit::
  116. >>> from abp.fancy import GraphState
  117. >>> g = GraphState(10)
  118. >>> g.act_circuit([(i, "hadamard") for i in range(10)])
  119. >>> g.act_circuit([((i, i+1), "cz") for i in range(9)])
  120. >>> g.update()
  121. And you should see a 3D visualization of the state. You can call ``update()`` in a loop to see an animation.
  122. 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::
  123. >>> g.add_qubit(0, position={"x": 0, "y":0, "z":0}, vop="identity")
  124. >>> g.add_qubit(0, position={"x": 1, "y":0, "z":0}, vop="identity")
  125. There's a utility function in ``abp.util`` to construct those dictionaries::
  126. >>> from abp.util import xyz
  127. >>> g.add_qubit(0, position=xyz(0, 0, 0), vop="identity")
  128. >>> g.add_qubit(1, position=xyz(0, 0, 1), vop="identity")
  129. Note that if **any** nodes are missing a ``position`` attribute, ``abp`` will revert to automatic layout for **all** qubits.
  130. GraphState API
  131. -------------------------
  132. The ``abp.GraphState`` class is the main interface to ``abp``.
  133. .. autoclass:: abp.GraphState
  134. :special-members: __init__
  135. :members:
  136. .. _clifford:
  137. The Clifford group
  138. ----------------------
  139. .. automodule:: abp.clifford
  140. |
  141. The ``clifford`` module provides a few useful functions:
  142. .. autofunction:: abp.clifford.use_old_cz
  143. :noindex:
  144. Testing
  145. ----------------------
  146. ``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``::
  147. $ nosetests
  148. ...
  149. 53 tests run in 39.5 seconds (53 tests passed)
  150. 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.
  151. Reference
  152. ----------------------------
  153. More detailed docs are available here:
  154. * :ref:`genindex`
  155. * :ref:`modindex`
  156. * :ref:`search`