Helpers#

Base class for helper module methods.

class ivy.stateful.helpers.ModuleHelpers[source]#

Bases: ABC

check_submod_rets()[source]#

Return True if there is an expected submodule return value set by the user during the call.

Returns:

ret – True if the top module has expected_submod_rets.

get_mod_key(*, top_mod=None)[source]#

Get the key of current module to be used when checking or tracking the return values of a submodule.

Parameters:

top_mod – Explicit indicate the top module. None for the top module of current module. Default is None.

Returns:

A string of current module key.

mod_depth()[source]#

Return the depth of the current module. Return 0 for root module.

Returns:

ret – The depth of the module in the network.

mod_height()[source]#

Return the height of the network, with the current level being 0.

Returns:

ret – The height of the network. 0 if the are no submodules.

mod_with_top_mod_key_chain(*, depth=None, flatten_key_chain=False)[source]#

Return a list containing the modules of the network starting from the top module, and ending with the current module.

Parameters:
  • depth – If specified, will return a list of modules of length starting at the current module and ending at the module at the specified depth. 0 for the current module. 1 for the iimediate parent module. None for the top module. Default is None.

  • flatten_key_chain – If set True, will return return a flat container, with all nested key-chains flattened. Default is False.

show_mod_in_top_mod(*, upper_depth=None, lower_depth=None, flatten_key_chains=False)[source]#

Show lower submodules in the top module. upper_depth and lower_depth are for controlling the coverage of upper and lower modules. Will give prompt if no top module found.

Parameters:
  • upper_depth – How many modules it tracks up as upper module. None for current module. Default is None. Will be truncated to mod_depth.

  • lower_depth – How many modules it tracks down. None for current module. Default is None. Will be truncated to mod_height.

  • flatten_key_chains – If set True, will return a flat (depth-1) container, which all nested key-chains flattened. Default is False.

show_structure()[source]#

Print the structure of the layer network.

Returns:

this_repr – String of the structure of the module.

show_v_in_top_v(*, depth=None)[source]#

Show sub containers from the perspective of the top layer. Will give prompt if either of v or top_v is not initialized.

Parameters:

depth – The number of modules we want to step in. None for the value of current module. Default is None.

sub_mods(*, show_v=True, depth=None, flatten_key_chains=False)[source]#

Return a container comoposed of all submodules.

Parameters:
  • show_v – If set True, will return values of all submodule variables. Default is True.

  • depth – How many layers we step in before beginning enumerating submodules. None for current layer. Default is None.

  • flatten_key_chains – If set True, will return a flat (depth-1) container, in which all nested key-chains flattened. Default is False.

Returns:

ret – A container composed of all submodules.

track_submod_call_order()[source]#

Tracks the order in which the submodules are called.

Returns:

ret – True if the current module allows call order tracking.

track_submod_rets()[source]#

Return True if the current module should have its returns tracked as set by the user during the call.

Returns:

ret – True if the returned values of the current module should be tracked.

v_with_top_v_key_chains(*, depth=None, flatten_key_chains=False)[source]#

Show the network’s variables from the perspective of value of top layer. Will give prompt if either of v and top_v is not initialized.

Parameters:
  • depth – The number of modules we want to step in. None for the value of current module. Default is None.

  • flatten_key_chains – If set True, will return a flat container, with all nested key-chains flattened. Default is False.