py4mulas.mpi

modules

py4mulas.mpi.executors

class py4mulas.mpi.executors.KspaceExecutor(k_vectors: MakeVectors | list[tuple[float]] | None = None, k_bounds: MakeBounds | tuple[tuple[float]] | None = None)[source]

Bases: object

Parallel execution over k_vectors or k_bounds

k_vectors

The momentum vectors to be shared between workers, if not specified default model k_vectors are used.

k_bounds

Initial bounds to be shared between workers, if not specified default model bounds are used.

Note

We recommand to use num of processors = m^dim when scipy integration is expected. When discrete kspace sum is to be performed, the splitting is anyway deterministic.

__call__(fun)[source]

Call self as a function.

property input_data
property k_bounds
property k_vectors

py4mulas.mpi.kspace_partitioner

class py4mulas.mpi.kspace_partitioner.MakeBounds(model: Kmodel, centers: dict | None = None, size: int = 4)[source]

Bases: object

Makes a list of bounds with focus at some particular centers in kspace. This works perfectly for periodically ordered centers within model’s kspace.

model

An instance of Kmodel

centers

In the form {center:length}, with length being the half side-length of the box to be constructed around center. If centers is None, size will be used to uniformly split model’s bounds.

size

The number of points per dimention. Corresponds ideally to the number of processors for which bounds are discretized.

Example

>>> centers = {(i, j):0.1 for i in range(-4, 5) for j in range(-3, 4)}
>>> bounds = MakeBounds(model, centers, size=4)
>>> bounds.view()
apply()[source]
boxes_factory()[source]
build_box_from_center(center)[source]
complementary_directions(room, box)[source]
data() list[list[tuple[tuple[float]]]][source]
delete(previous_room)[source]
equal_in_some_directions(room, box)[source]
generate_bounds(room, box)[source]
isinside(room, box, dim=None)[source]
partial_generation(room, box)[source]
split_boxes()[source]
split_others() list[tuple[tuple[float]]][source]
update_bounds(box)[source]
valid(new_bounds, room)[source]
valid_appartenance(room, box)[source]
view()[source]
where_it_belongs(box)[source]
where_it_partially_belongs(box)[source]
class py4mulas.mpi.kspace_partitioner.MakeVectors(model: Kmodel, centers: dict, coarse_n: int | None = None)[source]

Bases: object

Makes k_vectors of the a model considering centers where a denser discretization is required.

model

An instance of Kmodel

centers

Contains the kpoints at which a zooming is wanted format: {coord:(side_length, n)} where n is the number of points along each direction

coarse_n

Number of sampling points along each dimension of the coarse kspace grid. If not provided, available k_vectors are considered for coarse grid within which centers are discretized.

data() list[numpy.ndarray][source]
Returns:

A list of k_vectors each consisting of discretized centers in addition to the coarse grid.

view() None[source]

py4mulas.mpi.computers

class py4mulas.mpi.computers.HamParamComputer(formula: KuboFormula, executor: KspaceExecutor, params: dict[str, list | numpy.ndarray], method: str = 'discrete', opts: dict | None = None)[source]

Bases: _Computer

Computes a response formula using an executor for varied Hamiltonian params.

Parameters:
  • formula – An instance of KuboFormula

  • executor – An instance of KspaceExecutor

  • params – A dictionary containing the parameters to be changed. It should be in the form: {'param1':[...], 'param2':[...]}.

Example

>>> params = {'param1':np.linspace(0, 1, 10), 'param2':[0, 1]}
>>> result = py4mulas.mpi.computers.HamParamComputer(some_formula, some_executor, params)(mu=0, temperature=0, eta=0)
__call__(mu: float = 0, temperature: float = 0, eta: float = 0) numpy.ndarray[source]

Gives the parallelly computed response formula at (\(\mu\), \(T\), \(\eta\))

Parameters:
  • mu – Chemical potential \(\mu\)

  • temperature – System’s temperature

  • eta – Broadening \(\eta\)

Returns:

The transport response as a 1d array ordered exactly as itertools.product(\(l_1\), \(l2\), …) with \(l_i\) being the list of values for the \(i\) th parameter in params

Return type:

np.ndarray

discret_response(k_vectors: list[tuple[float]] | tuple[list[tuple[float]]], **kwargs: float) numpy.ndarray[source]
nquad_response(k_bounds: tuple[tuple[float]] | list[tuple[tuple[float]]], **kwargs: float) numpy.ndarray[source]
class py4mulas.mpi.computers.MuTEtaComputer(formula: KuboFormula, executor: KspaceExecutor, opts: dict | None = None, method: str = 'discrete')[source]

Bases: _Computer

Computes a response formula using an executor with precomputation of the operator kernel for a set of data. The energy kernel is computed once for each set of k_vectors. Therefore, the loop over data is made cheap for each worker.

Parameters:
  • formula – An instance of KuboFormula

  • executor – An instance of KspaceExecutor

  • opts – The options to be passed to scipy integrator

  • method – Either discrete for discrete sum or scipy for adaptive integration.

__call__(mu: float | list = 0, temperature: float | list = 0, eta: float | list = 0) numpy.ndarray[source]

Executes parallelly a transport formula for a combunation of transport parameters (\(\mu\), \(T\), \(\eta\))

Parameters:
  • mu – Chemical potential \(\mu\)

  • temperature – System’s temperature

  • eta – Broadening \(\eta\)

Example

>>> mu = np.linspace(0, 1, 10)
>>> temperature = np.linspace(0, 1, 10)
>>> eta = np.linspace(0, 0.1, 10)
>>> result = py4mulas.mpi.computers.MuTEtaComputer(some_formula, some_executor)(mu, temperature, eta)
Returns:

The transport response as a 1d array ordered exactly itertools.product(mu, temperature, eta). If these are all given as floats the result is an array containing a single element.

Return type:

np.ndarray

discret_response(k_vectors: list[tuple[float]] | tuple[list[tuple[float]]], data: list) numpy.ndarray[source]
nquad_response(k_bounds: tuple[tuple[float]] | list[tuple[tuple[float]]], data: list) numpy.ndarray[source]