tbplas.DiagSolver
- class tbplas.DiagSolver(model: Any, overlap: Any = None, enable_mpi: bool = False, echo_details: bool = True)
Base class for solvers based on exact diagonalization.
NOTE: we declare the type of ‘model’ and ‘overlap’ to be ‘Any’ for duck typing.
- __model
model for which properties will be calculated
- Type:
‘PrimitiveCell’ or ‘Sample’ instance
- __overlap
container for holding overlaps for primitive cells with non-orthogonal orbitals
- Type:
‘Overlap’ instance
- __h_mat
dense Hamiltonian matrix
- Type:
(num_orb, num_orb) complex128 array
- __s_mat
dense overlap matrix for the general eigenvalue problem
- Type:
(num_orb, num_orb) complex128 array
- __init__(model: Any, overlap: Any = None, enable_mpi: bool = False, echo_details: bool = True) None
- Parameters:
model – primitive cell or sample under study
overlap – container for overlaps between orbitals
enable_mpi – whether to enable MPI-based parallelization
echo_details – whether to output parallelization details
Methods
__init__
(model[, overlap, enable_mpi, ...])- param model:
primitive cell or sample under study
all_average
(data_local)Average results over random samples broadcast to all process.
all_reduce
(data_local)Reduce local data and broadcast to all processes.
average
(data_local)Average results over random samples and store results to master process.
barrier
()Wrapper for self.comm.Barrier.
bcast
(data_local)Broadcast data from master to other processes.
calc_bands
(k_points[, convention, solver, ...])Calculate band structure along given k_path.
calc_dos
(k_points[, e_min, e_max, e_step, ...])Calculate density of states for given energy range and step.
calc_states
(k_points[, convention, solver, ...])Calculate energies and wave functions on k-points.
dist_bound
(n_max)Same as dist_range, but returns the lower and upper bounds.
dist_list
(raw_list[, algorithm])Distribute a list over processes.
dist_range
(n_max)Distribute range(n_max) over processes.
log
([event, fmt])Log the date and time of event.
print
([text])Print text on master process.
reduce
(data_local)Reduce local data to master process.
Attributes
Determine whether this is the master process.
Get the lattice vectors of the model.
Check if the model is a primitive cell.
Determine whether MPI is enabled.
Get the number of orbitals in the model.
Interface for the '__rank' attribute.
Get the reciprocal lattice vectors of the model in 1/nm.
Interface for the '__size' attribute.
- __init__(model: Any, overlap: Any = None, enable_mpi: bool = False, echo_details: bool = True) None
- Parameters:
model – primitive cell or sample under study
overlap – container for overlaps between orbitals
enable_mpi – whether to enable MPI-based parallelization
echo_details – whether to output parallelization details
- all_average(data_local: ndarray) ndarray
Average results over random samples broadcast to all process.
- Parameters:
data_local – local results on each process
- Returns:
averaged data from data_local
- all_reduce(data_local: ndarray) ndarray
Reduce local data and broadcast to all processes.
- Parameters:
data_local – local results on each process
- Returns:
summed data from data_local
- average(data_local: ndarray) ndarray
Average results over random samples and store results to master process.
- Parameters:
data_local – local results on each process
- Returns:
averaged data from data_local
- barrier() None
Wrapper for self.comm.Barrier.
- bcast(data_local: ndarray) None
Broadcast data from master to other processes.
- Parameters:
data_local – local results on each process
- Returns:
None
- calc_bands(k_points: ndarray, convention: int = 1, solver: str = 'lapack', orbital_indices: Union[Iterable[int], ndarray] = None, **kwargs) namedtuple
Calculate band structure along given k_path.
The result is a named tuple with the following attributes: k_len: (num_kpt,) float64 array, length of k-path bands: (num_kpt, num_bands) float64 array, band structure proj: (num_kpt, num_bands) float64 array, projection on selected orbitals
- Parameters:
k_points – (num_kpt, 3) float64 array FRACTIONAL coordinates of the k-points
convention – convention for setting up the Hamiltonian
solver – solver type, should be “lapack” or “arpack”
orbital_indices – indices of orbitals for evaluating projection, take all orbitals into consideration if no orbitals are specified
kwargs – arguments for the arpack solver
- Returns:
k_len, band structure and projection packed in named tuple
- Raises:
ValueError – if solver is neither lapack nor arpack
- calc_dos(k_points: ndarray, e_min: float = None, e_max: float = None, e_step: float = 0.05, sigma: float = 0.05, basis: str = 'Gaussian', g_s: int = 1, **kwargs) Tuple[ndarray, ndarray]
Calculate density of states for given energy range and step.
- Parameters:
k_points – (num_kpt, 3) float64 array FRACTIONAL coordinates of k-points
e_min – lower bound of the energy range in eV
e_max – upper hound of the energy range in eV
e_step – energy step in eV
sigma – broadening parameter in eV
basis – basis function to approximate the Delta function
g_s – spin degeneracy
kwargs – arguments for ‘calc_bands’
- Returns:
(energies, dos) energies: (num_grid,) float64 array energy grid corresponding to e_min, e_max and e_step dos: (num_grid,) float64 array density of states in states/eV
- Raises:
ValueError – if basis is neither Gaussian nor Lorentzian, or the solver is neither lapack nor arpack
- calc_states(k_points: ndarray, convention: int = 1, solver: str = 'lapack', all_reduce: bool = True, **kwargs) Tuple[ndarray, ndarray]
Calculate energies and wave functions on k-points.
- Parameters:
k_points – (num_kpt, 3) float64 array FRACTIONAL coordinates of the k-points
convention – convention for setting up the Hamiltonian
solver – solver type, should be “lapack” or “arpack”
all_reduce – whether to call MPI_Allreduce to synchronize the results on each process
kwargs – arguments for the arpack solver
- Returns:
(bands, states) bands: (num_kpt, num_bands) float64 array energies on the k-points states: (num_kpt, num_bands, num_orb) complex128 array wave functions on the k-points, each ROW of states[i_k] is a wave function
- Raises:
ValueError – if solver is neither lapack nor arpack
- dist_bound(n_max: int) Tuple[int, int]
Same as dist_range, but returns the lower and upper bounds. Both of the bounds are close, i.e. [i_min, i_max].
- Parameters:
n_max – upper bound of range
- Returns:
lower and upper bounds of subrange assigned to this process
- dist_list(raw_list: List[Any], algorithm: str = 'range') List[Any]
Distribute a list over processes.
- Parameters:
raw_list – raw list to distribute
algorithm – distribution algorithm, should be either “remainder” or “range”
- Returns:
sublist assigned to this process
- dist_range(n_max: int) range
Distribute range(n_max) over processes.
- Parameters:
n_max – upper bound of the range
- Returns:
subrange assigned to this process
- log(event: str = '', fmt: str = '%x %X') None
Log the date and time of event.
- Parameters:
event – notice of the event
fmt – date and time format
- Returns:
None.
- print(text: str = '') None
Print text on master process.
NOTE: flush=True is essential for some MPI implementations, e.g. MPICH3.
- Parameters:
text – text to print
- Returns:
None
- reduce(data_local: ndarray) ndarray
Reduce local data to master process.
- Parameters:
data_local – local results on each process
- Returns:
summed data from data_local
- __weakref__
list of weak references to the object (if defined)
- property is_master: bool
Determine whether this is the master process.
- property lat_vec: ndarray
Get the lattice vectors of the model.
- Returns:
(3, 3) float64 array lattice vectors of in nm
- property model_is_pc: bool
Check if the model is a primitive cell.
- Returns:
whether the model is a primitive cell
- property mpi_enabled: bool
Determine whether MPI is enabled.
- property num_orb: int
Get the number of orbitals in the model.
- Returns:
number of orbitals
- property rank: int
Interface for the ‘__rank’ attribute.
- Returns:
rank of this MPI process
- property recip_lat_vec: ndarray
Get the reciprocal lattice vectors of the model in 1/nm.
- Returns:
(3, 3) float64 array reciprocal lattice vectors of in nm
- property size: int
Interface for the ‘__size’ attribute.
- Returns:
number of MPI processes