diff --git a/examples/1d_hubbard.ipynb b/examples/1d_hubbard.ipynb index 79ef0d60d10db5b7ec5377a14ddc702e40e44c31..0fec29d68acd8de67ebb9c3b569ac155adcd3b42 100644 --- a/examples/1d_hubbard.ipynb +++ b/examples/1d_hubbard.ipynb @@ -9,10 +9,9 @@ }, "outputs": [], "source": [ - "import kwant\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", - "from codes import utils, hf, kwant_examples\n", + "from codes import utils, hf\n", "from tqdm import tqdm" ] }, @@ -43,6 +42,7 @@ "tb_model = {\n", " (0,) : hopp + hopp.T.conj(),\n", " (1,) : hopp,\n", + " (-1,) : hopp.T.conj()\n", "}" ] }, @@ -74,8 +74,12 @@ "source": [ "# Set number of k-points\n", "nk = 100\n", + "hk = utils.model2hk(tb_model=tb_model)\n", "# Compute Hamiltonian on the corresponding k-point grid\n", - "hamiltonians_0, ks = utils.kgrid_hamiltonian(nk, tb_model, return_ks=True)\n", + "hamiltonians_0, ks = utils.kgrid_hamiltonian(\n", + " nk=nk, hk=hk, dim=1,\n", + " return_ks=True\n", + ")\n", "# Perform diagonalization\n", "vals, vecs = np.linalg.eigh(hamiltonians_0)\n", "# Plot data\n", @@ -97,34 +101,36 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 4, "id": "41bd9f60-8f29-4e7c-a0c4-a0bbf66445b2", "metadata": {}, "outputs": [], "source": [ "def compute_gap(\n", - " tb_model,\n", - " int_model,\n", + " hk,\n", + " Vk,\n", " nk,\n", " nk_dense,\n", " filling=2\n", "):\n", - " # Generate guess on the same k-point grid\n", - " guess = utils.generate_guess(nk, tb_model, int_model, scale=1)\n", - "\n", " # Find groundstate Hamiltonian on the same grid\n", - " mf_model = hf.find_groundstate_ham(\n", - " int_model=int_model,\n", + " _, mf_model = hf.find_groundstate_ham(\n", + " hk=hk,\n", + " Vk=Vk,\n", " filling=filling,\n", - " tb_model=tb_model,\n", - " guess=guess,\n", + " dim=1,\n", " nk=nk,\n", - " tol=1e-8\n", + " cutoff=1,\n", + " return_model=True\n", " )\n", " # Generate Hamiltonian on a denser k-point grid\n", - " hk = utils.kgrid_hamiltonian(nk_dense, mf_model)\n", + " mf_k = utils.kgrid_hamiltonian(\n", + " nk=nk_dense,\n", + " hk=utils.model2hk(tb_model=mf_model),\n", + " dim=1\n", + " )\n", " # Diagonalize groundstate Hamiltonian\n", - " vals, vecs = np.linalg.eigh(hk)\n", + " vals, _ = np.linalg.eigh(mf_k)\n", " # Extract dense-grid Fermi energy\n", " E_F = utils.get_fermi_energy(vals, filling)\n", " gap = utils.calc_gap(vals, E_F)\n", @@ -150,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 5, "id": "32b9e7c5-db12-44f9-930c-21e5494404b8", "metadata": { "tags": [] @@ -169,9 +175,10 @@ " int_model = {\n", " (0,) : U * np.kron(np.ones((2, 2)), np.eye(2))\n", " }\n", + " Vk = utils.model2hk(tb_model=int_model)\n", " _gap, _vals = compute_gap(\n", - " tb_model=tb_model,\n", - " int_model=int_model,\n", + " hk=hk,\n", + " Vk=Vk,\n", " nk=nk,\n", " nk_dense=nk_dense,\n", " )\n", @@ -182,7 +189,7 @@ }, { "cell_type": "code", - "execution_count": 126, + "execution_count": 6, "id": "6a8c08a9-7e31-420b-b6b4-709abfb26793", "metadata": { "tags": [] @@ -192,7 +199,14 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|██████████| 20/20 [00:31<00:00, 1.60s/it]\n" + " 0%| | 0/20 [00:00<?, ?it/s]" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 20/20 [00:12<00:00, 1.63it/s]\n" ] } ], @@ -205,7 +219,7 @@ }, { "cell_type": "code", - "execution_count": 127, + "execution_count": 7, "id": "e17fc96c-c463-4e1f-8250-c254d761b92a", "metadata": {}, "outputs": [], @@ -231,7 +245,7 @@ }, { "cell_type": "code", - "execution_count": 128, + "execution_count": 8, "id": "868cf368-45a0-465e-b042-6182ff8b6998", "metadata": {}, "outputs": [ @@ -270,7 +284,7 @@ }, { "cell_type": "code", - "execution_count": 129, + "execution_count": 9, "id": "ac2eb725-f3bd-4d5b-a509-85d0d0071958", "metadata": {}, "outputs": [ @@ -301,17 +315,17 @@ }, { "cell_type": "code", - "execution_count": 131, + "execution_count": 10, "id": "5499ea62-cf1b-4a13-8191-ebb73ea38704", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array(1.00352528)" + "array(1.00352529)" ] }, - "execution_count": 131, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -322,7 +336,7 @@ }, { "cell_type": "code", - "execution_count": 132, + "execution_count": 11, "id": "0cb395cd-84d1-49b4-89dd-da7a2d09c8d0", "metadata": {}, "outputs": [], @@ -347,7 +361,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.11.6" }, "widgets": { "application/vnd.jupyter.widget-state+json": { diff --git a/examples/data/1d_hubbard_example.nc b/examples/data/1d_hubbard_example.nc index 7ea1d4f36266ed22a7b8a12472c15f3f9b41c02b..c973f6b2aaaf2a6d41d0438192854bac87ec2b2b 100644 Binary files a/examples/data/1d_hubbard_example.nc and b/examples/data/1d_hubbard_example.nc differ