Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
5.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.4.21
  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. GraphState API
  109. -------------------------
  110. The ``abp.GraphState`` class is the main interface to ``abp``.
  111. .. autoclass:: abp.GraphState
  112. :special-members: __init__
  113. :members:
  114. .. _clifford:
  115. The Clifford group
  116. ----------------------
  117. .. automodule:: abp.clifford
  118. |
  119. The ``clifford`` module provides a few useful functions:
  120. .. autofunction:: abp.clifford.use_old_cz
  121. :noindex:
  122. Visualization
  123. ----------------------
  124. ``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.
  125. First, run ``abpserver`` in a terminal:
  126. .. code-block:: bash
  127. $ abpserver
  128. Listening on port 5000 for clients..
  129. Then browse to ``http://localhost:5001/`` (in some circumstances ``abp`` will automatically pop a browser window).
  130. Now, in another terminal, use ``abp.fancy.GraphState`` to run a Clifford circuit::
  131. >>> from abp.fancy import GraphState
  132. >>> g = GraphState(10)
  133. >>> g.act_circuit([(i, "hadamard") for i in range(10)])
  134. >>> g.act_circuit([((i, i+1), "cz") for i in range(9)])
  135. >>> g.update()
  136. And you should see a 3D visualization of the state. You can call ``update()`` in a loop to see an animation.
  137. Reference
  138. ----------------------------
  139. More detailed docs are available here:
  140. * :ref:`genindex`
  141. * :ref:`modindex`
  142. * :ref:`search`