Skip to content

Commit e17fa5c

Browse files
authored
Merge pull request #15 from SpM-lab/fix/author-issues-py
Fix the Python notebooks reported in the author issues
2 parents a84ceb2 + 0259cea commit e17fa5c

8 files changed

Lines changed: 24 additions & 21 deletions

‎pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies = [
77
"matplotlib",
88
"ghp-import",
99
"jupyterlab",
10-
"sparse-ir>=2.0.0a9",
10+
"sparse-ir>=2.1.5",
1111
"admmsolver",
12-
"pylibsparseir>=0.7.5",
12+
"pylibsparseir>=0.10.0",
1313
]

‎src/FLEX_py.ipynb‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,15 @@
194194
"\n",
195195
" \n",
196196
" def k_to_r(self,obj_k):\n",
197-
" \"\"\" Fourier transform from k-space to real space \"\"\"\n",
197+
" \"\"\" Fourier transform from k-space to real space, A(r) = sum_k exp(-ik.r) A(k), without a factor 1/nk \"\"\"\n",
198198
" obj_k = obj_k.reshape(-1, self.nk1, self.nk2)\n",
199199
" obj_r = np.fft.fftn(obj_k,axes=(1,2))\n",
200200
" obj_r = obj_r.reshape(-1, self.nk)\n",
201201
" return obj_r\n",
202202
"\n",
203203
" def r_to_k(self,obj_r):\n",
204-
" \"\"\" Fourier transform from real space to k-space \"\"\"\n",
204+
" \"\"\" Fourier transform from real space to k-space, A(k) = (1/nk^2) sum_r exp(ik.r) A(r) (1/nk from ifftn and 1/nk here),\n",
205+
" so that the product of two k_to_r arrays A(r)B(r) gives the convolution (1/nk) sum_q A(q)B(k-q) \"\"\"\n",
205206
" obj_r = obj_r.reshape(-1, self.nk1, self.nk2)\n",
206207
" obj_k = np.fft.ifftn(obj_r,axes=(1,2))/self.nk\n",
207208
" obj_k = obj_k.reshape(-1, self.nk)\n",

‎src/GW_py.ipynb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"cell_type": "markdown",
9494
"metadata": {},
9595
"source": [
96-
"Above we have successfully derived $G^\\mathrm{F}(\\bar{\\tau}_k^\\mathrm{F})$ from $G^\\mathrm{F}(\\mathrm{i}\\bar{\\nu}_k^\\mathrm{F})$ by first obtaining the Green's function's basis representation $G_l^\\mathrm{F}$ and secondly evaluating $G_l^\\mathrm{F}$ on the $\\tau$-sampling points, which are given by the computations of sparse_ir. Throughout, $\\bar{\\tau}_k^\\mathrm{F}$ and $\\mathrm{i}\\bar{\\nu}_k^\\mathrm{F}$ ($\\bar{\\tau}_k^\\mathrm{B}$ and $\\mathrm{i}\\bar{\\nu}_k^\\mathrm{B}$) denote the fermionic (bosonic) sampling points in imaginary time and Matsubara frequency, where $\\nu^\\mathrm{F} = n\\pi/\\beta$ with odd $n$ and $\\nu^\\mathrm{B} = n\\pi/\\beta$ with even $n$. Here, the self-consistent second order Green's function theory (GF2) and the self-consistent GW method are are based this very mechanism (and the so called Hedin equations).[5][7]\n",
96+
"Above, we have computed the non-interacting Green's function $G^\\mathrm{F}(\\mathrm{i}\\bar{\\nu}_k^\\mathrm{F})$ on the Matsubara sampling points. Below, we derive $G^\\mathrm{F}(\\bar{\\tau}_k^\\mathrm{F})$ from $G^\\mathrm{F}(\\mathrm{i}\\bar{\\nu}_k^\\mathrm{F})$ by first obtaining the Green's function's basis representation $G_l^\\mathrm{F}$ and secondly evaluating $G_l^\\mathrm{F}$ on the $\\tau$-sampling points, which are given by the computations of sparse_ir. Throughout, $\\bar{\\tau}_k^\\mathrm{F}$ and $\\mathrm{i}\\bar{\\nu}_k^\\mathrm{F}$ ($\\bar{\\tau}_k^\\mathrm{B}$ and $\\mathrm{i}\\bar{\\nu}_k^\\mathrm{B}$) denote the fermionic (bosonic) sampling points in imaginary time and Matsubara frequency, where $\\nu^\\mathrm{F} = n\\pi/\\beta$ with odd $n$ and $\\nu^\\mathrm{B} = n\\pi/\\beta$ with even $n$. Here, the self-consistent second order Green's function theory (GF2) and the self-consistent GW method are are based this very mechanism (and the so called Hedin equations).[5][7]\n",
9797
"\n",
9898
"The following image should give an overview on their iterative schemes[5]:\n",
9999
"\n",
@@ -394,13 +394,13 @@
394394
"cell_type": "markdown",
395395
"metadata": {},
396396
"source": [
397-
"After changing back into fermionic statistics the next quantity that is being dealt with is the so-called self energy $\\Sigma$. When we first introduced the Dyson equation in the first chapter, we saw $V$ as some sort of pertubation. The self-energy is very much alike as it describes the correlation effects of a many-body system. Here we will calculate $\\tilde{\\Sigma}(\\bar{\\tau}_k^\\mathrm{F})$ using $\\Sigma^{GW}$ so that\n",
397+
"After changing back into fermionic statistics the next quantity that is being dealt with is the so-called self energy $\\Sigma$. It enters the Dyson equation below and describes the correlation effects of a many-body system. Here we will calculate $\\tilde{\\Sigma}(\\bar{\\tau}_k^\\mathrm{F})$ using $\\Sigma^{GW}$ so that\n",
398398
"\n",
399-
"$${\\Sigma}(\\bar{\\tau}_k^\\mathrm{F})=-G(\\bar{\\tau}_k^\\mathrm{F})*{W}(\\bar{\\tau}_k^\\mathrm{F}).$$\n",
399+
"$${\\Sigma}(\\bar{\\tau}_k^\\mathrm{F})=G(\\bar{\\tau}_k^\\mathrm{F})*{W}(\\bar{\\tau}_k^\\mathrm{F}).$$\n",
400400
"\n",
401401
"This can again be rewritten into its equivalent form\n",
402402
"\n",
403-
"$$\\Sigma=-G(U+UP(U+UP(...)))= -(GU+GUPU+GUPUPU+...)$$"
403+
"$$\\Sigma=G(U+UP(U+UP(...)))= GU+GUPU+GUPUPU+...$$"
404404
]
405405
},
406406
{

‎src/TPSC_py.ipynb‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"\n",
5858
"Afterwards we can calculate the double occupancy $\\langle n_{\\uparrow}n_{\\downarrow}\\rangle = \\frac{U_{\\mathrm{sp}}}{4U} n^2$ and then perform a similar root finding for $U_{\\mathrm{ch}}$ from the function \n",
5959
"\n",
60-
"$$ g(U_{\\mathrm{ch}}) = 2 \\frac{T}{N_{\\boldsymbol{k}}} \\sum_{\\nu^\\mathrm{B},\\boldsymbol{q}} \\chi_{\\mathrm{ch}}(U_{\\mathrm{ch}}) - n - 2\\langle n_{\\uparrow}n_{\\downarrow}\\rangle^2 + n^2\\;. $$\n",
60+
"$$ g(U_{\\mathrm{ch}}) = 2 \\frac{T}{N_{\\boldsymbol{k}}} \\sum_{\\nu^\\mathrm{B},\\boldsymbol{q}} \\chi_{\\mathrm{ch}}(U_{\\mathrm{ch}}) - n - 2\\langle n_{\\uparrow}n_{\\downarrow}\\rangle + n^2\\;. $$\n",
6161
"\n",
6262
"In TPSC, a self-energy $\\Sigma$ can be derived that is calculated from the interaction {cite:p}`Moukouri2000`\n",
6363
"\n",
@@ -218,14 +218,15 @@
218218
"\n",
219219
"\n",
220220
" def k_to_r(self,obj_k):\n",
221-
" \"\"\" Fourier transform from k-space to real space \"\"\"\n",
221+
" \"\"\" Fourier transform from k-space to real space, A(r) = sum_k exp(-ik.r) A(k), without a factor 1/nk \"\"\"\n",
222222
" obj_k = obj_k.reshape(-1, self.nk1, self.nk2)\n",
223223
" obj_r = np.fft.fftn(obj_k,axes=(1,2))\n",
224224
" obj_r = obj_r.reshape(-1, self.nk)\n",
225225
" return obj_r\n",
226226
"\n",
227227
" def r_to_k(self,obj_r):\n",
228-
" \"\"\" Fourier transform from real space to k-space \"\"\"\n",
228+
" \"\"\" Fourier transform from real space to k-space, A(k) = (1/nk^2) sum_r exp(ik.r) A(r) (1/nk from ifftn and 1/nk here),\n",
229+
" so that the product of two k_to_r arrays A(r)B(r) gives the convolution (1/nk) sum_q A(q)B(k-q) \"\"\"\n",
229230
" obj_r = obj_r.reshape(-1, self.nk1, self.nk2)\n",
230231
" obj_k = np.fft.ifftn(obj_r,axes=(1,2))/self.nk\n",
231232
" obj_k = obj_k.reshape(-1, self.nk)\n",
@@ -380,7 +381,7 @@
380381
" U_b = 100\n",
381382
"\n",
382383
" chi_trace = self.chi_qtrace_calc\n",
383-
" sfc_eq = lambda U_ch : 2*chi_trace(-U_ch) - self.n + (1 - 2*self.docc)*self.n**2\n",
384+
" sfc_eq = lambda U_ch : 2*chi_trace(-U_ch) - self.n - 2*self.docc + self.n**2\n",
384385
"\n",
385386
" self.U_ch = sc.optimize.brentq(sfc_eq, U_a, U_b, rtol = self.U_sfc_tol)\n",
386387
"\n",

‎src/analytic_continuation_py.ipynb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@
116116
"outputs": [],
117117
"source": [
118118
"def semicirc_dos(w):\n",
119-
" return 2/np.pi * np.sqrt((np.abs(w) < wmax) * (1 - np.square(w/wmax)))\n",
119+
" return 2/(np.pi*wmax) * np.sqrt((np.abs(w) < wmax) * (1 - np.square(w/wmax)))\n",
120120
"\n",
121121
"def insulator_dos(w):\n",
122-
" return semicirc_dos(8*w/wmax - 4) + semicirc_dos(8*w/wmax + 4)\n",
122+
" return 4/wmax * (semicirc_dos(8*w/wmax - 4) + semicirc_dos(8*w/wmax + 4))\n",
123123
"\n",
124124
"# For testing, compute exact coefficients g_l for two models\n",
125125
"rho1_l = basis.v.overlap(semicirc_dos)\n",
@@ -232,7 +232,7 @@
232232
"As a simple example, let us consider **Ridge regression** in the above problem. We again expand the spectral function in the right singular functions with $L'=L$, but include a regularization term:\n",
233233
"\n",
234234
"$$\n",
235-
" f_\\mathrm{reg}[\\rho] = \\alpha \\sum_{l=0}^{L-1} | \\rho_l |^2,\n",
235+
" f_\\mathrm{reg}[\\rho] = \\alpha^2 \\sum_{l=0}^{L-1} | \\rho_l |^2,\n",
236236
"$$\n",
237237
"\n",
238238
"where $\\alpha$ is a hyperparameter (ideally tuned to the noise level). This term prevents $\\rho_l$ becoming too large due to noise amplification. The regularized least squares problem (2) then amounts to:\n",

‎src/eliashberg_holstein_py.ipynb‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,13 @@
399399
},
400400
"outputs": [],
401401
"source": [
402-
"def add_noise(arr, noise):\n",
402+
"def add_noise(arr, noise, seed=0):\n",
403403
" \"\"\"\n",
404-
" Add Gaussian noise to an array\n",
404+
" Add Gaussian noise to an array (seeded, so that the results are reproducible)\n",
405405
" \"\"\"\n",
406-
" arr += noise*np.random.randn(*arr.shape)\n",
407-
" arr += noise*1j*np.random.randn(*arr.shape)\n",
406+
" rng = np.random.default_rng(seed)\n",
407+
" arr += noise*rng.standard_normal(arr.shape)\n",
408+
" arr += noise*1j*rng.standard_normal(arr.shape)\n",
408409
" return arr"
409410
]
410411
},

‎src/liechtenstein_py.ipynb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
"outputs": [],
202202
"source": [
203203
"Lambda = 2*max(8*t, b_eff) * beta\n",
204-
"basis = sparse_ir.FiniteTempBasis(statistics='F', beta=beta, wmax=Lambda, eps=1e-7)\n",
204+
"basis = sparse_ir.FiniteTempBasis(statistics='F', beta=beta, wmax=Lambda/beta, eps=1e-7)\n",
205205
"l = liechtenstein(basis, t, beta, nk, b_eff)"
206206
]
207207
},

‎src/second_order_perturbation_py.ipynb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"The corresponding non-interacting Green's function is given by\n",
4242
"\n",
4343
"$$\n",
44-
" G(\\mathrm{i}\\nu, \\boldsymbol{k}) = \\frac{1}{\\mathrm{i}\\nu - \\epsilon(\\boldsymbol{k}) - \\mu},\n",
44+
" G(\\mathrm{i}\\nu, \\boldsymbol{k}) = \\frac{1}{\\mathrm{i}\\nu - \\epsilon(\\boldsymbol{k}) + \\mu},\n",
4545
"$$\n",
4646
"\n",
4747
"where $\\nu = n\\pi/\\beta$ with odd $n$ is a fermionic Matsubara frequency.\n",

0 commit comments

Comments
 (0)