pyop2 package

Subpackages

Submodules

pyop2.caching module

pyop2.compilation module

pyop2.configuration module

PyOP2 global configuration.

class pyop2.configuration.Configuration

Bases: dict

PyOP2 configuration parameters

Parameters:
  • cc – C compiler (executable name eg: gcc or path eg: /opt/gcc/bin/gcc).

  • cxx – C++ compiler (executable name eg: g++ or path eg: /opt/gcc/bin/g++).

  • ld – Linker (executable name ld or path eg: /opt/gcc/bin/ld).

  • cflags – extra flags to be passed to the C compiler.

  • cxxflags – extra flags to be passed to the C++ compiler.

  • ldflags – extra flags to be passed to the linker.

  • simd_width – number of doubles in SIMD instructions (e.g. 4 for AVX2, 8 for AVX512).

  • debug – Turn on debugging for generated code (turns off compiler optimisations).

  • type_check – Should PyOP2 type-check API-calls? (Default, yes)

  • check_src_hashes – Should PyOP2 check that generated code is the same on all processes? (Default, yes). Uses an allreduce.

  • cache_dir – Where should generated code be cached?

  • node_local_compilation

    Should generated code by compiled “node-local” (one process for each set of processes that share

    a filesystem)? You should probably arrange to set cache_dir to a node-local filesystem too.

  • log_level – How chatty should PyOP2 be? Valid values are “DEBUG”, “INFO”, “WARNING”, “ERROR”, “CRITICAL”.

  • print_cache_size – Should PyOP2 print the cache information at program exit?

  • matnest – Should matrices on mixed maps be built as nests? (Default yes)

  • block_sparsity – Should sparsity patterns on datasets with cdim > 1 be built as block sparsities, or dof sparsities. The former saves memory but changes which preconditioners are available for the resulting matrices. (Default yes)

  • spmd_strict – Enable barriers for calls marked with @collective and for cache access. This adds considerable overhead, but is useful for tracking down deadlocks. (Default no)

cache_dir = '/tmp/pyop2-cache-uid1001'
DEFAULTS = {'block_sparsity': ('PYOP2_BLOCK_SPARSITY', <class 'bool'>, True), 'cache_dir': ('PYOP2_CACHE_DIR', <class 'str'>, '/tmp/pyop2-cache-uid1001'), 'cc': ('PYOP2_CC', <class 'str'>, ''), 'cflags': ('PYOP2_CFLAGS', <class 'str'>, ''), 'check_src_hashes': ('PYOP2_CHECK_SRC_HASHES', <class 'bool'>, True), 'compute_kernel_flops': ('PYOP2_COMPUTE_KERNEL_FLOPS', <class 'bool'>, False), 'cxx': ('PYOP2_CXX', <class 'str'>, ''), 'cxxflags': ('PYOP2_CXXFLAGS', <class 'str'>, ''), 'debug': ('PYOP2_DEBUG', <class 'bool'>, False), 'ld': ('PYOP2_LD', <class 'str'>, ''), 'ldflags': ('PYOP2_LDFLAGS', <class 'str'>, ''), 'log_level': ('PYOP2_LOG_LEVEL', (<class 'str'>, <class 'int'>), 'WARNING'), 'matnest': ('PYOP2_MATNEST', <class 'bool'>, True), 'no_fork_available': ('PYOP2_NO_FORK_AVAILABLE', <class 'bool'>, False), 'node_local_compilation': ('PYOP2_NODE_LOCAL_COMPILATION', <class 'bool'>, True), 'print_cache_info': ('PYOP2_CACHE_INFO', <class 'bool'>, False), 'simd_width': ('PYOP2_SIMD_WIDTH', <class 'int'>, 4), 'spmd_strict': ('PYOP2_SPMD_STRICT', <class 'bool'>, False), 'type_check': ('PYOP2_TYPE_CHECK', <class 'bool'>, True)}

Default values for PyOP2 configuration parameters

reset()

Reset the configuration parameters to the default values.

reconfigure(**kwargs)

Update the configuration parameters with new values.

unsafe_reconfigure(**kwargs)

“Unsafely reconfigure (just replacing the values)

pyop2.datatypes module

pyop2.datatypes.as_cstr(dtype)

Convert a numpy dtype like object to a C type as a string.

pyop2.datatypes.as_ctypes(dtype)

Convert a numpy dtype like object to a ctypes type.

pyop2.datatypes.as_numpy_dtype(dtype)

Convert a dtype-like object into a numpy dtype.

pyop2.datatypes.dtype_limits(dtype)

Attempt to determine the min and max values of a datatype.

Parameters:

dtype – A numpy datatype.

Returns:

a 2-tuple of min, max

Raises:

ValueError – If numeric limits could not be determined.

class pyop2.datatypes.OpaqueType(name)

Bases: OpaqueType

pyop2.exceptions module

OP2 exception types

exception pyop2.exceptions.DataTypeError

Bases: TypeError

Invalid type for data.

exception pyop2.exceptions.DimTypeError

Bases: TypeError

Invalid type for dimension.

exception pyop2.exceptions.ArityTypeError

Bases: TypeError

Invalid type for arity.

exception pyop2.exceptions.IndexTypeError

Bases: TypeError

Invalid type for index.

exception pyop2.exceptions.NameTypeError

Bases: TypeError

Invalid type for name.

exception pyop2.exceptions.SetTypeError

Bases: TypeError

Invalid type for pyop2.op2.Set.

exception pyop2.exceptions.SizeTypeError

Bases: TypeError

Invalid type for size.

exception pyop2.exceptions.SubsetIndexOutOfBounds

Bases: TypeError

Out of bound index.

exception pyop2.exceptions.SparsityTypeError

Bases: TypeError

Invalid type for pyop2.op2.Sparsity.

exception pyop2.exceptions.MapTypeError

Bases: TypeError

Invalid type for pyop2.op2.Map.

exception pyop2.exceptions.DataSetTypeError

Bases: TypeError

Invalid type for pyop2.op2.DataSet.

exception pyop2.exceptions.MatTypeError

Bases: TypeError

Invalid type for pyop2.op2.Mat.

exception pyop2.exceptions.DatTypeError

Bases: TypeError

Invalid type for pyop2.op2.Dat.

exception pyop2.exceptions.KernelTypeError

Bases: TypeError

Invalid type for pyop2.op2.Kernel.

exception pyop2.exceptions.DataValueError

Bases: ValueError

Illegal value for data.

exception pyop2.exceptions.IndexValueError

Bases: ValueError

Illegal value for index.

exception pyop2.exceptions.ModeValueError

Bases: ValueError

Illegal value for mode.

exception pyop2.exceptions.IterateValueError

Bases: ValueError

Illegal value for iterate.

exception pyop2.exceptions.SetValueError

Bases: ValueError

Illegal value for pyop2.op2.Set.

exception pyop2.exceptions.MapValueError

Bases: ValueError

Illegal value for pyop2.op2.Map.

exception pyop2.exceptions.ConfigurationError

Bases: RuntimeError

Illegal configuration value or type.

exception pyop2.exceptions.CompilationError

Bases: RuntimeError

Error during JIT compilation

exception pyop2.exceptions.SparsityFormatError

Bases: ValueError

Unable to produce a sparsity for this matrix format.

exception pyop2.exceptions.CachingError

Bases: ValueError

A caching error.

exception pyop2.exceptions.HashError

Bases: CachingError

Something is wrong with the hash.

pyop2.global_kernel module

pyop2.local_kernel module

pyop2.logger module

The PyOP2 logger, based on the Python standard library logging module.

pyop2.logger.set_log_level(level)

Set the log level of the PyOP2 logger.

Parameters:

level – the log level. Valid values: DEBUG, INFO, WARNING, ERROR, CRITICAL

pyop2.logger.log(level, msg, *args, **kwargs)

Print ‘msg % args’ with the severity ‘level’.

Parameters:
  • level – the log level. Valid values: DEBUG, INFO, WARNING, ERROR, CRITICAL

  • msg – the message

pyop2.logger.progress(level, msg, *args, **kwargs)

A context manager to print a progress message.

The block is wrapped in msg..., msg...done log messages with an appropriate indent (to distinguish nested message).

Parameters:
  • level – the log level. See log() for valid values

  • msg – the message.

See log() for more details.

pyop2.mpi module

PyOP2 MPI communicator.

pyop2.mpi.internal_comm(comm, obj)

Creates an internal comm from the user comm. If comm is None, create an internal communicator from COMM_WORLD :arg comm: A communicator or None :arg obj: The object which the comm is an attribute of (usually self)

Returns pyop2_comm:

A PyOP2 internal communicator

pyop2.mpi.is_pyop2_comm(comm)

Returns True if comm is a PyOP2 communicator, False if comm another communicator. Raises exception if comm is not a communicator.

Parameters:

comm – Communicator to query

pyop2.mpi.incref(comm)

Increment communicator reference count

pyop2.mpi.decref(comm)

Decrement communicator reference count

class pyop2.mpi.temp_internal_comm(comm)

Bases: object

Use a PyOP2 internal communicator and increment and decrement the internal comm. :arg comm: Any communicator

pyop2.op2 module

pyop2.parloop module

pyop2.profiling module

pyop2.profiling.timed_stage()

Enter a code Stage, this is a PETSc log Stage.

Parameters:

name – The name of the stage.

pyop2.profiling.timed_region()

Time a code region, this a PETSc log Event.

Parameters:

name – The name of the region.

class pyop2.profiling.timed_function(name=None)

Bases: object

pyop2.sparsity module

pyop2.utils module

Common utility classes/functions.

pyop2.utils.as_tuple(item, type=None, length=None, allow_none=False)
pyop2.utils.as_type(obj, typ)

Return obj if it is of dtype typ, otherwise return a copy type-cast to typ.

pyop2.utils.tuplify(xs)

Turn a data structure into a tuple tree.

class pyop2.utils.validate_base(*checks)

Bases: object

Decorator to validate arguments

Formal parameters that don’t exist in the definition of the function being decorated as well as actual arguments not being present when the validation is called are silently ignored.

check_args(args, kwargs)
class pyop2.utils.validate_type(*checks)

Bases: validate_base

Decorator to validate argument types

The decorator expects one or more arguments, which are 3-tuples of (name, type, exception), where name is the argument name in the function being decorated, type is the argument type to be validated and exception is the exception type to be raised if validation fails.

check_arg(arg, argtype, exception)
class pyop2.utils.validate_in(*checks)

Bases: validate_base

Decorator to validate argument is in a set of valid argument values

The decorator expects one or more arguments, which are 3-tuples of (name, list, exception), where name is the argument name in the function being decorated, list is the list of valid argument values and exception is the exception type to be raised if validation fails.

check_arg(arg, values, exception)
class pyop2.utils.validate_range(*checks)

Bases: validate_base

Decorator to validate argument value is in a given numeric range

The decorator expects one or more arguments, which are 3-tuples of (name, range, exception), where name is the argument name in the function being decorated, range is a 2-tuple defining the valid argument range and exception is the exception type to be raised if validation fails.

check_arg(arg, range, exception)
class pyop2.utils.validate_dtype(*checks)

Bases: validate_base

Decorator to validate argument value is in a valid Numpy dtype

The decorator expects one or more arguments, which are 3-tuples of (name, _, exception), where name is the argument name in the function being decorated, second argument is ignored and exception is the exception type to be raised if validation fails.

check_arg(arg, ignored, exception)
pyop2.utils.verify_reshape(data, dtype, shape, allow_none=False)

Verify data is of type dtype and try to reshaped to shape.

pyop2.utils.align(bytes, alignment=16)

Align BYTES to a multiple of ALIGNMENT

pyop2.utils.flatten(iterable)

Flatten a given nested iterable.

pyop2.utils.parser(description=None, group=False)

Create default argparse.ArgumentParser parser for pyop2 programs.

pyop2.utils.parse_args(*args, **kwargs)

Return parsed arguments as variables for later use.

ARGS and KWARGS are passed into the parser instantiation. The only recognised options are group and description.

pyop2.utils.trim(docstring)

Trim a docstring according to PEP 257.

pyop2.utils.strip(code)
pyop2.utils.get_petsc_dir()

pyop2.version module

Module contents