From 167c30b60e77294b285fbc50c38e44e33c8ae5da Mon Sep 17 00:00:00 2001 From: alan-nala <44471696+alan-nala@users.noreply.github.com> Date: Wed, 12 Jun 2024 04:39:59 -0300 Subject: [PATCH] Gates in qutip-v5 User Guide (#2441) Co-authored-by: alan-nala --- doc/apidoc/functions.rst | 7 +++ doc/changes/2441.doc | 1 + doc/guide/guide-basics.rst | 1 + doc/guide/guide-states.rst | 96 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 doc/changes/2441.doc diff --git a/doc/apidoc/functions.rst b/doc/apidoc/functions.rst index f5d58db96a..475c69aa98 100644 --- a/doc/apidoc/functions.rst +++ b/doc/apidoc/functions.rst @@ -21,6 +21,13 @@ Quantum Operators :members: charge, commutator, create, destroy, displace, fcreate, fdestroy, jmat, num, qeye, identity, momentum, phase, position, qdiags, qutrit_ops, qzero, sigmam, sigmap, sigmax, sigmay, sigmaz, spin_Jx, spin_Jy, spin_Jz, spin_Jm, spin_Jp, squeeze, squeezing, tunneling, qeye_like, qzero_like +Quantum Gates +----------------- + +.. automodule:: qutip.core.gates + :members: rx, ry, rz, sqrtnot, snot, phasegate, qrot, cy_gate, cz_gate, s_gate, t_gate, cs_gate, ct_gate, cphase, cnot, csign, berkeley, swapalpha, swap, iswap, sqrtswap, sqrtiswap, fredkin, molmer_sorensen, toffoli, hadamard_transform, qubit_clifford_group, globalphase + + Energy Restricted Operators --------------------------- diff --git a/doc/changes/2441.doc b/doc/changes/2441.doc new file mode 100644 index 0000000000..981bf2660c --- /dev/null +++ b/doc/changes/2441.doc @@ -0,0 +1 @@ +Added `qutip.core.gates` to apidoc/functions.rst and a Gates section to guide-states.rst. diff --git a/doc/guide/guide-basics.rst b/doc/guide/guide-basics.rst index 73e946881a..ef00ff37ac 100644 --- a/doc/guide/guide-basics.rst +++ b/doc/guide/guide-basics.rst @@ -427,6 +427,7 @@ Of course, like matrices, multiplying two objects of incompatible shape throws a In addition, the logic operators "is equal" `==` and "is not equal" `!=` are also supported. + .. _basics-functions: Functions operating on Qobj class diff --git a/doc/guide/guide-states.rst b/doc/guide/guide-states.rst index 4d4efc3c53..28859a3492 100644 --- a/doc/guide/guide-states.rst +++ b/doc/guide/guide-states.rst @@ -696,6 +696,101 @@ the non-zero component is the zeroth-element of the underlying matrix (remember If one wants to create spin operators for higher spin systems, then the :func:`.jmat` function comes in handy. +.. _quantum_gates: + +Gates +===== + +The pre-defined gates are shown in the table below: + + +.. cssclass:: table-striped + ++------------------------------------------------+-------------------------------------------------------+ +| Gate function | Description | ++================================================+=======================================================+ +| :func:`~qutip.core.gates.rx` | Rotation around x axis | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.ry` | Rotation around y axis | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.rz` | Rotation around z axis | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.sqrtnot` | Square root of not gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.sqrtnot` | Square root of not gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.snot` | Hardmard gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.phasegate` | Phase shift gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.qrot` | A qubit rotation under a Rabi pulse | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.cy_gate` | Controlled y gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.cz_gate` | Controlled z gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.s_gate` | Single-qubit rotation | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.t_gate` | Square root of s gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.cs_gate` | Controlled s gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.ct_gate` | Controlled t gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.cphase` | Controlled phase gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.cnot` | Controlled not gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.csign` | Same as cphase | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.berkeley` | Berkeley gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.swapalpha` | Swapalpha gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.swap` | Swap the states of two qubits | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.iswap` | Swap gate with additional phase for 01 and 10 states | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.sqrtswap` | Square root of the swap gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.sqrtiswap` | Square root of the iswap gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.fredkin` | Fredkin gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.molmer_sorensen` | Molmer Sorensen gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.toffoli` | Toffoli gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.hadamard_transform` | Hadamard gate | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.qubit_clifford_group` | Generates the Clifford group on a single qubit | ++------------------------------------------------+-------------------------------------------------------+ +| :func:`~qutip.core.gates.globalphase` | Global phase gate | ++------------------------------------------------+-------------------------------------------------------+ + +To load this qutip module, first you have to import gates: + +.. code-block:: Python + + from qutip import gates + +For example to use the Hadamard Gate: + +.. testcode:: [basics] + + H = gates.hadamard_transform() + print(H) + +**Output**: + +.. testoutput:: [basics] + :options: +NORMALIZE_WHITESPACE + + Quantum object: dims=[[2], [2]], shape=(2, 2), type='oper', dtype=Dense, isherm=True + Qobj data = + [[ 0.70710678 0.70710678] + [0.70710678 -0.70710678]] + .. _states-expect: Expectation values @@ -788,6 +883,7 @@ as well as the composite objects discussed in the next section :ref:`tensor`: np.testing.assert_almost_equal(expect(sz2, two_spins), -1) + .. _states-super: Superoperators and Vectorized Operators