MPIBlockVector

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

class pyomo.contrib.pynumero.sparse.mpi_block_vector.MPIBlockVector(nblocks, rank_owner, mpi_comm, assert_correct_owners=False)[source]

Bases: BaseBlockVector, ndarray

Parallel structured vector interface. This interface can be used to perform parallel operations on vectors composed by vectors. The main idea is to allocate vectors in different processors and make the corresponding parallel calls when necessary.

_rank_owner

1D-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 communicator

_block_vector

Internal BlockVector. Blocks that belong to this processor are stored in _block_vector. Blocks that do not belong to this processor are empty and store as numpy.zeros(0)

Type:

BlockVector

_owned_mask

1D-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

_owned_blocks

1D-array with block indices owned by this processor. This includes blocks with ownership -1.

Type:

numpy.ndarray

_unique_owned_blocks

1D-array with block indices owned only by this processor. This does not include blocks with ownership -1.

Type:

numpy.ndarray

_brow_lengths

1D-Array of size nblocks that specifies the length of each entry in the MPIBlockVector. This is the same across all processors.

Type:

numpy.ndarray

_undefined_brows

A set of block indices for which the blocks are still None (i.e., the dimensions have not yet ben set). Operations with BlockVectors require all entries to be different than None.

Type:

set

Notes

This is the parallel implementation of pyomo.contrib.pynumero.sparse.BlockVector

Parameters:
  • nblocks (int) – number of blocks contained in the block vector

  • rank_owner (array_like) – Array_like of size nblocks. Each entry defines ownership of each block. There are two types of ownership. Block that are owned by all processor, and blocks owned by a single processor. If a block is owned by all processors then its ownership is -1. Otherwise, if a block is owned by a single processor, then its ownership is equal to the rank of the processor.

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

__init__(nblocks, rank_owner, mpi_comm, assert_correct_owners=False)[source]

Methods

__init__(nblocks, rank_owner, mpi_comm[, ...])

all([axis, out, keepdims])

Returns True if all elements evaluate to True.

any([axis, out, keepdims])

Returns True if all elements evaluate to True.

argmax([axis, out, keepdims])

Return indices of the maximum values along the given axis.

argmin([axis, out, keepdims])

Return indices of the minimum values along the given axis.

argpartition(kth[, axis, kind, order])

Returns the indices that would partition this array.

argsort([axis, kind, order])

Returns the indices that would sort this array.

astype(dtype[, order, casting, subok, copy])

Copy of the array, cast to a specified type.

block_sizes([copy])

Returns 1D-Array with sizes of individual blocks in this MPIBlockVector

broadcast_block_sizes()

Send sizes of all blocks to all processors.

byteswap([inplace])

Swap the bytes of the array elements

choose(choices[, out, mode])

Use an index array to construct a new array from a set of choices.

clip([min, max, out])

Return MPIBlockVector whose values are limited to [min, max].

clone([value, copy])

Returns a copy of this MPIBlockVector

compress(condition[, axis, out])

Return selected slices of each subblock.

conj()

Complex-conjugate all elements.

conjugate()

Complex-conjugate all elements.

copy([order])

Returns a copy of the MPIBlockVector

copy_structure()

Returns a copy of the MPIBlockVector structure filled with zeros

copyfrom(other)

Copy entries of other into this MPIBlockVector

copyto(other)

Copy entries of this MPIBlockVector into other

cumprod([axis, dtype, out])

Return the cumulative product of the elements along the given axis.

cumsum([axis, dtype, out])

Return the cumulative sum of the elements along the given axis.

diagonal([offset, axis1, axis2])

Return specified diagonals.

dot(other[, out])

Returns dot product

dump(file)

Dump a pickle of the array to the specified file.

dumps()

Returns the pickle of the array as a string.

fill(value)

Fills the MPIBLockVector with a scalar value.

finalize_block_sizes([broadcast, block_sizes])

Only set broadcast=False if you know what you are doing!

flatten([order])

Return a copy of the array collapsed into one dimension.

get_block(key)

get_block_size(ndx)

getfield(dtype[, offset])

Returns a field of the given array as a certain type.

is_broadcasted()

item(*args)

Copy an element of an array to a standard Python scalar and return it.

itemset(*args)

make_local_copy()

Copies the MPIBlockVector into a BlockVector

make_local_structure_copy()

Creates a BlockVector with the same structure as the MPIBlockVector

max([axis, out, keepdims])

Returns the largest value stored in this MPIBlockVector

mean([axis, dtype, out, keepdims])

Returns the average of all entries in this MPIBlockVector

min([axis, out, keepdims])

Returns the smallest value stored in the vector

newbyteorder([new_order])

nonzero()

Returns the indices of the elements that are non-zero.

partition(kth[, axis, kind, order])

Partially sorts the elements in the array in such a way that the value of the element in k-th position is in the position it would be in a sorted array.

pprint([root])

Prints BlockVector in pretty format

prod([axis, dtype, out, keepdims])

Returns the product of all entries in this MPIBlockVector

put(indices, values[, mode])

Set a.flat[n] = values[n] for all n in indices.

ravel([order])

Return a flattened array.

repeat(repeats[, axis])

Repeat elements of an array.

reshape(shape, /, *[, order, copy])

Returns an array containing the same data with a new shape.

resize(new_shape[, refcheck])

Change shape and size of array in-place.

round([decimals, out])

Return MPIBlockVector with each element rounded to the given number of decimals

searchsorted(v[, side, sorter])

Find indices where elements of v should be inserted in a to maintain order.

set_block(key, value)

set_blocks(blocks)

Assigns vectors in blocks

setfield(val, dtype[, offset])

Put a value into a specified place in a field defined by a data-type.

setflags([write, align, uic])

Set array flags WRITEABLE, ALIGNED, WRITEBACKIFCOPY, respectively.

sort([axis, kind, order])

Sort an array in-place.

squeeze([axis])

Remove axes of length one from a.

std([axis, dtype, out, ddof, keepdims, where])

Returns the standard deviation of the array elements along given axis.

sum([axis, dtype, out, keepdims])

Returns the sum of all entries in this MPIBlockVector

swapaxes(axis1, axis2)

Return a view of the array with axis1 and axis2 interchanged.

take(indices[, axis, out, mode])

Return an array formed from the elements of a at the given indices.

to_device

tobytes([order])

Construct Python bytes containing the raw data bytes in the array.

tofile(fid[, sep, format])

Write array to a file as text or binary (default).

tolist()

Disable np.ndarray.tolist as it is not supported.

tostring([order])

A compatibility alias for ~ndarray.tobytes, with exactly the same behavior.

trace([offset, axis1, axis2, dtype, out])

Return the sum along diagonals of the array.

transpose(*axes)

Returns a view of the array with axes transposed.

var([axis, dtype, out, ddof, keepdims, where])

Returns the variance of the array elements, along given axis.

view([dtype][, type])

New view of array with the same data.

Attributes

T

View of the transposed array.

base

Base object if memory is from some other object.

bshape

Returns the number of blocks in this MPIBlockVector in a tuple.

ctypes

An object to simplify the interaction of the array with the ctypes module.

data

Python buffer object pointing to the start of the array's data.

device

dtype

Data-type of the array's elements.

flags

Information about the memory layout of the array.

flat

A 1-D iterator over the array.

has_none

Returns True if block vector has none entry

imag

The imaginary part of the array.

itemsize

Length of one array element in bytes.

mT

View of the matrix transposed array.

mpi_comm

Returns MPI communicator

nblocks

Returns the number of blocks.

nbytes

Total bytes consumed by the elements of the array.

ndim

Returns dimension of this MPIBlockVector

owned_blocks

Returns list with indices of blocks owned by this processor.

ownership_mask

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

ptp

rank_ownership

Returns 1D-Array with processor ranks that own each block.

real

The real part of the array.

shape

Returns total number of elements in the MPIBlockVector

shared_blocks

Returns list with indices of blocks shared by all processors

size

Returns total number of elements in this MPIBlockVector

strides

Tuple of bytes to step in each dimension when traversing an array.

Member Documentation

all(axis=None, out=None, keepdims=False)[source]

Returns True if all elements evaluate to True.

any(axis=None, out=None, keepdims=False)[source]

Returns True if all elements evaluate to True.

block_sizes(copy=True)[source]

Returns 1D-Array with sizes of individual blocks in this MPIBlockVector

broadcast_block_sizes()[source]

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

clip(min=None, max=None, out=None)[source]

Return MPIBlockVector whose values are limited to [min, max]. One of max or min must be given.

Parameters:
  • min (scalar_like, optional) – Minimum value. If None, clipping is not performed on lower interval edge.

  • max (scalar_like, optional) – Maximum value. If None, clipping is not performed on upper interval edge.

Return type:

MPIBlockVector

clone(value=None, copy=True)[source]

Returns a copy of this MPIBlockVector

Parameters:
  • value (scalar, optional) – all entries of the cloned vector are set to this value

  • copy (bool, optional) – if set to true makes a deepcopy of each block in this vector. default False

Return type:

MPIBlockVector

compress(condition, axis=None, out=None)[source]

Return selected slices of each subblock.

Parameters:

condition (MPIBlockVector that selects which entries to return.) – Determines to select (evaluate True in condition)

Return type:

MPIBlockVector

conj()[source]

Complex-conjugate all elements.

conjugate()[source]

Complex-conjugate all elements.

copy(order='C')[source]

Returns a copy of the MPIBlockVector

copy_structure()[source]

Returns a copy of the MPIBlockVector structure filled with zeros

copyfrom(other)[source]

Copy entries of other into this MPIBlockVector

Parameters:

other (MPIBlockVector or BlockVector)

Return type:

None

copyto(other)[source]

Copy entries of this MPIBlockVector into other

Parameters:

other (MPIBlockVector or BlockVector)

Return type:

None

cumprod(axis=None, dtype=None, out=None)[source]

Return the cumulative product of the elements along the given axis.

Refer to numpy.cumprod for full documentation.

See also

numpy.cumprod

equivalent function

cumsum(axis=None, dtype=None, out=None)[source]

Return the cumulative sum of the elements along the given axis.

Refer to numpy.cumsum for full documentation.

See also

numpy.cumsum

equivalent function

dot(other, out=None)[source]

Returns dot product

Parameters:

other (MPIBlockVector)

Return type:

float

fill(value)[source]

Fills the MPIBLockVector with a scalar value.

Parameters:

value (scalar) – All elements in the vector will be assigned this value

Return type:

None

finalize_block_sizes(broadcast=True, block_sizes=None)[source]

Only set broadcast=False if you know what you are doing!

Parameters:
  • broadcast (bool)

  • block_sizes (None or np.ndarray)

flatten(order='C')[source]

Return a copy of the array collapsed into one dimension.

Parameters:

order ({'C', 'F', 'A', 'K'}, optional) – ‘C’ means to flatten in row-major (C-style) order. ‘F’ means to flatten in column-major (Fortran- style) order. ‘A’ means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. ‘K’ means to flatten a in the order the elements occur in memory. The default is ‘C’.

Returns:

y – A copy of the input array, flattened to one dimension.

Return type:

ndarray

See also

ravel

Return a flattened array.

flat

A 1-D flat iterator over the array.

Examples

>>> import numpy as np
>>> a = np.array([[1,2], [3,4]])
>>> a.flatten()
array([1, 2, 3, 4])
>>> a.flatten('F')
array([1, 3, 2, 4])
make_local_copy()[source]

Copies the MPIBlockVector into a BlockVector

Return type:

BlockVector

make_local_structure_copy()[source]

Creates a BlockVector with the same structure as the MPIBlockVector

Return type:

BlockVector

max(axis=None, out=None, keepdims=False)[source]

Returns the largest value stored in this MPIBlockVector

mean(axis=None, dtype=None, out=None, keepdims=False)[source]

Returns the average of all entries in this MPIBlockVector

min(axis=None, out=None, keepdims=False)[source]

Returns the smallest value stored in the vector

nonzero()[source]

Returns the indices of the elements that are non-zero.

pprint(root=0)[source]

Prints BlockVector in pretty format

prod(axis=None, dtype=None, out=None, keepdims=False)[source]

Returns the product of all entries in this MPIBlockVector

ravel([order])[source]

Return a flattened array.

Refer to numpy.ravel for full documentation.

See also

numpy.ravel

equivalent function

ndarray.flat

a flat iterator on the array.

round(decimals=0, out=None)[source]

Return MPIBlockVector with each element rounded to the given number of decimals

set_blocks(blocks)[source]

Assigns vectors in blocks

Parameters:

blocks (list) – list of vectors

Return type:

None

std(axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True)[source]

Returns the standard deviation of the array elements along given axis.

Refer to numpy.std for full documentation.

See also

numpy.std

equivalent function

sum(axis=None, dtype=None, out=None, keepdims=False)[source]

Returns the sum of all entries in this MPIBlockVector

tolist()[source]

Disable np.ndarray.tolist as it is not supported.

var(axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True)[source]

Returns the variance of the array elements, along given axis.

Refer to numpy.var for full documentation.

See also

numpy.var

equivalent function

property bshape

Returns the number of blocks in this MPIBlockVector in a tuple.

property has_none

Returns True if block vector has none entry

property mpi_comm

Returns MPI communicator

property nblocks

Returns the number of blocks.

property ndim

Returns dimension of this MPIBlockVector

property owned_blocks

Returns list with indices of blocks owned by this processor.

property ownership_mask

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

property rank_ownership

Returns 1D-Array with processor ranks that own each block. The ownership of blocks that are owned by all processors is -1.

property shape

Returns total number of elements in the MPIBlockVector

property shared_blocks

Returns list with indices of blocks shared by all processors

property size

Returns total number of elements in this MPIBlockVector