Skip to content

Commit 00c5c73

Browse files
6069 Add default metadata and logging values for bundle run (#6072)
Fixes #6069 . ### Description This PR adds commonly used default values for `meta_file` and `logging_file` of `monai.bundle.run` function. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Yiheng Wang <vennw@nvidia.com>
1 parent b30ea42 commit 00c5c73

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

monai/bundle/scripts.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def run(
617617
**override: Any,
618618
) -> list:
619619
"""
620-
Specify `meta_file` and `config_file` to run monai bundle components and workflows.
620+
Specify `config_file` to run monai bundle components and workflows.
621621
622622
Typical usage examples:
623623
@@ -642,10 +642,12 @@ def run(
642642
Args:
643643
runner_id: ID name of the expected config expression to run, can also be a list of IDs to run in order.
644644
meta_file: filepath of the metadata file, if it is a list of file paths, the content of them will be merged.
645+
Default to "configs/metadata.json", which is commonly used for bundles in MONAI model zoo.
645646
config_file: filepath of the config file, if `None`, must be provided in `args_file`.
646647
if it is a list of file paths, the content of them will be merged.
647-
logging_file: config file for `logging` module in the program, default to `None`. for more details:
648+
logging_file: config file for `logging` module in the program. for more details:
648649
https://docs.python.org/3/library/logging.config.html#logging.config.fileConfig.
650+
Default to "configs/logging.conf", which is commonly used for bundles in MONAI model zoo.
649651
tracking: enable the experiment tracking feature at runtime with optionally configurable and extensible.
650652
if "mlflow", will add `MLFlowHandler` to the parsed bundle with default logging settings,
651653
if other string, treat it as file path to load the logging settings, if `dict`,
@@ -719,18 +721,30 @@ def run(
719721
warnings.warn("`config_file` not provided for 'monai.bundle run'.")
720722
_log_input_summary(tag="run", args=_args)
721723
config_file_, meta_file_, runner_id_, logging_file_, tracking_ = _pop_args(
722-
_args, config_file=None, meta_file=None, runner_id="", logging_file=None, tracking=None
724+
_args,
725+
config_file=None,
726+
meta_file="configs/metadata.json",
727+
runner_id="",
728+
logging_file="configs/logging.conf",
729+
tracking=None,
723730
)
724731
if logging_file_ is not None:
725732
if not os.path.exists(logging_file_):
726-
raise FileNotFoundError(f"can't find the logging config file: {logging_file_}.")
727-
logger.info(f"set logging properties based on config: {logging_file_}.")
728-
fileConfig(logging_file_, disable_existing_loggers=False)
733+
if logging_file_ == "configs/logging.conf":
734+
warnings.warn("default logging file in 'configs/logging.conf' not exists, skip logging.")
735+
else:
736+
raise FileNotFoundError(f"can't find the logging config file: {logging_file_}.")
737+
else:
738+
logger.info(f"set logging properties based on config: {logging_file_}.")
739+
fileConfig(logging_file_, disable_existing_loggers=False)
729740

730741
parser = ConfigParser()
731742
parser.read_config(f=config_file_)
732743
if meta_file_ is not None:
733-
parser.read_meta(f=meta_file_)
744+
if not os.path.exists(meta_file_):
745+
warnings.warn("default meta file in 'configs/metadata.json' not exists.")
746+
else:
747+
parser.read_meta(f=meta_file_)
734748

735749
# the rest key-values in the _args are to override config content
736750
parser.update(pairs=_args)

0 commit comments

Comments
 (0)