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.
- class AutoKw(*args, module='auto', module_kwargs=None, **kwargs)[source]
 Bases:
objectHelper class for piping keyword arguments into an nn.module class.
Keyword Argument sources (lower precedence first):
module_kwargs argument to init.
kwarg-source pairs from self.auto_module_kwargs, where the value for the source is popped from the kwargs to the node.
self.module_kwargs.
- Note: If self.auto_module_kwargs is not a dict, it will then be interpreted
 as a list of keys for a dictionary with the identity for key-value mapping.
After constructing the kwargs, they are saved as self.module_kwargs.
- auto_module_kwargs: Tuple[str] | Dict[str, str] | None = None
 
- class CompatibleIdxTypeTransformer(form)[source]
 Bases:
FormTransformer
- class ExpandParentMeta[source]
 Bases:
type- parent_expander: ParentExpander
 
- class ExpandParents(name, parents, *args, **kwargs)[source]
 Bases:
objectKeyword Argument sources (lower precedence first):
expansion_kwargs argument to init.
kwarg-source pairs from self.parent_expansion_kwargs, where the value for the source is popped from the kwargs to the node.
self.module_kwargs.
- If self.parent_expansion_kwargs is not a dictionary it will be interpreted as
 a list of keys for an identity key-value mapping.
- parent_expander: ParentExpander = <hippynn.graphs.nodes.base.definition_helpers.ParentExpander object>
 
- parent_expansion_kwargs: Tuple[str] | Dict[str, str] | None = None
 
- class FormAssertLength(length)[source]
 Bases:
FormAssertion
- class FormAssertion(form)[source]
 Bases:
FormHandler
- class FormTransformer(form, fn)[source]
 Bases:
FormHandler
- class IndexFormTransformer(form, idxstates)[source]
 Bases:
FormTransformer
- class MainOutputTransformer(form)[source]
 Bases:
FormTransformer
- class ParentExpander[source]
 Bases:
objectManager object to register and implement optional steps in building a graph node.
- 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.
- 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.
- 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