Adding new modules
The package is designed such that each module can be used as part of a pipeline (via the CLI or a configuration file) or independently (via importing them into an existing codebase).
In the future it may be desireable to add / adjust the modules of the package, this guide offers a high-level overview of how to do so.
Importing a module from this package
After installing the package, you can simply do:
and you will be able to use it in your code!Creating a new module and folding it into the CLI
The following instructions specify how to extend this package with a new module:
- Create a folder for your module within the package, i.e.
src/nhssynth/modules/mymodule
-
Include within it a main executor function that accepts arguments from the CLI, i.e.
In
mymodule/executor.py
and export it by addingfrom .executor import myexecutor
tomymodule/__init__.py
. Check the existing modules for examples of what a typical executor function looks like. -
In the
cli
folder, add a corresponding function tomodule_arguments.py
and populate with arguments you want to expose in the CLI: -
Next, in
module_setup.py
make the following adjustments to theMODULE_MAP
code:MODULE_MAP = { ... "mymodule": ModuleConfig( func=m.mymodule.myexecutor, add_args=ma.add_mymodule_args, description="...", help="...", common_parsers=[...] ), ... }
Where
common_parsers
is a subset ofCOMMON_PARSERS
defined incommon_arguments.py
. Note that the "seed" and "core" parsers are added automatically, so you don't need to specify them. These parsers can be used to add arguments to your module that are common to multiple modules, e.g. thedataloader
andevaluation
modules both use--typed
to specify the path of the typed input dataset. -
You can (optionally) also edit the following block if you want your module to be included in a full pipeline run:
-
Congrats, your module is implemented within the CLI, its documentation etc. will now be built automatically and it can be referenced in configuration files!