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.visitors package

Submodules

pyop3.visitors.base module

class pyop3.visitors.base.Renamer(*, existing_type_store=None, existing_obj_store=None, allow_missing=True)[source]

Bases: object

Class for renaming things inside a visitor.

The class support two types of renaming: by type and by instance. This is because sometimes instance renaming is insufficient. For example you may have the axis label to hand but not the actual axis instance.

Note that each rename map is assumed to be distinct. No checking is performed to see if there are clashes.

add_obj(obj)[source]
add_type(type_, key)[source]

pyop3.visitors.comm module

pyop3.visitors.comm.common_comm(objects, **kwargs)[source]

Return a communicator valid for all objects.

The valid communicator is defined as the one with the largest size.

Parameters:

objects – Communicator-carrying objects to inspect. All object must define a comm attribute.

Returns:

A communicator that the provided objects are safely collective over.

Return type:

mpi4py.MPI.Comm

pyop3.visitors.comm.get_comm(obj, /)[source]
pyop3.visitors.comm.get_comm(comm, /)
pyop3.visitors.comm.get_comm(obj, /)
pyop3.visitors.comm.get_comm(sf, /)
pyop3.visitors.comm.get_comm(obj, /)
pyop3.visitors.comm.get_comm(_, /)
pyop3.visitors.comm.get_comm(_, /)
pyop3.visitors.comm.get_comm(_, /)
pyop3.visitors.comm.get_comm(_, /)
pyop3.visitors.comm.get_comm(_, /)
pyop3.visitors.comm.get_comm(_, /)
pyop3.visitors.comm.get_comm(iterable, /)
pyop3.visitors.comm.get_comm(iterable, /)
pyop3.visitors.comm.get_comm(mapping, /)
pyop3.visitors.comm.get_comm(set_, /)

Return the communicator associated with an object.

If no communicator is available (e.g. trying to get the comm of an integer) then COMM_SELF is used.

pyop3.visitors.comm.single_comm(*objects)[source]

Return the single comm shared by all objects.

pyop3.visitors.compress_indirections module

pyop3.visitors.compress_indirections.MAX_COST_CONSIDERATION_FACTOR = 3

Maximum factor an expression cost can exceed the minimum and still be considered.

pyop3.visitors.compress_indirections.MINIMUM_COST_TABULATION_THRESHOLD = 128

The minimum cost below which tabulation will not be considered.

Indirections with a cost below this are considered as fitting into cache and so memory optimisations are ineffectual.

pyop3.visitors.compress_indirections.materialize_indirections(insn, *, compress=False)[source]

pyop3.visitors.concretize module

class pyop3.visitors.concretize.ObjectConcretizer(*, reuse_results=True)[source]

Bases: NodeVisitor

process(obj, /)[source]
process(null, /)
process(exscan, /)
process(insn_list, /)
process(loop, /)
process(func, /)
process(assignment, /)
process(op, /, **kwargs)
process(var, /, **kwargs)
process(var, /, **kwargs)
process(var, /, **kwargs)
process(var, /, **kwargs)
process(scalar, /, **kwargs)
process(dat, /, *, axis_trees)
process(mat, /, *, axis_trees)
process(dat_expr, /, axis_trees)
process(dat_expr, /, axis_trees)
process(mat_expr, /, axis_trees)
pyop3.visitors.concretize.concretize(obj)[source]

‘Concretise’ all parts of obj.

An object is considered concretised if it does not contain any indexable objects (i.e. a \(Dat\) or \(Mat\)). This is an important step in code generation because it locks down things like the specific layout functions used to address things.

This function also trims expressions to remove any zero-sized parts.

pyop3.visitors.identity module

class pyop3.visitors.identity.IdentityVisitor(shallow=False, allowed_types=None)[source]

Bases: NodeVisitor

Visitor that reproduces an unchanged pyop3 object.

This class is intended to be subclassed by ‘reconstruction’ visitors that build similar objects.

process(obj, /, **kwargs)[source]
process(tree, /, **kwargs)
process(region, /, **kwargs)
process(component, /, **kwargs)
process(axis, /, **kwargs)
process(axis_tree, /, **kwargs)
process(forest, /, **kwargs)
process(loop_index, /, **kwargs)
process(scalar, /, **kwargs)
process(dat, /, **kwargs)
process(mat, /, **kwargs)
process(av, /, **kwargs)
process(liv, /, **kwargs)
process(dat_expr, /, **kwargs)
process(dat_expr, /, **kwargs)
process(cdat, /, **kwargs)
process(op, /, **kwargs)
process(tern, /, **kwargs)
process(obj, /, **kwargs)
process(obj, /, **kwargs)
process(transform, /, **kwargs)
process(loop, /, **kwargs)
process(assignment, /, **kwargs)
process(exscan, /, **kwargs)
process(func, /, **kwargs)
process(obj, /, **kwargs)
process(obj, /, **kwargs)
visit_path(path, **kwargs)[source]

pyop3.visitors.relabel module

class pyop3.visitors.relabel.Relabeler(relabel_map=None, *, allow_missing=None, shallow=False)[source]

Bases: IdentityVisitor

Visitor that relabels a pyop3 object.

Parameters:

relabel_map – Mapping from old to new names per type. If \(None\) then everything is numbered from zero.

property inverse_relabel_map
process(obj, /)[source]
process(region, /)
process(component, /)
process(axis, /)
process(axis_tree, /)
process(axis_tree, /)
process(axis_target, /)
process(cs_tree, /, **kwargs)
process(loop_index, /)
process(slice_, /)
process(scalar_index, /)
process(called_map, /)
process(map_, /)
process(map_, /)
process(map_component, /)
property relabel_map
visit_path(path)[source]
pyop3.visitors.relabel.relabel(obj, relabel_map, **kwargs)[source]

pyop3.visitors.replace module

class pyop3.visitors.replace.Replacer(shallow=False, allowed_types=None)[source]

Bases: IdentityVisitor

process(obj, /, **kwargs)[source]
process(obj, /, replace_map)
pyop3.visitors.replace.replace(obj, replace_map, *, assert_modified=False)[source]

Module contents

class pyop3.visitors.BufferCollector(*, reuse_results=True)[source]

Bases: NodeCollector

process(obj, /)[source]
process(obj, /)
process(obj, /)
process(obj, /)
class pyop3.visitors.CacheKeyGetter(recurse_vars=True)[source]

Bases: NodeVisitor

active_axis(label)[source]
active_loop_index(label)[source]
relabel_axis_tree_path(path)[source]
class pyop3.visitors.DiskCacheKeyGetter[source]

Bases: CacheKeyGetter

process(obj)[source]
process(obj, /)
process(obj, /)
process(obj, /)
class pyop3.visitors.MemoryCacheKeyGetter(*, identity_hash_outer_buffers=True, **kwargs)[source]

Bases: CacheKeyGetter

get_cache_key(obj, /, **kwargs)[source]
identity_hash_buffers()[source]
process(obj, /)[source]
process(obj, /)
process(obj, /)
process(obj)
pyop3.visitors.collect_buffers(obj)[source]
pyop3.visitors.get_cache_key(obj)[source]
pyop3.visitors.get_disk_cache_key(obj)[source]
pyop3.visitors.get_instruction_executor_cache_key(obj)[source]

This cache key is different to, say, a disk cache key because it happens at the start of a calculation Also we only care about the top-level input buffers - buffers from things like indirection maps aren’t considered replaceable because the idea is that we pass the input expression in here and get something back that we can reuse if we only change the top level buffers.

e.g. dat1.assign(dat2) is the same as dat3.assign(dat4) if dat1/dat2 have the same axis trees as dat3/dat4. We can reuse the indirection maps and preprocessing optimisations etc and just change the buffers at the top-level.