indextypes

Full Documentation for hippynn.graphs.indextypes package. Click here for a summary page.

Package for tracking node index state. The index state describes the meaning of the batch axis or axes for the tensor. i.e. system level, atom level, pair level.

class IdxType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Atoms = 'Atoms'
MolAtom = 'MolAtom'
MolAtomAtom = 'MolAtomAtom'
Molecules = 'Molecules'
NotFound = 'NOT FOUND'
Pair = 'Pair'
QuadMol = 'QuadMol'
QuadPack = 'QuadPack'
Scalar = 'Scalar'
clear_index_cache()[source]

Remove any cached index types for nodes.

The index cache holds global references to nodes that have been transformed automatically, so these nodes won’t be garbage collected automatically. Clearing the cache will free any reference to them.

If you modify the index dispatch table or type comparison table on the fly, you may want to clear the cache to remove references to nodes created using the old rules.

db_form(node)[source]

Return a node converted to the index state of the database.

elementwise_compare_reduce(*nodes_to_reduce)[source]

Return nodes converted to a mutually compatible index state with no padding.

Parameters:

nodes_to_reduce – nodes to put in a comparable, reduced index state

Returns:

node (if single argument) or tuple(nodes) (if multiple arguments)

get_reduced_index_state(*nodes_to_reduce)[source]

Find the index state for comparison between values in a loss function or plot.

Note

This function is unlikely to be directly needed as a user. it’s more likely you want to use elementwise_compare_reduce().

Parameters:

nodes_to_reduce

Returns:

index_type_coercion(node, output_index_state)[source]

Attempt to convert a node to a given index state.

Note

  1. If given a MultiNode, this function operates on the node’s main_output.

  2. If there is no IdxType on the node, this function is a no-op, so that if one has not been implemented, no error will be raised.

  3. If the index type already matches, then this function just returns the input node.

  4. If the index type doesn’t match, an index transformer of the appropriate type will be looked for. If no conversion is found, a ValueError is raised.

Parameters:
  • node – the node to convert

  • output_index_state – the index state to convert to.

Returns:

a node in the requested index state

register_index_transformer(input_idxstate, output_idxstate)[source]

Decorator for registering a transformer from one IdxType to another.

An index transformer should have a signature:

f(node) -> (parents, child_node_type)

with types:

node: Node
parents : Tuple[Node]
child_node_type : Union[Type[Node],Callable[[str,Tuple[node]],[node]]]

That is, the child_node_type can be a class of node, or a factory function which acts with the same signature as a node constructor. If f supports additional arguments, they must have default values, as it will be invoked by the automatic index transformation system as f(node).

The decorator results in a new function of type:

f(node: Node) -> Node

which is cached so that the same index transformation may be repeatedly applied to yield the same output node, and registered with the dispatch table for index transformations. No two functions may be registered for the same index type conversion simultaneously.

soft_index_type_coercion(node, output_index_state)[source]

Coerce if information is available.

Parameters:
  • node

  • output_index_state

Returns:

Submodules