Warning

You are reading a version of the website built against the unstable main branch. This content is liable to change without notice and may be inappropriate for your use case. You can find the documentation for the current stable release here.

pyop3.expr.tensor package

Submodules

pyop3.expr.tensor.base module

class pyop3.expr.tensor.base.CallableTensorTransform[source]

Bases: TensorTransform

class pyop3.expr.tensor.base.IdentityTensorTransform[source]

Bases: TensorTransform

class pyop3.expr.tensor.base.OutOfPlaceCallableTensorTransform(transform_in, transform_out, prev=None)[source]

Bases: CallableTensorTransform

OutOfPlaceCallableTensorTransform(transform_in: ‘Callable[[Tensor, Tensor], None]’, transform_out: ‘Callable[[Tensor, Tensor], None]’, prev: ‘TensorTransform | None’ = None)

get_instruction_executor_cache_key(visitor)[source]
prev = None
record_new(**attrs)

Create and initialise a new record from an existing one.

transform_in
transform_out
class pyop3.expr.tensor.base.ReshapeTensorTransform(axis_trees, prev=None)[source]

Bases: IdentityTensorTransform

ReshapeTensorTransform(axis_trees: ‘tuple[pyop3.axis_tree.AxisTree, …]’, prev: ‘TensorTransform | None’ = None)

axis_trees
get_instruction_executor_cache_key(visitor)[source]
prev = None
record_new(**attrs)

Create and initialise a new record from an existing one.

class pyop3.expr.tensor.base.Tensor[source]

Bases: TerminalExpression, ABC

DEFAULT_PREFIX = 'array'
__getitem__(indices)[source]
assemble()[source]

Ensure that values are up-to-date.

assign(other, /, mode='write', *, eager=False, eager_strategy=None, compiler_parameters=None, **kwargs)[source]
abstract property axis_trees
property comm
concretize()[source]

Convert to an expression, can no longer be indexed properly

copy(*, constant=None)[source]

Return a copy of the tensor.

Parameters:

constant – Is the copy mutable or not? If \(None\) then default to the const-ness of the original object.

property data
property data_ro

Return a read-only view of the data stored by the dat.

property data_rw

Return a modifiable view of the data stored by the dat.

property data_wo

Return a write-only view of the data stored by the dat.

abstract property dim
property dtype
duplicate(*, copy=False, constant=None)[source]

Return a duplicate of the tensor.

Parameters:
  • copy – Whether to copy values to the new object.

  • constant – Is the duplicate mutable or not? If \(None\) then default to the const-ness of the original object.

abstractmethod getitem(*indices, strict=False)[source]
iassign(other, /, *, eager=False, eager_strategy=None, compiler_parameters=None, **kwargs)[source]
abstract property size
abstract property transform
abstractmethod with_axis_trees(trees)[source]
with_context(context)[source]
zero(**kwargs)[source]
class pyop3.expr.tensor.base.TensorTransform[source]

Bases: Object, ABC

pyop3.expr.tensor.dat module

class pyop3.expr.tensor.dat.AggregateDat(subdats, axis, *, name=None, prefix=None)[source]

Bases: Object

A dat formed of multiple subdats concatenated together.

DEFAULT_PREFIX = 'aggdat'
assign(other, *, _weakref=True)[source]
property axes[source]
axis
property comm
property dtype
get_instruction_executor_cache_key(visitor)[source]
iassign(other, *, _weakref=True)[source]
materialize()[source]
name
record_new(**attrs)

Create and initialise a new record from an existing one.

property size
subdats
property subtensors
with_context(context)[source]
exception pyop3.expr.tensor.dat.AxisMismatchException[source]

Bases: Pyop3Exception

class pyop3.expr.tensor.dat.CompositeDat(axis_tree, exprs)[source]

Bases: Terminal

exprs: expression per leaf path TODO check only leaf paths allowed, I think so?

axis_tree
dtype = dtype('int32')
exprs
get_instruction_executor_cache_key(visitor)[source]
property local_max
property local_min
record_new(**attrs)

Create and initialise a new record from an existing one.

class pyop3.expr.tensor.dat.Dat(axes, buffer=None, *, data=None, name=None, prefix=None, buffer_kwargs=None, constant=False, transform=None)[source]

Bases: Tensor

Multi-dimensional, hierarchical array.

DEFAULT_PREFIX = 'dat'
__getitem__(indices)[source]
as_array(mode, block_shape=None, *, include_ghosts=False)[source]
as_vec(mode, block_shape=None)[source]
axes
property axis_trees
axpy(alpha, other)[source]

Compute the operation \(y = \alpha x + y\).

In this case, self is y and other is x.

buffer
property comm
concretize(*, linear)[source]

Convert to an expression, can no longer be indexed properly

property context_free
property dat_version
property data_ro_with_halos

Return a read-only view of the data stored by the dat.

This view includes ghost entries.

property data_rw_with_halos

Return a modifiable view of the data stored by the dat.

This view includes ghost entries.

property data_with_halos
property data_wo_with_halos

Return a write-only view of the data stored by the dat.

This view includes ghost entries.

dim = 1
property dtype
duplicate(*, copy=False, constant=None)[source]
classmethod empty(axes, dtype=dtype('float64'), *, buffer_kwargs=immutabledict({}), **kwargs)[source]
classmethod empty_like(dat, **kwargs)[source]
classmethod from_array(array, *, sf=None, comm=<mpi4py.MPI.Intracomm object>, buffer_kwargs=None, constant=False, rank_equal=False, **kwargs)[source]
classmethod from_sequence(sequence, dtype, **kwargs)[source]
classmethod full(axes, fill_value, dtype=dtype('float64'), *, buffer_kwargs=immutabledict({}), **kwargs)[source]
get_instruction_executor_cache_key(visitor)[source]
get_value(indices, path=None, *, loop_exprs=immutabledict({}))[source]
getitem(index, *, strict=False)[source]
property global_data

Return all the data for the Dat gathered onto individual ranks.

This function is logically collective over MPI ranks, it is an error to call it on fewer than all the ranks in MPI communicator. PYOP3_SPMD_STRICT=1 is in your environment and function calls will be guarded by a barrier where possible.

inner(other, /)[source]

Compute the l2 inner product against another dat.

Parameters:

other – The other \(Dat\) to compute the inner product against. Its complex conjugate is taken.

Returns:

The l2 inner product.

Return type:

numpy.number

property local_max
property local_min
localize()[source]
materialize()[source]

Return a new “unindexed” array with the same shape.

property max

Return the global maximum value held by the dat.

maxpy(alphas, dats)[source]

Compute a sequence of axpy operations.

This is equivalent to calling axpy for each pair of scalars and \(Dat\) in the input sequences.

Parameters:
  • alphas – A sequence of scalars.

  • dats – A sequence of \(Dat\).

property min

Return the global minimum value held by the dat.

name
property nbytes

Return an estimate of the size of the data associated with this Dat in bytes. This will be the correct size of the data payload, but does not take into account the (presumably small) overhead of the object and its metadata.

Note that this is the process local memory usage, not the sum over all MPI processes.

property norm

Compute the l2 norm of this \(Dat\).

Note

This acts on the flattened data (see also inner()).

classmethod null(axes, dtype=dtype('float64'), *, buffer_kwargs=immutabledict({}), **kwargs)[source]
null_like(**kwargs)[source]
record_new(**attrs)

Create and initialise a new record from an existing one.

reshape(axes, _allow_indexed=False)[source]

Return a reshaped view of the \(Dat\).

TODO

set_value(indices, value, path=None, *, loop_exprs=immutabledict({}))[source]
property sf
property size
property transform
property vec
property vec_ro
property vec_rw
property vec_wo
with_axes(axes)[source]

Return a view of the current \(Dat\) with new axes.

Parameters:

axes – XXX (type?)

Returns:

XXX

Return type:

Dat

with_axis_trees(axis_trees)[source]
classmethod zeros(axes, dtype=dtype('float64'), *, buffer_kwargs=None, **kwargs)[source]
classmethod zeros_like(dat, **kwargs)[source]
exception pyop3.expr.tensor.dat.IncompatibleShapeError[source]

Bases: Exception

TODO, also bad name

pyop3.expr.tensor.mat module

class pyop3.expr.tensor.mat.AggregateMat(submats, row_axis, column_axis, *, name=None, prefix=None)[source]

Bases: Object

A matrix formed of multiple submatrices concatenated together.

DEFAULT_PREFIX = 'aggmat'
assign(other, *, _weakref=True)[source]
property column_axes[source]
column_axis
property comm
property dtype
get_instruction_executor_cache_key(visitor)[source]
iassign(other, *, _weakref=True)[source]
materialize()[source]
name
record_new(**attrs)

Create and initialise a new record from an existing one.

property row_axes[source]
row_axis
submats
property subtensors
with_context(context)[source]
class pyop3.expr.tensor.mat.Mat(row_axes, column_axes, buffer, *, name=None, prefix=None, transform=None)[source]

Bases: Tensor

A matrix.

DEFAULT_MAT_INIT_BUFFER_SPEC = MonolithicPetscMatInitBufferSpec(mat_type='aij', block_shape=((), ()))
DEFAULT_PREFIX = 'mat'
as_array(mode)[source]
property axis_trees[source]
buffer
column_axes
property comm
property dim
property dtype
classmethod empty(row_axes, column_axes, *, buffer_spec=None, preallocator=False, buffer_kwargs=immutabledict({}), **kwargs)[source]
classmethod from_sparsity(sparsity, **kwargs)[source]
get_instruction_executor_cache_key(visitor)[source]
getitem(row_index, column_index, *, strict=False)[source]
property handle
property local_max
property local_min
materialize()[source]

Return a new “unindexed” array with the same shape.

name
property ncols[source]

The number of local columns in the matrix (including ghosts).

property nest_indices[source]
property nrows[source]

The number of local rows in the matrix (including ghosts).

classmethod null(row_axes, column_axes, dtype=dtype('float64'), *, buffer_kwargs=immutabledict({}), **kwargs)[source]
null_like(**kwargs)[source]
record_new(**attrs)

Create and initialise a new record from an existing one.

reshape(row_axes, column_axes)[source]

Return a reshaped view of the \(Mat\).

TODO

row_axes
property size[source]
classmethod sparsity(row_axes, column_axes, **kwargs)[source]
property transform
property values
with_axes(row_axes, column_axes)[source]

Return a view of the current mat with new axes.

with_axis_trees(axis_trees)[source]
pyop3.expr.tensor.mat.make_full_mat_buffer_spec(partial_spec, row_axes, column_axes)[source]

pyop3.expr.tensor.scalar module

class pyop3.expr.tensor.scalar.Scalar(value=None, comm=None, *, buffer=None, constant=None, name=None, prefix=None)[source]

Bases: Tensor

A scalar value.

DEFAULT_DTYPE = dtype('float64')
DEFAULT_PREFIX = 'scalar'
as_array(mode)[source]

Return a view of the scalar’s buffer.

Parameters:

mode – The access mode: read-only, write-only, or read-write.

Returns:

A view of the buffer with the requested access mode.

Return type:

numpy.ndarray

axis_trees = ()
buffer
property comm
concretize(*, linear=True)[source]
property constant
copy()[source]
dim = 0
get_instruction_executor_cache_key(visitor)[source]
getitem(*, strict=False)[source]
property local_max
property local_min
loop_axes = immutabledict({})
name
record_new(**attrs)

Create and initialise a new record from an existing one.

shape = (_UnitAxisTree(),)
size = 1
transform = None
property value
with_axis_trees(axis_trees)[source]

Module contents