
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/build/qip/plot_qip_relaxation.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_gallery_build_qip_plot_qip_relaxation.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_build_qip_plot_qip_relaxation.py:


T2 Relaxation
=============

Simulating the T2 relaxation of a single qubit with :class:`qutip.qip.device.Processor`. The single qubit is driven by a rotation around z axis. We measure the population of the plus state as a function of time to see the Ramsey signal.

.. GENERATED FROM PYTHON SOURCE LINES 7-37



.. image-sg:: /gallery/build/qip/images/sphx_glr_plot_qip_relaxation_001.png
   :alt: Relaxation T2=5
   :srcset: /gallery/build/qip/images/sphx_glr_plot_qip_relaxation_001.png
   :class: sphx-glr-single-img





.. code-block:: default

    import numpy as np
    import matplotlib.pyplot as plt
    from qutip.qip.device import Processor
    from qutip.operators import sigmaz, destroy
    from qutip.qip.operations import snot
    from qutip.states import basis

    a = destroy(2)
    Hadamard = snot()
    plus_state = (basis(2,1) + basis(2,0)).unit()
    tlist = np.arange(0.00, 20.2, 0.2)

    T2 = 5
    processor = Processor(1, t2=T2)
    processor.add_control(sigmaz())
    processor.pulses[0].coeff = np.ones(len(tlist))
    processor.pulses[0].tlist = tlist
    result = processor.run_state(
        plus_state, e_ops=[a.dag()*a, Hadamard*a.dag()*a*Hadamard])

    fig, ax = plt.subplots()
    # detail about length of tlist needs to be fixed
    ax.plot(tlist[:-1], result.expect[1][:-1], '.', label="simulation")
    ax.plot(tlist[:-1], np.exp(-1./T2*tlist[:-1])*0.5 + 0.5, label="theory")
    ax.set_xlabel("t")
    ax.set_ylabel("Ramsey signal")
    ax.legend()
    ax.set_title("Relaxation T2=5")
    ax.grid()
    fig.tight_layout()
    fig.show()

.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  0.111 seconds)


.. _sphx_glr_download_gallery_build_qip_plot_qip_relaxation.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: plot_qip_relaxation.py <plot_qip_relaxation.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: plot_qip_relaxation.ipynb <plot_qip_relaxation.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
