Skip to content
Snippets Groups Projects
Commit e5edbefd authored by Kostas Vilkelis's avatar Kostas Vilkelis :flamingo:
Browse files

make tb type hidden; rm redundant ks type; adjust import order

parent fbaee62f
No related branches found
No related tags found
1 merge request!6Documentation
......@@ -2,18 +2,19 @@ import inspect
from copy import copy
from itertools import product
from typing import Callable
from pymf.tb.tb import tb_type
import numpy as np
from scipy.sparse import coo_array
import kwant
import kwant.lattice
import kwant.builder
import numpy as np
from scipy.sparse import coo_array
from pymf.tb.tb import _tb_type
def builder_to_tb(
builder: kwant.builder.Builder, params: dict = {}, return_data: bool = False
) -> tb_type:
) -> _tb_type:
"""Construct a tight-binding dictionary from a `kwant.builder.Builder` system.
Parameters
......
......@@ -2,7 +2,7 @@ import numpy as np
from scipy.fftpack import ifftn
from typing import Tuple
from pymf.tb.tb import add_tb, tb_type
from pymf.tb.tb import add_tb, _tb_type
from pymf.tb.transforms import ifftn_to_tb, tb_to_khamvector
......@@ -36,8 +36,8 @@ def construct_density_matrix_kgrid(
def construct_density_matrix(
h: tb_type, filling: float, nk: int
) -> Tuple[tb_type, float]:
h: _tb_type, filling: float, nk: int
) -> Tuple[_tb_type, float]:
"""Compute the real-space density matrix tight-binding dictionary.
Parameters
......@@ -69,7 +69,7 @@ def construct_density_matrix(
return {(): density_matrix}, fermi
def meanfield(density_matrix: tb_type, h_int: tb_type) -> tb_type:
def meanfield(density_matrix: _tb_type, h_int: _tb_type) -> _tb_type:
"""Compute the mean-field correction from the density matrix.
Parameters
......
......@@ -4,7 +4,7 @@ from pymf.mf import (
construct_density_matrix,
meanfield,
)
from pymf.tb.tb import add_tb, tb_type
from pymf.tb.tb import add_tb, _tb_type
def _check_hermiticity(h):
......@@ -57,7 +57,7 @@ class Model:
the interaction is the same between all internal degrees of freedom.
"""
def __init__(self, h_0: tb_type, h_int: tb_type, filling: float) -> None:
def __init__(self, h_0: _tb_type, h_int: _tb_type, filling: float) -> None:
_tb_type_check(h_0)
self.h_0 = h_0
_tb_type_check(h_int)
......@@ -76,7 +76,7 @@ class Model:
_check_hermiticity(h_0)
_check_hermiticity(h_int)
def mfield(self, mf: tb_type, nk: int = 200) -> tb_type:
def mfield(self, mf: _tb_type, nk: int = 200) -> _tb_type:
"""Computes a new mean-field correction from a given one.
Parameters
......
import numpy as np
from pymf.tb.tb import tb_type
from pymf.tb.tb import _tb_type
def expectation_value(density_matrix: tb_type, observable: tb_type) -> complex:
def expectation_value(density_matrix: _tb_type, observable: _tb_type) -> complex:
"""Compute the expectation value of an observable with respect to a density matrix.
Parameters
......
import numpy as np
from pymf.tb.tb import tb_type
from pymf.tb.tb import _tb_type
def tb_to_flat(tb: tb_type) -> np.ndarray:
def tb_to_flat(tb: _tb_type) -> np.ndarray:
"""Parametrise a hermitian tight-binding dictionary by a flat complex vector.
Parameters
......@@ -29,7 +29,7 @@ def flat_to_tb(
tb_param_complex: np.ndarray,
ndof: int,
tb_keys: list[tuple[None] | tuple[int, ...]],
) -> tb_type:
) -> _tb_type:
"""Reverse operation to `tb_to_flat`.
It takes a flat complex 1d array and return the tight-binding dictionary.
......
......@@ -6,10 +6,10 @@ from pymf.params.param_transforms import (
real_to_complex,
tb_to_flat,
)
from pymf.tb.tb import tb_type
from pymf.tb.tb import _tb_type
def tb_to_rparams(tb: tb_type) -> np.ndarray:
def tb_to_rparams(tb: _tb_type) -> np.ndarray:
"""Parametrise a hermitian tight-binding dictionary by a real vector.
Parameters
......@@ -27,7 +27,7 @@ def tb_to_rparams(tb: tb_type) -> np.ndarray:
def rparams_to_tb(
tb_params: np.ndarray, tb_keys: list[tuple[None] | tuple[int, ...]], ndof: int
) -> tb_type:
) -> _tb_type:
"""Extract a hermitian tight-binding dictionary from a real vector parametrisation.
Parameters
......
......@@ -4,7 +4,7 @@ import scipy
from typing import Optional, Callable
from pymf.params.rparams import rparams_to_tb, tb_to_rparams
from pymf.tb.tb import add_tb, tb_type
from pymf.tb.tb import add_tb, _tb_type
from pymf.model import Model
from pymf.tb.utils import calculate_fermi_energy
......@@ -43,7 +43,7 @@ def solver(
nk: int = 100,
optimizer: Optional[Callable] = scipy.optimize.anderson,
optimizer_kwargs: Optional[dict[str, str]] = {"M": 0},
) -> tb_type:
) -> _tb_type:
"""Solve for the mean-field correction through self-consistent root finding.
Parameters
......
import numpy as np
tb_type = dict[tuple[()] | tuple[int, ...], np.ndarray]
_tb_type = dict[tuple[()] | tuple[int, ...], np.ndarray]
def add_tb(tb1: tb_type, tb2: tb_type) -> tb_type:
def add_tb(tb1: _tb_type, tb2: _tb_type) -> _tb_type:
"""Add up two tight-binding dictionaries together.
Parameters
......@@ -21,7 +21,7 @@ def add_tb(tb1: tb_type, tb2: tb_type) -> tb_type:
return {k: tb1.get(k, 0) + tb2.get(k, 0) for k in frozenset(tb1) | frozenset(tb2)}
def scale_tb(tb: tb_type, scale: float) -> tb_type:
def scale_tb(tb: _tb_type, scale: float) -> _tb_type:
"""Scale a tight-binding dictionary by a constant.
Parameters
......
import itertools
import numpy as np
from typing import Optional
from pymf.tb.tb import tb_type
ks_type = Optional[np.ndarray]
from pymf.tb.tb import _tb_type
def tb_to_khamvector(tb: tb_type, nk: int) -> np.ndarray:
def tb_to_khamvector(tb: _tb_type, nk: int) -> np.ndarray:
"""Evaluate a tight-binding dictionary on a k-space grid.
Parameters
......@@ -39,7 +37,7 @@ def tb_to_khamvector(tb: tb_type, nk: int) -> np.ndarray:
return np.sum(tb_array * k_dependency, axis=0)
def ifftn_to_tb(ifft_array: np.ndarray) -> tb_type:
def ifftn_to_tb(ifft_array: np.ndarray) -> _tb_type:
"""
Convert the result of `scipy.fft.ifftn` to a tight-binding dictionary.
......
from itertools import product
import numpy as np
from pymf.tb.tb import tb_type
from pymf.tb.tb import _tb_type
from pymf.mf import fermi_on_grid
from pymf.tb.transforms import tb_to_khamvector
def generate_guess(
tb_keys: list[tuple[None] | tuple[int, ...]], ndof: int, scale: float = 1
) -> tb_type:
) -> _tb_type:
"""Generate guess tight-binding dictionary.
Parameters
......@@ -59,7 +59,7 @@ def generate_tb_keys(cutoff: int, dim: int) -> list[tuple[None] | tuple[int, ...
return [*product(*([[*range(-cutoff, cutoff + 1)]] * dim))]
def calculate_fermi_energy(tb: tb_type, filling: float, nk: int = 100):
def calculate_fermi_energy(tb: _tb_type, filling: float, nk: int = 100):
"""
Calculate the Fermi energy of a given tight-binding dictionary.
......
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