graphviper.graph_tools.reduce
Attributes
Functions
|
Appends a reduce step to the graph created by the |
Module Contents
- reduce(graph: Dict, reduce_node_task: Callable[Ellipsis, Any], input_params: Dict, mode: {'tree', 'single_node', 'tree_n'} = 'tree', n_batch: int = 2) Dict[source]
Appends a reduce step to the graph created by the
graphviper.graph_tools.map(). function.- Parameters:
graph (Dict) – Graph produced by
graphviper.graph_tools.map().reduce_node_task (Callable[..., Any]) – The function that forms the nodes in the reduce portion of the graph must have two parameters:
input_dataandinput_params. Theinput_datarepresents the output from the mapping nodes, whileinput_paramscomes from thereduceparameter with the same name.input_params (Dict) – The input parameters to be passed to
node_task.mode ({"tree","single_node","tree_n"}, optional) –
single_node: The output from all map nodes is sent to a single node,tree: The outputs are combined using a binary tree reduction (each reduce node combines two inputs), by default “tree”.tree_n: The outputs are combined using a tree reduction in which each reduce node combinesn_batchinputs per layer, repeating layer by layer until a single node remains.n_batch=2reproducestree; a largen_batchreduces the number of layers (shallower tree, more inputs combined per node) trending towardsingle_nodebehaviour.
n_batch (int, optional) – Number of inputs combined by each reduce node, per layer, when
mode="tree_n". Must be>= 2(validated unconditionally so a meaningless value can never be recorded on the graph). Used only bymode="tree_n"; the other modes ignore it. Default 2.
- Returns:
The input
graphdict with an added"reduce"entry ({"mode", "node_task", "input_params", "n_batch"}) describing the reduce step. Nodask.delayedobjects are constructed here; the actual reduce tree is built later bygraphviper.graph_tools.generate_dask_workflow()(or executed bygraphviper.graph_tools.processes_with_mpi()).- Return type:
Dict
- Raises:
ValueError – If
modeis not one of{"tree", "single_node", "tree_n"}, or ifn_batchis not an integer>= 2(boolis rejected too).
Notes
The chosen
mode/n_batchare recorded on the graph and honoured by both execution backends:graphviper.graph_tools.generate_dask_workflow()(builds the correspondingdask.delayedreduce tree) andgraphviper.graph_tools.processes_with_mpi()(applies the same fan-in when reducing the gathered map results).