Skip to content

Commit

Permalink
Docstring runner loaders (#416)
Browse files Browse the repository at this point in the history
* doc(runner): updated docstrings for loaders and runner
  • Loading branch information
diwei-tan authored Aug 12, 2021
1 parent d79c08d commit 7739a3e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 16 deletions.
26 changes: 22 additions & 4 deletions peekingduck/configloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@


class ConfigLoader: # pylint: disable=too-few-public-methods
""" Reads configuration and returns configuration required to
create the nodes for the project
"""
A helper class to create pipeline.
The config loader class is used to allow for instantiation of Node classes
directly instead of reading configurations from the run config yaml.
Args:
basedir (:obj:`str`): base directory of peekingduck
"""

def __init__(self, basedir: str) -> None:
Expand All @@ -41,8 +49,18 @@ def _get_config_path(self, node: str) -> str:
return filepath

def get(self, node_name: str) -> Dict[str, Any]:
"""Get item from configuration read from the filepath,
item refers to the node item configuration you are trying to get"""
"""
Get node configuration for specified node.
Args:
node_name (:obj:`str`): name of node
Outputs:
node_config (:obj:`Dict`): dictionary of node configurations for the
specified node
"""

filepath = self._get_config_path(node_name)

Expand Down
23 changes: 22 additions & 1 deletion peekingduck/declarative_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,28 @@


class DeclarativeLoader: # pylint: disable=too-few-public-methods
"""Uses the declarative run_config.yml to load pipelines or compiled configs"""
"""
A helper class to create pipeline.
The declarative loader class creates the specified nodes according to any
modfications provided in the configs and returns the pipeline needed for
inference.
Args:
run_config (:obj:`str`): Path to yaml file that declares the node \
sequence to be used in the pipeline
config_updates_cli (:obj:`str`): stringified nested dictionaries of \
config changes passed as part of cli command. Used to modify the node \
configurations direct from cli.
custom_node_parent_folder (:obj:`str`): path to parent folder which contains \
custom nodes that users have created to be used with PeekingDuck. \
For more information on using custom nodes, please refer to \
`getting started <getting_started/03_custom_nodes.html>`_.
"""

def __init__(self,
run_config: str,
Expand Down
36 changes: 25 additions & 11 deletions peekingduck/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,37 @@


class Runner():
"""Runner class that uses the declared nodes to create pipeline to run inference
"""
The runner class for creation of pipeline using declared/given nodes.
The runner class uses the provided configurations to setup a node pipeline
which is used to run inference.
Args:
RUN_PATH (:obj:`str`): If path to a run_config.yml is provided, uses \
our declarative loader to load the yaml file according to our specified \
schema to obtain the declared nodes that would be sequentially \
initialized and used to create the pipeline for running inference. \
config_updates_cli (:obj:`str`): config changes passed as part of the \
cli command sed to modify the node configurations direct from cli.
CUSTOM_NODE_PARENT_FOLDER (:obj:`str`): path to folder which contains \
custom nodes that users have created to be used with PeekingDuck. \
For more information on using custom nodes, please refer to \
`getting started <getting_started/03_custom_nodes.html>`_.
nodes (:obj:`list` of :obj:`Node`): if not using declarations via yaml, \
initialize by giving the node stack directly as a list.
"""

def __init__(self,
RUN_PATH: str = "",
config_updates_cli: str = None,
CUSTOM_NODE_PARENT_FOLDER: str = None,
nodes: List[AbstractNode] = None):
"""
Args:
RUN_PATH (str): path to yaml file of node pipeine declaration.
config_updates_cli (str): stringified nested dictionaries of configs.
CUSTOM_NODE_PARENT_FOLDER (str): parent folder of the custom nodes folder.
nodes (:obj:'list' of :obj:'Node'): if not using declarations via yaml,
initialize by giving the node stack as a list
"""

self.logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -86,6 +100,6 @@ def get_run_config(self) -> List[str]:
"""retrieve run configs
Returns:
Dict[Any]: run configs being used for runner
(:obj:`Dict`: run configs being used for runner
"""
return self.node_loader.node_list

0 comments on commit 7739a3e

Please sign in to comment.