Skip to content
Snippets Groups Projects
Commit 52f36c5d authored by Johanna Zijderveld's avatar Johanna Zijderveld
Browse files

delete another unused example file

parent eeecb4c7
No related branches found
No related tags found
1 merge request!4Interface refactoring
%% Cell type:code id: tags:
``` python
from codes.tb.transforms import tb2kfunc
from codes.model import Model
import numpy as np
from codes.solvers import solver
```
%% Cell type:code id: tags:
``` python
# 1D
filling = 2
hopp = np.kron(np.array([[0, 1], [0, 0]]), np.eye(2))
h_0 = {(0, ): hopp + hopp.T.conj(), (1,): hopp, (-1,): hopp.T.conj()}
h_int = {
(0,): 4 * np.kron(np.eye(2), np.ones((2, 2))),
}
guess = np.random.rand(4, 4) * np.exp(1j * 2 * np.pi * np.random.rand(4, 4))
guess += guess.T.conj()
guess /= 2
mf_model = {(0,) : guess}
tb = Model(h_0, h_int, filling)
mf_sol = solver(tb, mf_model, nK=100)
```
%% Cell type:code id: tags:
``` python
# 2D
hopp = np.kron(np.array([[0, 1], [0, 0]]), np.eye(2))
h_0 = {(0, 0): hopp + hopp.T.conj(), (1, 0): hopp, (-1, 0 ): hopp.T.conj(), (0, 1): hopp, (0, -1): hopp.T.conj()}
h_int = {
(0, 0): 2 * np.kron(np.eye(2), np.ones((2, 2))),
}
mf_model = {(0, 0) : guess}
tb = Model(h_0, h_int, filling)
mf_sol = solver(tb, mf_model, nK=20) # does not run as fast, something is wrong in 2D
```
%% Output
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
Cell In[16], line 10
8 mf_model = {(0, 0) : guess}
9 tb = Model(h_0, h_int, filling)
---> 10 mf_sol = solver(tb, mf_model, nK=20) # does not converge as fast, something is wrong in 2D
File ~/Projects/kwant-scf/examples/codes/solvers.py:59, in solver(Model, mf_guess, nK, optimizer, optimizer_kwargs)
56 mf_params = mf2rParams(mf_guess)
57 f = partial(cost, Model=Model, nK=nK)
58 result = rParams2mf(
---> 59 optimizer(f, mf_params, **optimizer_kwargs), list(Model.h_int), shape
60 )
61 Model.calculateEF(nK=nK)
62 local_key = tuple(np.zeros((Model._ndim,), dtype=int))
File <string>:6, in anderson(F, xin, iter, alpha, w0, M, verbose, maxiter, f_tol, f_rtol, x_tol, x_rtol, tol_norm, line_search, callback, **kw)
File ~/mambaforge/lib/python3.11/site-packages/scipy/optimize/_nonlin.py:214, in nonlin_solve(F, x0, jacobian, iter, verbose, maxiter, f_tol, f_rtol, x_tol, x_rtol, tol_norm, line_search, callback, full_output, raise_exception)
212 # Line search, or Newton step
213 if line_search:
--> 214 s, x, Fx, Fx_norm_new = _nonlin_line_search(func, x, Fx, dx,
215 line_search)
216 else:
217 s = 1.0
File ~/mambaforge/lib/python3.11/site-packages/scipy/optimize/_nonlin.py:293, in _nonlin_line_search(func, x, Fx, dx, search_type, rdiff, smin)
290 s, phi1, phi0 = scalar_search_wolfe1(phi, derphi, tmp_phi[0],
291 xtol=1e-2, amin=smin)
292 elif search_type == 'armijo':
--> 293 s, phi1 = scalar_search_armijo(phi, tmp_phi[0], -tmp_phi[0],
294 amin=smin)
296 if s is None:
297 # XXX: No suitable step length found. Take the full Newton step,
298 # and hope for the best.
299 s = 1.0
File ~/mambaforge/lib/python3.11/site-packages/scipy/optimize/_linesearch.py:692, in scalar_search_armijo(phi, phi0, derphi0, c1, alpha0, amin)
678 def scalar_search_armijo(phi, phi0, derphi0, c1=1e-4, alpha0=1, amin=0):
679 """Minimize over alpha, the function ``phi(alpha)``.
680
681 Uses the interpolation algorithm (Armijo backtracking) as suggested by
(...)
690
691 """
--> 692 phi_a0 = phi(alpha0)
693 if phi_a0 <= phi0 + c1*alpha0*derphi0:
694 return alpha0, phi_a0
File ~/mambaforge/lib/python3.11/site-packages/scipy/optimize/_nonlin.py:277, in _nonlin_line_search.<locals>.phi(s, store)
275 return tmp_phi[0]
276 xt = x + s*dx
--> 277 v = func(xt)
278 p = _safe_norm(v)**2
279 if store:
File ~/mambaforge/lib/python3.11/site-packages/scipy/optimize/_nonlin.py:168, in nonlin_solve.<locals>.func(z)
167 def func(z):
--> 168 return _as_inexact(F(_array_like(z, x0))).flatten()
File ~/Projects/kwant-scf/examples/codes/solvers.py:25, in cost(mf_param, Model, nK)
23 shape = Model._size
24 mf_tb = rParams2mf(mf_param, list(Model.h_int), shape)
---> 25 mf_tb_new = Model.mfieldFFT(mf_tb, nK=nK)
26 mf_params_new = mf2rParams(mf_tb_new)
27 return mf_params_new - mf_param
File ~/Projects/kwant-scf/examples/codes/model.py:34, in Model.mfieldFFT(self, mf_model, nK)
33 def mfieldFFT(self, mf_model, nK=200):
---> 34 self.density_matrix = self.makedensity_matrix(mf_model)
35 return addTb(
36 meanFieldFFT(self.density_matrix, self.h_int, n=self._ndim, nK=nK),
37 {self._local_key: -self.EF * np.eye(self._size)},
38 )
File ~/Projects/kwant-scf/examples/codes/model.py:20, in Model.makedensity_matrix(self, mf_model, nK)
18 def makedensity_matrix(self, mf_model, nK=200):
19 self.hkfunc = tb2kfunc(addTb(self.h_0, mf_model))
---> 20 self.calculateEF(nK=nK)
21 return density_matrixGenerator(self.hkfunc, self.EF)
File ~/Projects/kwant-scf/examples/codes/model.py:24, in Model.calculateEF(self, nK)
23 def calculateEF(self, nK=200):
---> 24 self.EF = fermi_on_grid(self.hkfunc, self.filling, nK=nK, ndim=self._ndim)
File ~/Projects/kwant-scf/examples/codes/mf.py:54, in fermi_on_grid(hkfunc, filling, nK, ndim)
52 hkarray = np.array([hkfunc(k) for k in ks])
53 if ndim == 2:
---> 54 hkarray = np.array([[hkfunc((kx, ky)) for kx in ks] for ky in ks])
55 elif ndim > 2:
56 raise NotImplementedError("Fermi energy calculation is not implemented for ndim > 2")
File ~/Projects/kwant-scf/examples/codes/mf.py:54, in <listcomp>(.0)
52 hkarray = np.array([hkfunc(k) for k in ks])
53 if ndim == 2:
---> 54 hkarray = np.array([[hkfunc((kx, ky)) for kx in ks] for ky in ks])
55 elif ndim > 2:
56 raise NotImplementedError("Fermi energy calculation is not implemented for ndim > 2")
File ~/Projects/kwant-scf/examples/codes/mf.py:54, in <listcomp>(.0)
52 hkarray = np.array([hkfunc(k) for k in ks])
53 if ndim == 2:
---> 54 hkarray = np.array([[hkfunc((kx, ky)) for kx in ks] for ky in ks])
55 elif ndim > 2:
56 raise NotImplementedError("Fermi energy calculation is not implemented for ndim > 2")
File ~/Projects/kwant-scf/examples/codes/tb/transforms.py:24, in tb2kfunc.<locals>.bloch_ham(k)
22 ham = 0
23 for vector in h_0.keys():
---> 24 ham += h_0[vector] * np.exp(
25 -1j * np.dot(k, np.array(vector, dtype=float))
26 )
27 return ham
KeyboardInterrupt:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment