definition_helpers module

Full Documentation for hippynn.graphs.nodes.base.definition_helpers module. Click here for a summary page.

Tools for organizing node definitions.

Usage of these tools is optional; they support node definitions but are not required.

Note

The functions in this module are intended purely for defining new types of nodes. They are not strictly necessary; they only aid in defining more complex node behavior in a simple fashion.

exception TupleTypeMismatch[source]

Bases: Exception

class AlwaysMatch[source]

Bases: object

class AutoKw[source]

Bases: object

auto_module()[source]
class AutoNoKw[source]

Bases: object

auto_module()[source]
class CompatibleIdxTypeTransformer(form)[source]

Bases: FormTransformer

add_class_doc()[source]
static fn(node_self, *parents, **kwargs)[source]

Enforces that all parents have compatible index states.

class ExpandParentMeta[source]

Bases: type

class ExpandParents[source]

Bases: object

expand_parents(parents, *, purpose=None, **kwargs)[source]
class FormAssertLength(length)[source]

Bases: FormAssertion

add_class_doc()[source]
class FormAssertion(form)[source]

Bases: FormHandler

add_class_doc()[source]
class FormHandler[source]

Bases: object

add_class_doc()[source]
class FormTransformer(form, fn)[source]

Bases: FormHandler

add_class_doc()[source]
class IndexFormTransformer(form, idxstates)[source]

Bases: FormTransformer

add_class_doc()[source]
fn(node_self, *parents, **kwargs)[source]

Coerces index states for all parents

class MainOutputTransformer(form)[source]

Bases: FormTransformer

add_class_doc()[source]
static fn(node_self, *parents, **kwargs)[source]

Gets main_output of nodes: casts multinodes to single nodes

class ParentExpander[source]

Bases: object

Manager object to register and implement optional steps in building a graph node.

assertion(*form)[source]

Assert that the parents match a given form.

Parameters:

form

Returns:

assertlen(length)[source]

Assert that there are a given number of parents.

Parameters:

length

Returns:

Note

It is recommended only to use this function once as the final stage of expanding a node’s parents, to ensure that a node can be constructed directly from a satisfactory set of parents that doesn’t require any expansion.

get_main_outputs()[source]

Return the main outputs for any multinodes in the parents.

Returns:

match(*form)[source]

Decorator: the applied function will be a generic FormTransformer

matched_idx_coercion(form, needed_index_states)[source]

Apply coercion to the needed index states if the given form is present. :param form: :param needed_index_states: :return:

matchlen(length)[source]

Decorator: The decorated function will be applied if the number of parents matches the given length. :param length: :return:

require_compatible_idx_states()[source]

Ensure that all parents have commensurate index states. :return:

require_idx_states(*needed_index_states)[source]

Always coerce the nodes into a needed index state.

Parameters:

needed_index_states

Returns:

Note

It is recommended only to use this function once as the final stage of expanding a node’s parents, to ensure that a node can be constructed directly from a satisfactory set of parents that doesn’t require any expansion.

adds_to_forms(fn)[source]
format_form_name(form)[source]
temporary_parents(child, parents)[source]

Context manager for temporarily connecting a node to a set of parents. This is used during parent expansion so that find_relatives and find_unique_relatives can treat the nodes as connected even though they are not fully formed.

Parameters:
  • child

  • parents

Returns:

None