MPIBlockMatrix

(class from pyomo.contrib.pynumero.sparse.mpi_block_matrix)

class pyomo.contrib.pynumero.sparse.mpi_block_matrix.MPIBlockMatrix(nbrows, nbcols, rank_ownership, mpi_comm, assert_correct_owners=False)[source]

Bases: BaseBlockMatrix

Parallel Structured Matrix interface

_rank_owner

2D-array with processor ownership of each block. A block can be own by a single processor or by all processors. Blocks own by all processors have ownership -1. Blocks own by a single processor have ownership rank. where rank=MPI.COMM_WORLD.Get_rank()

Type:

numpy.ndarray

_mpiw

A communicator from the MPI space. Typically MPI.COMM_WORLD

Type:

MPI.Comm

_block_matrix

Internal BlockMatrix. Blocks that belong to this processor are stored in _block_matrix.

Type:

BlockMatrix

_owned_mask

2D-array that indicates if a block belongs to this processor. While _rank_owner tells which processor(s) owns each block, _owned_mask tells if a block is owned by this processor. Blocks that are owned by everyone (i.e. ownership = -1) are True in _owned_mask

Type:

numpy.ndarray bool

_unique_owned_mask

2D-array that indicates if a block belongs to this processor. While _rank_owner tells which processor(s) owns each block, _unique_owned_mask tells if a block is owned by this processor. Blocks that are owned by everyone (i.e. ownership = -1) are False in _unique_owned_mask

Type:

numpy.ndarray bool

Parameters:
  • nbrows (int) – number of block-rows in the matrix

  • nbcols (int) – number of block-columns in the matrix

  • rank_ownership (array_like) – integer 2D array that specifies the rank of process owner of each block in the matrix. For blocks that are owned by all processes the rank is -1. Blocks that are None should be owned by all processes.

  • mpi_comm (MPI communicator)

  • assert_correct_owners (bool) – If True, then checks will be performed to ensure that processor owners are consistent. This check requires communication. If False, this check is skipped.

__init__(nbrows, nbcols, rank_ownership, mpi_comm, assert_correct_owners=False)[source]

Methods

__init__(nbrows, nbcols, rank_ownership, ...)

block_shapes()

Returns list with shapes of blocks in this BlockMatrix

broadcast_block_sizes()

Send sizes of all blocks to all processors.

col_block_sizes([copy])

Returns array with col-block sizes

coo_data()

copy()

Makes a copy of this MPIBlockMatrix

copy_structure()

Makes a copy of the structure of this MPIBlockMatrix.

diagonal([k])

dot(other)

Ordinary dot product

fromBlockMatrix(block_matrix, ...[, ...])

Creates a parallel MPIBlockMatrix from blockmatrix

get_block(row, col)

get_block_column_index(index)

Returns block-column idx from matrix column index.

get_block_mask([copy])

get_block_row_index(index)

Returns block-row idx from matrix row index.

get_col_size(col)

get_row_size(row)

getcol(j)

Returns MPIBlockVector of column j

getrow(i)

Returns MPIBlockVector of column i

has_undefined_col_sizes()

Indicates if the matrix has block-columns with undefined dimensions

has_undefined_row_sizes()

Indicates if the matrix has block-rows with undefined dimensions

is_col_size_defined(col[, this_process_only])

is_empty_block(idx, jdx[, this_process_only])

Indicates if a block is empty

is_row_size_defined(row[, this_process_only])

mean([axis, dtype, out])

nonzero()

reset_bcol(jdx)

Resets all blocks in selected column to None (0 nonzero entries)

reset_brow(idx)

Resets all blocks in selected row to None (0 nonzero entries)

row_block_sizes([copy])

Returns array with row-block sizes

set_block(row, col, value)

set_col_size(col, size)

set_row_size(row, size)

setdiag(values[, k])

sum([axis, dtype, out])

to_local_array()

This method is only for testing/debugging

toarray()

Returns a dense ndarray representation of this matrix.

tobsr([blocksize, copy])

tocoo()

Converts this matrix to coo_matrix format.

tocsc()

Converts this matrix to csc format.

tocsr()

Converts this matrix to csr format.

todia([copy])

tolil([copy])

tostring([order])

transpose([axes, copy])

Reverses the dimensions of the block matrix.

Attributes

T

Transpose matrix

bshape

Returns tuple with the block-shape of the matrix

mpi_comm

Returns MPI communicator

nnz

Returns total number of nonzero values in this matrix

owned_blocks

Returns list with indices of blocks owned by this processor.

ownership_mask

Returns boolean 2D-Array that indicates which blocks are owned by this processor

rank_ownership

Returns 2D array that specifies process rank that owns each blocks.

shape

Returns tuple with total number of rows and columns

shared_blocks

Returns list of 2-tuples with indices of blocks shared by all processors

Member Documentation

block_shapes()[source]

Returns list with shapes of blocks in this BlockMatrix

Notes

For an MPIBlockMatrix with 2 block-rows and 2 block-cols this method returns [[Block_00.shape, Block_01.shape],[Block_10.shape, Block_11.shape]]

Return type:

list

broadcast_block_sizes()[source]

Send sizes of all blocks to all processors. After this method is called this MPIBlockMatrix knows it’s dimensions of all rows and columns. This method must be called before running any operations with the MPIBlockMatrix.

col_block_sizes(copy=True)[source]

Returns array with col-block sizes

Parameters:

copy (bool) – If False, then the internal array which stores the column block sizes will be returned without being copied. Setting copy to False is risky and should only be done with extreme care.

Return type:

numpy.ndarray

copy()[source]

Makes a copy of this MPIBlockMatrix

Return type:

MPIBlockMatrix

copy_structure()[source]

Makes a copy of the structure of this MPIBlockMatrix. This proivides a light-weighted copy of each block in this MPIBlockMatrix. The blocks in the resulting matrix have the same shape as in the original matrices but not the same number of nonzeros.

Return type:

MPIBlockMatrix

dot(other)[source]

Ordinary dot product

static fromBlockMatrix(block_matrix, rank_ownership, mpi_comm, assert_correct_owners=False)[source]

Creates a parallel MPIBlockMatrix from blockmatrix

Parameters:
  • block_matrix (BlockMatrix) – The block matrix to use to create the MPIBlockMatrix

  • rank_ownership (array_like) – 2D-array with processor ownership of each block. A block can be own by a single processor or by all processors. Blocks own by all processors have ownership -1. Blocks own by a single processor have ownership rank. where rank=MPI.COMM_WORLD.Get_rank()

  • mpi_comm (MPI communicator) – An MPI communicator. Tyically MPI.COMM_WORLD

get_block_column_index(index)[source]

Returns block-column idx from matrix column index.

Parameters:

index (int) – Column index

Return type:

int

get_block_row_index(index)[source]

Returns block-row idx from matrix row index.

Parameters:

index (int) – Row index

Return type:

int

getcol(j)[source]

Returns MPIBlockVector of column j

Parameters:

j (int) – Column index

Return type:

pyomo.contrib.pynumero.sparse MPIBlockVector

getrow(i)[source]

Returns MPIBlockVector of column i

Parameters:

i (int) – Row index

Return type:

pyomo.contrib.pynumero.sparse MPIBlockVector

has_undefined_col_sizes()[source]

Indicates if the matrix has block-columns with undefined dimensions

Return type:

bool

has_undefined_row_sizes()[source]

Indicates if the matrix has block-rows with undefined dimensions

Return type:

bool

is_empty_block(idx, jdx, this_process_only=True)[source]

Indicates if a block is empty

Parameters:
  • idx (int) – block-row index

  • jdx (int) – block-column index

Return type:

boolean

reset_bcol(jdx)[source]

Resets all blocks in selected column to None (0 nonzero entries)

Parameters:

jdx (integer) – column index to be reset

Return type:

None

reset_brow(idx)[source]

Resets all blocks in selected row to None (0 nonzero entries)

Parameters:

idx (integer) – row index to be reset

Return type:

None

row_block_sizes(copy=True)[source]

Returns array with row-block sizes

Parameters:

copy (bool) – If False, then the internal array which stores the row block sizes will be returned without being copied. Setting copy to False is risky and should only be done with extreme care.

Return type:

numpy.ndarray

to_local_array()[source]

This method is only for testing/debugging

Returns:

result

Return type:

np.ndarray

toarray()[source]

Returns a dense ndarray representation of this matrix.

Returns:

arr – An array with the same shape and containing the same data represented by the block matrix.

Return type:

ndarray, 2-dimensional

tocoo()[source]

Converts this matrix to coo_matrix format.

Return type:

coo_matrix

tocsc()[source]

Converts this matrix to csc format.

Return type:

csc_matrix

tocsr()[source]

Converts this matrix to csr format.

Return type:

csr_matrix

transpose(axes=None, copy=True)[source]

Reverses the dimensions of the block matrix.

Parameters:
  • axes (None, optional) – This argument is in the signature solely for NumPy compatibility reasons. Do not pass in anything except for the default value.

  • copy (bool) – This argument is in the signature solely for scipy compatibility reasons. Do not pass in anything except for the default value.

Return type:

MPIBlockMatrix with dimensions reversed

property T

Transpose matrix

property bshape

Returns tuple with the block-shape of the matrix

property mpi_comm

Returns MPI communicator

property nnz

Returns total number of nonzero values in this matrix

property owned_blocks

Returns list with indices of blocks owned by this processor.

property ownership_mask

Returns boolean 2D-Array that indicates which blocks are owned by this processor

property rank_ownership

Returns 2D array that specifies process rank that owns each blocks. If a block is owned by all the ownership=-1.

property shape

Returns tuple with total number of rows and columns

property shared_blocks

Returns list of 2-tuples with indices of blocks shared by all processors