{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Impurity Solver Tutorial\n", "\n", "This tutorial goes through using the Hartree-Fock ImpuritySolver for a simple one band case. We start by importing the required modules:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Warning: could not identify MPI environment!\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Starting serial run at: 2026-06-12 18:12:27.493677\n" ] } ], "source": [ "import numpy as np\n", "from triqs.gfs import *\n", "from triqs.mesh import MeshImFreq\n", "from triqs.operators import *\n", "from h5 import HDFArchive\n", "from triqs_hartree_fock import ImpuritySolver\n", "from triqs.plot.mpl_interface import oplot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next we define G0, h_int, and the parameters that we will pass to the solver" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "beta = 40\n", "n_iw = 1025\n", "\n", "iw_mesh = MeshImFreq(beta=beta, statistic='Fermion', n_iw=n_iw)\n", "g0 = Gf(mesh=iw_mesh, target_shape=[1,1])\n", "g0 << inverse(iOmega_n + 2)\n", "G0 = BlockGf(name_list=['up', 'down'], block_list=[g0, g0], make_copies=True)\n", "\n", "h_int = 3*n('up', 0)*n('down', 0)\n", "\n", "gf_struct = [('up', 1), ('down', 1)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we are ready to initialize the solver:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "S = ImpuritySolver(gf_struct=gf_struct, mesh=iw_mesh)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next we pass G0 to the solver:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Green Function G composed of 2 blocks: \n", " Green's Function G_up with mesh Imaginary frequency mesh with beta = 40, statistics = Fermion, N_iw = 1025, positive_only = false and target_shape (1, 1): \n", " \n", " Green's Function G_down with mesh Imaginary frequency mesh with beta = 40, statistics = Fermion, N_iw = 1025, positive_only = false and target_shape (1, 1): \n", " " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S.G0_iw << G0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, we are ready to call the solve method. By default with_fock is True but can be turned to False to only include Hartree terms." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "╔╦╗╦═╗╦╔═╗ ╔═╗ ┬ ┬┌─┐\n", " ║ ╠╦╝║║═╬╗╚═╗ ├─┤├┤\n", " ╩ ╩╚═╩╚═╝╚╚═╝ ┴ ┴└\n", "TRIQS: Hartree-Fock solver\n", "\n", "Running Impurity Solver\n", "beta = 40.0000\n", "h_int =\n", "3*c_dag('down',0)*c_dag('up',0)*c('up',0)*c('down',0)\n", "HARTREE SOLVER: starting solver in one-shot mode\n", "Including Fock terms:\n", "True\n", "HARTREE SOLVER: Sigma_HF before iterating['up']:\n", "[[0.+0.j]]\n", "HARTREE SOLVER: Sigma_HF before iterating['down']:\n", "[[0.+0.j]]\n", "\n", "HARTREE SOLVER: fixing dc to 0.0000\n", "\n", "HARTREE SOLVER: fixing dc to 0.0000\n", "HARTREE SOLVER: Sigma_HF['up']:\n", "[[3.-0.j]]\n", "HARTREE SOLVER: Sigma_HF['down']:\n", "[[3.-0.j]]\n", "Final G_dens['up']:\n", "[[-0.-0.j]]\n", "Final G_dens['down']:\n", "[[-0.-0.j]]\n" ] } ], "source": [ "S.solve(h_int=h_int, with_fock=True)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 4 }