
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/BoseHubbard_2d_quench.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_BoseHubbard_2d_quench.py>`
        to download the full example code.

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

.. _sphx_glr_auto_examples_BoseHubbard_2d_quench.py:


Ground state simulation and quench of the Bose-Hubbard model in 2D.
===================================================================

.. GENERATED FROM PYTHON SOURCE LINES 16-90

.. code-block:: Python


    # pylint: disable=invalid-name

    import qtealeaves as qtl
    from qtealeaves.models import get_bose_hubbard_2d


    def main(tn_type=5, output_folder=None, timesteps=160):
        """
        Main method for the dynamics of the Bose-Hubbard model in 2d.

        **Arguments**

        tn_type : int, optional
            Choose 5 for python-TTN, 6 for python-MPS.
            Default to 5.

        output_folder : str | None, optional
            Output folder. Default to None.

        timesteps : int, optional
            NUmber of timesteps. Default to 160.
        """
        if output_folder is None:
            output_folder = lambda params: "BOHU_L%d" % (params["L"])

        model, my_ops = get_bose_hubbard_2d()

        my_conv = qtl.convergence_parameters.TNConvergenceParameters(
            max_iter=7, max_bond_dimension=16
        )
        my_obs = qtl.observables.TNObservables()

        # Dynamics
        quench = qtl.DynamicsQuench([0.05] * timesteps, time_evolution_mode=2)
        quench["J"] = lambda tt, params: params["J"] * (1 - tt / 8.0)

        simulation = qtl.QuantumGreenTeaSimulation(
            model,
            my_ops,
            my_conv,
            my_obs,
            tn_type=tn_type,
            folder_name_output=output_folder,
            has_log_file=False,
            store_checkpoints=False,
        )

        params = []

        params.append(
            {
                "L": 4,
                "U": 1.0,
                "J": 4.0,
                "Quenches": [quench],
                "exclude_from_hash": ["Quenches"],
            }
        )

        simulation.run(params, delete_existing_folder=True)

        for elem in params:
            e0_tn = simulation.get_static_obs(elem)["energy"]

            print("Energies ground state TTN", e0_tn)

        print(f"\nExample `{__file__}` ran successfully; no asserts implemented.")

        return


    if __name__ == "__main__":
        main()


.. _sphx_glr_download_auto_examples_BoseHubbard_2d_quench.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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