dubfi.linalg.mpi_parent¶
MPI linear algebra parent module.
This module instructs multiple MPI processes (workers) to do linear algebra computations.
Added in version 0.1.0: (initial release)
Classes¶
Singleton class keeping information about MPI setup. |
|
Base class for all MPI parent objects. |
|
MPI distributed vector. |
|
MPI parent of approximately diagonal or block-diagonal matrix. |
|
MPI distributed linear parametrized vector. |
|
MPI distributed R matrix for flux inversion. |
Functions¶
|
Construct MPI segments along one linear, equally spaced coordinate. |
|
Broadcast array to all child processes. |
Module Contents¶
- class dubfi.linalg.mpi_parent.MpiContext¶
Singleton class keeping information about MPI setup.
Return singleton when trying to create new instance.
- setup(workers: int = -1) None¶
Create MPI setup, create child process if necessary.
- is_initialized() bool¶
Check whether self has been initialized.
- init(workers: int = -1) None¶
Initialize self if it is not initialized yet.
- property workers: int¶
Number of MPI workers.
- property root: int¶
Number (id) of MPI root (or parent) process.
- property iter¶
Iterator over ids of worker processes.
- property comm¶
MPI communicator.
- gen_name(prefix: str = '') str¶
Generate a new, unique name.
- send_cmd(command: str) None¶
Send command to worker processes.
- quit() None¶
Send termination signal to MPI child processes.
- __del__() None¶
Destructor: quit child processes.
- Reduce(recvbuf: numpy.ndarray, op: mpi4py.MPI.Op) None¶
Wrap
mpi4py.MPI.Comm.Reduce()to receive data in root.
- dubfi.linalg.mpi_parent.simple_segments(size: int, overlap: int, number: int = -1) dubfi.linalg.segments.Segments¶
Construct MPI segments along one linear, equally spaced coordinate.
- dubfi.linalg.mpi_parent._send_array(array: numpy.ndarray | float) None¶
Broadcast array to all child processes.
- class dubfi.linalg.mpi_parent.MpiObj¶
Base class for all MPI parent objects.
Initialization generates self._name and destruction deletes the associated objects on worker processes.
- __del__()¶
Destructor: Delete associated objects on worker processes.
- class dubfi.linalg.mpi_parent.MpiVector(seg: dubfi.linalg.segments.Segments, shape: tuple[int, ...])¶
Bases:
dubfi.linalg.types.AbstractVector,MpiObjMPI distributed vector.
- property shape¶
Shape of array representation of self, last dimension is the vector dimension.
- property data¶
Numpy array representation of self, collects data from worker processes.
- classmethod fromdata(data: numpy.ndarray, other=None)¶
Construct distributed vector from dense array, borrowing segment information from other.
- classmethod fromarray(segments: dubfi.linalg.segments.Segments, data: numpy.ndarray)¶
Construct distributed vector from dense array and given segments.
- apply(other)¶
Compute scalar product with other vector.
- __add__(other)¶
Add two vectors, applying broadcasting rules.
- __iadd__(other)¶
Add vector in-place.
- __sub__(other)¶
Subtract vector from self, applying broadcasting rules.
- __isub__(other)¶
Subtract vector in-place.
- __mul__(other)¶
Multiply by scalar or numpy array treated as scalar along vector space dimension.
- iszero()¶
Check if all elements are zero.
- tonumpy()¶
Numpy array representation of self, collects data from worker processes.
- class dubfi.linalg.mpi_parent.MpiDenseBdMatrix(seg: dubfi.linalg.segments.Segments, shape: tuple[int, ...])¶
Bases:
dubfi.linalg.types.AbstractOperator,MpiObjMPI parent of approximately diagonal or block-diagonal matrix.
- property shape¶
Shape of array (matrix) representation of self.
- classmethod fromarray(data: numpy.ndarray, seg: dubfi.linalg.segments.Segments)¶
Construct distributed operator from dense array and given segments.
- apply(vec)¶
Apply operator on vector: self @ vec.
- rapply(vec)¶
Apply transpose operator on vector: self.T @ vec.
- inv()¶
Compute (multiplicative) inverse operator.
- solve(vec)¶
Solve linear equation self @ x = vec for x.
- chain(other)¶
Combine operators: self @ other.
- diagonal()¶
Return diagonal of self as MPI vector.
- __mul__(other)¶
Multiply element-wise.
- __add__(other)¶
Add to other linear operator.
- __iadd__(other)¶
Add other linear operator in-place.
- __sub__(other)¶
Subtract other linear operator.
- __isub__(other)¶
Subtract other linear operator in-place.
- dot(other)¶
Inner product along non-vector dimensions.
- trace()¶
Compute trace of self.
- trace_product(other)¶
Compute trace of (self @ other).
- logdet()¶
Compute log(det(self)) assuming that self is a positive definite, real-symmetric matrix.
- tonumpy()¶
Numpy array representation of self, collects data from worker processes.
- sandwich(vec)¶
Compute vec @ self @ vec.
- validate_uncertainty_statistics(vec) tuple[numpy.ndarray, numpy.ndarray]¶
Indicate whether vec is a likely realization of a Gaussian random variable with variance self.
Assume that self is the error covariance matrix of a Gaussian random variable X with mean 0. Provide indications whether X is a likely realization of X in the following form:
Diagonalize self: self = V @ diag(D) @ V.T where D is the vector of eigenvalues of self and V is an orthogonal matrix. Return (V.T @ vec, D). One can expect that (V.T @ vec) / D is a Gaussian random variable with mean 0 and standard deviation 1.
Added in version 0.1.3.
- class dubfi.linalg.mpi_parent.MpiLinParamVector(seg: dubfi.linalg.segments.Segments, shape: tuple[int, ...])¶
Bases:
dubfi.linalg.generic.ParametrizedVector,MpiObjMPI distributed linear parametrized vector.
- classmethod fromarray(seg: dubfi.linalg.segments.Segments, array: numpy.ndarray)¶
Construct distributed parametrized vector from dense array and given segments.
- __call__(s)¶
Compute vector at given parameters.
- grad(s)¶
Compute gradient of vector at given parameters.
- hess(s)¶
Compute Hesse matrix of vector at given parameters.
- class dubfi.linalg.mpi_parent.MpiDensePostR(seg)¶
Bases:
dubfi.linalg.generic.ParametrizedOperator,MpiObjMPI distributed R matrix for flux inversion.
- classmethod fromarray(seg: dubfi.linalg.segments.Segments, h_ens: numpy.ndarray, localization_length: float, regularization: float)¶
Construct distributed object from dense vectors and given segments.
- __call__(s)¶
Compute R at given parameters.
- grad(s)¶
Compute gradient of R at given parameters.
- hess(s)¶
Compute Hesse matrix of R at given parameters.