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

add charge density wave order parameter to example file

parent 1761957a
No related branches found
No related tags found
1 merge request!7Examples
Pipeline #178904 passed
This commit is part of merge request !7. Comments created here will be created in the context of that merge request.
...@@ -26,7 +26,9 @@ import numpy as np ...@@ -26,7 +26,9 @@ import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import pymf.model as model import pymf.model as model
import pymf.solvers as solvers import pymf.solvers as solvers
import pymf.mf as mf
import pymf.tb as tb import pymf.tb as tb
import pymf.observables as observables
import pymf.kwant_helper.kwant_examples as kwant_examples import pymf.kwant_helper.kwant_examples as kwant_examples
import pymf.kwant_helper.utils as kwant_utils import pymf.kwant_helper.utils as kwant_utils
``` ```
...@@ -52,21 +54,124 @@ U=1 ...@@ -52,21 +54,124 @@ U=1
V=0.1 V=0.1
params = dict(U=U, V=V) params = dict(U=U, V=V)
h_int = kwant_utils.builder_to_tb(int_builder, params) h_int = kwant_utils.builder_to_tb(int_builder, params)
model = model.Model(h_0, h_int, filling=2) _model = model.Model(h_0, h_int, filling=2)
``` ```
To start the meanfield calculation we also need a starting guess. We will use our random guess generator for this. It creates a random Hermitian hopping dictionary based on the hopping keys provided and the number of degrees of freedom specified. As we don't expect the mean-field solution to contain terms more than the hoppings from the interacting part, we can use the hopping keys from the interacting part. We will use the same number of degrees as freedom as both the non-interacting and interacting part, so that they match. To start the meanfield calculation we also need a starting guess. We will use our random guess generator for this. It creates a random Hermitian hopping dictionary based on the hopping keys provided and the number of degrees of freedom specified. As we don't expect the mean-field solution to contain terms more than the hoppings from the interacting part, we can use the hopping keys from the interacting part. We will use the same number of degrees as freedom as both the non-interacting and interacting part, so that they match.
```{code-cell} ipython3 ```{code-cell} ipython3
guess = tb.utils.generate_guess(frozenset(h_int), len(list(h_0.values())[0])) guess = tb.utils.generate_guess(frozenset(h_int), len(list(h_0.values())[0]))
mf_sol = solvers.solver(model, guess, nk=18) mf_sol = solvers.solver(_model, guess, nk=18, optimizer_kwargs={'M':0})
full_sol = tb.tb.add_tb(h_0, mf_sol) full_sol = tb.tb.add_tb(h_0, mf_sol)
``` ```
After we have defined the guess, we feed it together with the model into the meanfield solver. The meanfield solver will return a hopping dictionary with the meanfield approximation. We can then add this solution to the non-interacting part to get the full solution. In order to get the solution, we specified the number of k-points to be used in the calculation. This refers to the k-grid used in the Brillouin zone for the density matrix. After we have defined the guess, we feed it together with the model into the meanfield solver. The meanfield solver will return a hopping dictionary with the meanfield approximation. We can then add this solution to the non-interacting part to get the full solution. In order to get the solution, we specified the number of k-points to be used in the calculation. This refers to the k-grid used in the Brillouin zone for the density matrix.
## Creating a phase diagram ## Creating a phase diagram of the gap
We can now create a phase diagram of the gap of the interacting solution. We will use the same hopping dictionary for the non-interacting part as before. We will vary the onsite Hubbard interactio $U$ strength from $0$ to $2$ and the nearest neighbor interaction strength $V$ from $0$ to $1.5$. We can now create a phase diagram of the gap of the interacting solution. In order to calculate the gap we first create a function which takes a hopping dictionary and a Fermi energy and returns the indirect gap. The gap is defined as the difference between the highest occupied and the lowest unoccupied energy level. We will use a dense k-grid to calculate the gap. In order to obtain the Hamiltonian on a dense k-grid, we use the `tb_to_khamvector` function from the `transforms` module.
```{code-cell} ipython3 ```{code-cell} ipython3
def compute_gap(h, fermi_energy=0, nk=100):
kham = tb.transforms.tb_to_khamvector(h, nk, ks=None)
vals = np.linalg.eigvalsh(kham)
emax = np.max(vals[vals <= fermi_energy])
emin = np.min(vals[vals > fermi_energy])
return np.abs(emin - emax)
```
Now that we can calculate the gap, we create a phase diagram of the gap as a function of the Hubbard interaction strength $U$ and the nearest neighbor interaction strength $V$. We vary the onsite Hubbard interactio $U$ strength from $0$ to $2$ and the nearest neighbor interaction strength $V$ from $0$ to $1.5$.
```{code-cell} ipython3
def compute_phase_diagram(Us, Vs, int_builder, h_0):
gap = []
mf_sols = []
for U in Us:
gap_U = []
mf_sols_U = []
for V in Vs:
params = dict(U=U, V=V)
h_int = kwant_utils.builder_to_tb(int_builder, params)
_model = model.Model(h_0, h_int, filling=2)
converged=False
while not converged:
guess = tb.utils.generate_guess(frozenset(h_int), len(list(h_0.values())[0]))
try:
mf_sol = solvers.solver(_model, guess, nk=18, optimizer_kwargs={'M':0})
converged=True
except:
converged=False
gap_U.append(compute_gap(tb.tb.add_tb(h_0, mf_sol), fermi_energy=0, nk=300))
mf_sols_U.append(mf_sol)
guess = None
gap.append(gap_U)
mf_sols.append(mf_sols_U)
return np.asarray(gap, dtype=float), np.asarray(mf_sols)
```
We chose to initialize a new guess for each $U$ value, but not for each $V$ value. Instead, for consecutive $V$ values we use the previous mean-field solution as a guess. We do this because the mean-field solution is expected to be smooth in the interaction strength and therefore by using an inspired guess we can speed up the calculation.
We can now compute the phase diagram and plot it.
```{code-cell} ipython3
Us = np.linspace(0, 4, 5)
Vs = np.linspace(0, 1.5, 5)
gap, mf_sols = compute_phase_diagram(Us, Vs, int_builder, h_0)
plt.imshow(gap.T, extent=(Us[0], Us[-1], Vs[0], Vs[-1]), origin='lower', aspect='auto')
plt.colorbar()
plt.xlabel('V')
plt.ylabel('U')
plt.title('Gap')
plt.show()
```
This phase diagram has gap openings at the same places as shown in the [literature](https://arxiv.org/abs/1204.4531).
## Order parameters
We might also want to calculate order parameters of the mean field solution. From literature we know to expect a charge density wave (CDW) and a spin density wave (SDW) in the mean field solution in different regions of the phase diagram. Here we show how to create both the CDW and SDW order parameters and evaluate them for the mean field solution in the phase diagram.
### Charge density wave
We first start with the CDW order parameter. In CDW the spins on different sublattices have opposite signs. This means that our order parameter can be constructed as:
```{code-cell} ipython3
sz = np.array([[1, 0], [0, -1]])
cdw_order_parameter = {}
cdw_order_parameter[(0,0)] = np.kron(sz, np.eye(2))
```
We choose a point in the phase diagram where we expect there to be a CDW phase and calculate the expectation value with the CDW order parameter. In order to do this we first construct the density matrix from the mean field solution.
```{code-cell} ipython3
params = dict(U=0, V=2)
h_int = kwant_utils.builder_to_tb(int_builder, params)
_model = model.Model(h_0, h_int, filling=2)
guess = tb.utils.generate_guess(frozenset(h_int), len(list(h_0.values())[0]))
mf_sol = solvers.solver(_model, guess, nk=18, optimizer_kwargs={'M':0})
full_sol = tb.tb.add_tb(h_0, mf_sol)
rho, _ = mf.construct_density_matrix(full_sol, filling=2, nk=40)
expectation_value = observables.expectation_value(rho, cdw_order_parameter)
print(expectation_value)
```
We can also perform the same calculation over the complete phase diagram where we calculated the gap earlier:
```{code-cell} ipython3
expectation_value_list = []
for mf_sol in mf_sols.flatten():
rho, _ = mf.construct_density_matrix(tb.tb.add_tb(h_0, mf_sol), filling=2, nk=40)
expectation_value = observables.expectation_value(rho, cdw_order_parameter)
expectation_value_list.append(expectation_value)
```
```{code-cell} ipython3
expectation_value_list = np.asarray(expectation_value_list).reshape(mf_sols.shape)
plt.imshow(np.abs(expectation_value_list.T.real), extent=(Us[0], Us[-1], Vs[0], Vs[-1]), origin='lower', aspect='auto')
plt.colorbar()
plt.xlabel('V')
plt.ylabel('U')
plt.title('Charge Density Wave Order Parameter')
plt.show()
```
%% Cell type:code id:cb509096-42c6-4a45-8dc4-a8eed3116e67 tags: %% Cell type:code id:cb509096-42c6-4a45-8dc4-a8eed3116e67 tags:
``` python ``` python
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from codes.model import Model import numpy as np
from codes.solvers import solver import matplotlib.pyplot as plt
from codes import kwant_examples import pymf.model as model
from codes.kwant_helper import utils as kwant_utils import pymf.solvers as solvers
from codes.tb.tb import add_tb import pymf.mf as mf
from codes.tb import utils import pymf.tb as tb
from tqdm import tqdm import pymf.observables as observables
import xarray as xr import pymf.kwant_helper.kwant_examples as kwant_examples
import pymf.kwant_helper.utils as kwant_utils
``` ```
%% Output
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
%% Cell type:code id:99f0e60c tags: %% Cell type:code id:99f0e60c tags:
``` python ``` python
# Create translationally-invariant `kwant.Builder`
graphene_builder, int_builder = kwant_examples.graphene_extended_hubbard() graphene_builder, int_builder = kwant_examples.graphene_extended_hubbard()
h_0 = kwant_utils.builder_to_tb(graphene_builder) h_0 = kwant_utils.builder_to_tb(graphene_builder)
``` ```
%% Cell type:code id:9189a20f tags:
``` python
U=4
V=0
params = dict(U=U, V=V)
h_int = kwant_utils.builder_to_tb(int_builder, params)
_model = model.Model(h_0, h_int, filling=2)
guess = tb.utils.generate_guess(frozenset(h_int), len(list(h_0.values())[0]))
mf_sol = solvers.solver(_model, guess, nk=18, optimizer_kwargs={'M':0})
full_sol = tb.tb.add_tb(h_0, mf_sol)
```
%% Cell type:code id:9d6ce961 tags:
``` python
sx = np.array([[0, 1], [1, 0]])
sy = np.array([[0, -1j], [1j, 0]])
sz = np.array([[1, 0], [0, -1]])
s_list = [sx, sy, sz]
rho, _ = mf.construct_density_matrix(full_sol, filling=2, nk=40)
order_parameter_list = []
for s in s_list:
order_parameter = {}
order_parameter[(0,0)] = np.kron(sz, s)
order_parameter_list.append(order_parameter)
expectation_value_list = []
for order_parameter in order_parameter_list:
expectation_value = observables.expectation_value(rho, order_parameter)
expectation_value_list.append(expectation_value)
```
%% Cell type:code id:d77b4bea tags:
``` python
np.sum(np.array(expectation_value_list)**2)
```
%% Output %% Output
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. (1.804655008699922+0j)
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. %% Cell type:code id:10dfae00 tags:
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. ``` python
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. #antiferromagnetic order parameter
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. anti_order_parameter = {}
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. anti_order_parameter[(0,0)] = np.kron(sz, sz)
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. expectation_value = observables.expectation_value(rho, anti_order_parameter)
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. ```
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. %% Cell type:code id:7d3394a1 tags:
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. ``` python
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. ```
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. %% Cell type:code id:260bd7c1 tags:
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. ``` python
cdw_order_parameter = {}
cdw_order_parameter[(0,0)] = np.kron(sz, np.eye(2))
sdw_order_parameter = {}
sdw_order_parameter[(0,0)] = np.kron(np.eye(2), sz)
```
%% Cell type:code id:345644dc tags:
``` python
expectation_value = observables.expectation_value(rho, cdw_order_parameter)
```
%% Cell type:code id:fe4b9564 tags:
``` python
expectation_value
```
%% Output
(-1.5833996732759665+0j)
%% Cell type:code id:83e823ed tags:
``` python
h_0
```
%% Output
{(0,
0): array([[0., 0., 1., 0.],
[0., 0., 0., 1.],
[1., 0., 0., 0.],
[0., 1., 0., 0.]]),
(0,
-1): array([[0., 0., 1., 0.],
[0., 0., 0., 1.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]]),
(0,
1): array([[0., 0., 0., 0.],
[0., 0., 0., 0.],
[1., 0., 0., 0.],
[0., 1., 0., 0.]]),
(1,
-1): array([[0., 0., 1., 0.],
[0., 0., 0., 1.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]]),
(-1,
1): array([[0., 0., 0., 0.],
[0., 0., 0., 0.],
[1., 0., 0., 0.],
[0., 1., 0., 0.]])}
%% Cell type:code id:e1894ac3 tags:
``` python
def compute_gap(h, fermi_energy=0, nk=100):
kham = tb.transforms.tb_to_khamvector(h, nk, ks=None)
vals = np.linalg.eigvalsh(kham)
emax = np.max(vals[vals <= fermi_energy])
emin = np.min(vals[vals > fermi_energy])
return np.abs(emin - emax)
```
%% Cell type:code id:f4d1bb07 tags: %% Cell type:code id:d0092977 tags:
``` python ``` python
np.random.seed(5)
def compute_phase_diagram(Us, Vs, int_builder, h_0): def compute_phase_diagram(Us, Vs, int_builder, h_0):
gap = [] gap = []
for U in tqdm(Us): for U in Us:
gap_U = [] for V in Vs:
guess=None params = dict(U=U, V=V)
for V in Vs: h_int = kwant_utils.builder_to_tb(int_builder, params)
params = dict(U=U, V=V) _model = model.Model(h_0, h_int, filling=2)
h_int = kwant_utils.builder_to_tb(int_builder, params)
if guess==None: converged=False
guess = utils.generate_guess(frozenset(h_int), len(list(h_0.values())[0])) while not converged:
model = Model(h_0, h_int, filling=2) guess = tb.utils.generate_guess(frozenset(h_int), len(list(h_0.values())[0]))
try:
mf_sol = solver(model, guess, nk=18) mf_sol = solvers.solver(_model, guess, nk=18, optimizer_kwargs={'M':0})
gap_U.append(utils.compute_gap(add_tb(h_0, mf_sol), fermi_energy=0, nk=300)) converged=True
guess = None except:
gap.append(gap_U) converged=False
return np.asarray(gap, dtype=float) gap.append(compute_gap(tb.tb.add_tb(h_0, mf_sol), fermi_energy=0, nk=300))
guess = None
return np.asarray(gap, dtype=float).reshape(len(Us), len(Vs))
``` ```
%% Cell type:code id:14f332f2 tags: %% Cell type:code id:14f332f2 tags:
``` python ``` python
Us = np.linspace(0, 3, 10, endpoint=True) Us = np.linspace(0, 3, 10, endpoint=True)
Vs = np.linspace(0, 1.5, 10, endpoint=True) Vs = np.linspace(0, 1.5, 10, endpoint=True)
gap = compute_phase_diagram(Us, Vs, int_builder, h_0) gap = compute_phase_diagram(Us, Vs, int_builder, h_0)
``` ```
%% Output %% Output
100%|██████████| 10/10 [07:09<00:00, 43.00s/it] 100%|██████████| 10/10 [07:09<00:00, 43.00s/it]
%% Cell type:code id:0d2ad9d8 tags: %% Cell type:code id:0d2ad9d8 tags:
``` python ``` python
gap_da = xr.DataArray(data=gap, coords=dict(Us=Us, Vs=Vs)) gap_da = xr.DataArray(data=gap, coords=dict(Us=Us, Vs=Vs))
gap_da.plot(x="Us", y="Vs", vmin=0, vmax=1) gap_da.plot(x="Us", y="Vs", vmin=0, vmax=1)
``` ```
%% Output %% Output
<matplotlib.collections.QuadMesh at 0x14de67c10> <matplotlib.collections.QuadMesh at 0x14de67c10>
%% Cell type:code id:a661ac28 tags: %% Cell type:code id:a661ac28 tags:
``` python ``` python
np.log10(gap_da).plot(x="Us", y="Vs", vmin=-3, vmax=1) np.log10(gap_da).plot(x="Us", y="Vs", vmin=-3, vmax=1)
``` ```
%% Output %% Output
<matplotlib.collections.QuadMesh at 0x14deef590> <matplotlib.collections.QuadMesh at 0x14deef590>
%% Cell type:code id:18191ba0 tags: %% Cell type:code id:18191ba0 tags:
``` python ``` python
#Single shot calculation #Single shot calculation
params = dict(U=0, V=1) params = dict(U=0, V=1)
filling = 2 filling = 2
h_int = utils.builder_to_tb(int_builder, params) h_int = utils.builder_to_tb(int_builder, params)
model = Model(h_0, h_int, filling) model = Model(h_0, h_int, filling)
mf_guess = utils.generate_guess(frozenset(h_int), len(list(h_0.values())[0])) mf_guess = utils.generate_guess(frozenset(h_int), len(list(h_0.values())[0]))
mf_sol = solver(model, mf_guess, nK=30) mf_sol = solver(model, mf_guess, nK=30)
ks = np.linspace(-np.pi, np.pi, 200) ks = np.linspace(-np.pi, np.pi, 200)
hkfunc = tb2kfunc(addTb(h_0, mf_sol)) hkfunc = tb2kfunc(addTb(h_0, mf_sol))
hkarray = np.array([hkfunc((kx, -kx)) for kx in ks]) hkarray = np.array([hkfunc((kx, -kx)) for kx in ks])
vals = np.linalg.eigvalsh(hkarray) vals = np.linalg.eigvalsh(hkarray)
plt.plot(vals) plt.plot(vals)
utils.calc_gap(vals, E_F=0) utils.calc_gap(vals, E_F=0)
``` ```
%% Output %% Output
0.02672641009348376 0.02672641009348376
%% Cell type:code id:e183c3cb tags: %% Cell type:code id:e183c3cb tags:
``` python ``` python
import numpy as np import numpy as np
from codes.model import Model from codes.model import Model
from codes import kwant_examples from codes import kwant_examples
from codes.kwant_helper import utils from codes.kwant_helper import utils
import timeit import timeit
import memray import memray
``` ```
%% Cell type:code id:078dd782 tags: %% Cell type:code id:078dd782 tags:
``` python ``` python
graphene_builder, int_builder = kwant_examples.graphene_extended_hubbard() graphene_builder, int_builder = kwant_examples.graphene_extended_hubbard()
params = {"U": 0.5, "V": 1.1} params = {"U": 0.5, "V": 1.1}
filling = 2 filling = 2
nK = 300 nK = 300
h_int = utils.builder_to_tb(int_builder, params) h_int = utils.builder_to_tb(int_builder, params)
h_0 = utils.builder_to_tb(graphene_builder) h_0 = utils.builder_to_tb(graphene_builder)
guess = utils.generate_guess(frozenset(h_int), len(list(h_0.values())[0])) guess = utils.generate_guess(frozenset(h_int), len(list(h_0.values())[0]))
model = Model(h_0, h_int, filling) model = Model(h_0, h_int, filling)
def scf_loop(): def scf_loop():
model.mfield(guess, nK=nK) model.mfield(guess, nK=nK)
# %% Memory profile # %% Memory profile
with memray.Tracker("memoryProfile.bin"): with memray.Tracker("memoryProfile.bin"):
scf_loop() scf_loop()
``` ```
%% Output %% Output
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
%% Cell type:code id:3455735e tags: %% Cell type:code id:3455735e tags:
``` python ``` python
# %% Time profiler # %% Time profiler
profiler = Profiler() profiler = Profiler()
profiler.start() profiler.start()
scf_loop() scf_loop()
profiler.stop() profiler.stop()
profiler.write_html(path="timeProfile.html") profiler.write_html(path="timeProfile.html")
``` ```
%% Cell type:code id:75fe9023 tags: %% Cell type:code id:75fe9023 tags:
``` python ``` python
# %% # %%
number = 1 number = 1
timeSCF = timeit.timeit(scf_loop, number=number) / number timeSCF = timeit.timeit(scf_loop, number=number) / number
H = np.random.rand(nK, nK) H = np.random.rand(nK, nK)
H += H.T.conj() H += H.T.conj()
timeDiag = timeit.timeit(lambda: np.linalg.eigh(H), number=number) / number timeDiag = timeit.timeit(lambda: np.linalg.eigh(H), number=number) / number
print( print(
f"Single SCF loop takes {timeSCF} whereas a single diagonalization of a corresponding system takes {timeDiag}" f"Single SCF loop takes {timeSCF} whereas a single diagonalization of a corresponding system takes {timeDiag}"
) )
``` ```
%% Output %% Output
Single SCF loop takes 7.120591291008168 whereas a single diagonalization of a corresponding system takes 0.024635875000967644 Single SCF loop takes 7.120591291008168 whereas a single diagonalization of a corresponding system takes 0.024635875000967644
%% Cell type:code id:f650872f tags: %% Cell type:code id:f650872f tags:
``` python ``` python
``` ```
......
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