.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/BoseHubbard_1d_groundstate.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_BoseHubbard_1d_groundstate.py: Ground state simulation of the Bose-Hubbard model. ================================================== .. GENERATED FROM PYTHON SOURCE LINES 16-98 .. code-block:: Python # pylint: disable=invalid-name import numpy as np import qtealeaves as qtl from qtealeaves.models import get_bose_hubbard_1d # Reference ground state energies from OSMPS # Keys are ... L, J, symmetry_sector ref_osmps = { (8, 0.5, None): -4.7358608335175, (8, 0.5, 8): -4.66662145271015, (8, 0.5, 7): -4.4656708344888, } def main(tn_type=5, statics_method=2, output_folder=None): """ Main method for the ground state calculation fo the 1d Bose-Hubbard model. **Arguments** tn_type : int, optional Choose 5 for python-TTN, 6 for python-MPS. Default to 5. statics_method : integer, optional Method to run ground state search for this/all iteration. 0 : default (2) 1 : sweep 2 : sweep with space expansion (can still be reduced to sweep during the simulation based on a energy condition) output_folder : str | None, optional Output folder. Default to None. """ if output_folder is None: output_folder = lambda params: "BOHU_L%d" % (params["L"]) model, my_ops = get_bose_hubbard_1d() my_conv = qtl.convergence_parameters.TNConvergenceParameters( max_iter=7, max_bond_dimension=16, statics_method=statics_method ) my_obs = qtl.observables.TNObservables() 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": 8, "U": 1.0, "J": 0.5}) simulation.run(params, delete_existing_folder=True) for elem in params: e0_tn = simulation.get_static_obs(elem)["energy"] e0_osmps = ref_osmps[(elem["L"], elem["J"], None)] print("Energies TTN vs OSMPS", e0_tn, e0_osmps) assert np.abs(e0_tn - e0_osmps) < 1e-4 print( f"\nExample `{__file__}` ran successfully; " + "ground state energy at least correct up to 1e-4." ) return if __name__ == "__main__": main() .. _sphx_glr_download_auto_examples_BoseHubbard_1d_groundstate.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: BoseHubbard_1d_groundstate.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: BoseHubbard_1d_groundstate.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: BoseHubbard_1d_groundstate.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_