Anders and Briegel in Python
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

223 строки
6.1KB

  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.6.0
  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. 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.
  113. In order to visualize states you must give each node a position attribute::
  114. >>> g.add_qubit(0, position={"x": 0, "y":0, "z":0}, vop="identity")
  115. >>> g.add_qubit(0, position={"x": 1, "y":0, "z":0}, vop="identity")
  116. There's a utility function in ``abp.util`` to construct those dictionaries::
  117. >>> from abp.util import xyz
  118. >>> g.add_qubit(0, position=xyz(0, 0, 0), vop="identity")
  119. >>> g.add_qubit(1, position=xyz(1, 0, 0), vop="identity")
  120. Then it's really easy to get a 3D picture of the state::
  121. >>> g.push()
  122. Shared state to https://abv.peteshadbolt.co.uk/lamp-moon-india-leopard
  123. 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::
  124. >>> g = GraphState()
  125. >>> g.pull("https://abv.peteshadbolt.co.uk/lamp-moon-india-leopard")
  126. >>> g.show()
  127. GraphState API
  128. -------------------------
  129. The ``abp.GraphState`` class is the main interface to ``abp``.
  130. .. autoclass:: abp.GraphState
  131. :special-members: __init__
  132. :members:
  133. .. _clifford:
  134. The Clifford group
  135. ----------------------
  136. .. automodule:: abp.clifford
  137. |
  138. The ``clifford`` module provides a few useful functions:
  139. .. autofunction:: abp.clifford.use_old_cz
  140. :noindex:
  141. Testing
  142. ----------------------
  143. ``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``::
  144. $ nosetests
  145. ...
  146. 53 tests run in 39.5 seconds (53 tests passed)
  147. 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.
  148. Reference
  149. ----------------------------
  150. More detailed docs are available here:
  151. * :ref:`genindex`
  152. * :ref:`modindex`
  153. * :ref:`search`