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

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_auto_examples_core_plot_RabiOsci_2level.py>`
        to download the full example code.

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

.. _sphx_glr_auto_examples_core_plot_RabiOsci_2level.py:


Simple Rabi oscillations
========================

This tutorial shows how to set up the most basic two-level system and add a laser.

The top-level docstring becomes the intro text.

.. GENERATED FROM PYTHON SOURCE LINES 11-12

importing and initializing the :class:`~MoleCool.System.System` instance

.. GENERATED FROM PYTHON SOURCE LINES 12-22

.. code-block:: Python

    from MoleCool import System, pi, plt
 
    system = System('Rabi-2level') # description string

    system.levels.add_electronicstate('g', 'gs') # ground electronic state
    system.levels.g.add(F=0,mF=0) # add a single level with F=0

    system.levels.add_electronicstate('e', 'exs') # excited electronic state
    system.levels.e.add(F=1,mF=0) # add single mF=0 with F=1 as F=0 would be forbidden





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    System is created with description: Rabi-2level
    /home/docs/checkouts/readthedocs.org/user_builds/molecool-py/checkouts/latest/MoleCool/Levelsystem.py:1573: UserWarning: Gamma must be defined for ElectronicState e! By default, it is now set to 1 MHz!
      warnings.warn(text)




.. GENERATED FROM PYTHON SOURCE LINES 23-25

The output shows a warning that no linewidth Gamma has been defined for the
excited electronic state and thus the default value of 1 MHz is used for now.

.. GENERATED FROM PYTHON SOURCE LINES 27-29

Next, we can set the initial population to be completely in the ground state
and define some quantities.

.. GENERATED FROM PYTHON SOURCE LINES 29-35

.. code-block:: Python

    system.levels.g.set_init_pops({'F=0':1.0}) # initial population

    ratio_OmGa  = 20 # ratio between Rabi frequency and the linewidth
    Omega       = system.levels.calc_Gamma()[0] * ratio_OmGa # Rabi frequency
    T_Om        = 2*pi/Omega # time of one period








.. GENERATED FROM PYTHON SOURCE LINES 36-43

Evaluation and plotting
-----------------------

We now initialize the plot and add laser objects to the system.
To iterate manually between different detunings of the laser, all laser objects
are first reset at each iteration. Then the OBEs are propagated and the
populations are plot against time.

.. GENERATED FROM PYTHON SOURCE LINES 43-60

.. code-block:: Python


    fig = plt.figure(system.description)
    plt.ylim([0,1])
    plt.xlabel('Time $t$ ($2\pi/\Omega$)')
    plt.ylabel('Excited state population $n^e$')

    for det in [0,1,2]:
        del system.lasers[:] # delete laser instances in every iteration
        system.lasers.add(freq_shift = det*Omega/2/pi, freq_Rabi = Omega) # add laser component
        # or alternatively (using intensity instead of directly providing the Rabi freq.):
        # system.lasers.add(freq_shift = det*Omega/2/pi,
                          # I = 2*system.levels.Isat[0,0]*ratio_OmGa**2)
    
        system.calc_OBEs(t_int=5*T_Om, dt=1e-2*T_Om) # calculate dynamics with OBEs
        plt.plot(system.t/T_Om, system.N[1,:], label=str(det))
    
    plt.legend(title='$\Delta/\Omega$',loc='upper right',ncols=3)



.. image-sg:: /auto_examples/core/images/sphx_glr_plot_RabiOsci_2level_001.png
   :alt: plot RabiOsci 2level
   :srcset: /auto_examples/core/images/sphx_glr_plot_RabiOsci_2level_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /home/docs/checkouts/readthedocs.org/user_builds/molecool-py/checkouts/latest/MoleCool/Levelsystem.py:293: UserWarning: There is no dipole matrix or reduced dipole matrix available!So a reduced matrix has been created only with ones:
    exs     e
    F       1
    gs F     
    g  0  1.0
      warnings.warn(warn_txt)
    Solving ode with OBEs...Execution time: 2.2742 seconds
    Scattered Photons (e): 0.782994
    Solving ode with OBEs...Execution time: 0.0036 seconds
    Scattered Photons (e): 0.336916
    Solving ode with OBEs...Execution time: 0.0048 seconds
    Scattered Photons (e): 0.123428

    <matplotlib.legend.Legend object at 0x799fb2c48070>




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

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


.. _sphx_glr_download_auto_examples_core_plot_RabiOsci_2level.py:

.. only:: html

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

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

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

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

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_RabiOsci_2level.zip <plot_RabiOsci_2level.zip>`


.. only:: html

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

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