From 2d08fb5e6f639bb4290e6998ca71b77b6f709da4 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Wed, 19 Apr 2023 16:49:13 +0800 Subject: [PATCH 1/5] [DLMED] add error message Signed-off-by: Nic Ma --- monai/bundle/workflows.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/monai/bundle/workflows.py b/monai/bundle/workflows.py index 5a5380057e..0281a9994a 100644 --- a/monai/bundle/workflows.py +++ b/monai/bundle/workflows.py @@ -148,8 +148,11 @@ class ConfigWorkflow(BundleWorkflow): Args: run_id: ID name of the expected config expression to run, default to "run". + the target config must contain this ID to run. init_id: ID name of the expected config expression to initialize before running, default to "initialize". + allow a config to have no `initialize` logic and the ID. final_id: ID name of the expected config expression to finalize after running, default to "finalize". + allow a config to have no `finalize` logic and the ID. meta_file: filepath of the metadata file, if it is a list of file paths, the content of them will be merged. Default to "configs/metadata.json", which is commonly used for bundles in MONAI model zoo. config_file: filepath of the config file, if it is a list of file paths, the content of them will be merged. @@ -209,6 +212,8 @@ def __init__( # the rest key-values in the _args are to override config content self.parser.update(pairs=override) self.init_id = init_id + if run_id not in self.parser: + raise ValueError(f"run ID '{run_id}' doesn't exist in the config file.") self.run_id = run_id self.final_id = final_id # set tracking configs for experiment management From d102770d7b00627d664cac86bfe981766635c785 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Wed, 19 Apr 2023 17:11:17 +0800 Subject: [PATCH 2/5] [DLMED] add test Signed-off-by: Nic Ma --- tests/test_integration_bundle_run.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_integration_bundle_run.py b/tests/test_integration_bundle_run.py index 2018ca801e..74ac93bc27 100644 --- a/tests/test_integration_bundle_run.py +++ b/tests/test_integration_bundle_run.py @@ -66,6 +66,9 @@ def test_tiny(self): # test both CLI entry "run" and "run_workflow" command_line_tests(cmd + ["run", "training", "--config_file", config_file]) command_line_tests(cmd + ["run_workflow", "--run_id", "training", "--config_file", config_file]) + with self.assertRaises(RuntimeError): + # test wrong run_id="run" + command_line_tests(cmd + ["run", "run", "--config_file", config_file]) @parameterized.expand([TEST_CASE_1, TEST_CASE_2]) def test_shape(self, config_file, expected_shape): From e18d584d442528a7fbdecc927b8f16e86a58f64c Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Wed, 19 Apr 2023 17:15:14 +0800 Subject: [PATCH 3/5] [DLMED] add doc-string Signed-off-by: Nic Ma --- monai/bundle/scripts.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index 44e92038b6..3220839567 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -625,8 +625,11 @@ def run( Args: run_id: ID name of the expected config expression to run, default to "run". + the target config must contain this ID to run. init_id: ID name of the expected config expression to initialize before running, default to "initialize". + allow a config to have no `initialize` logic and the ID. final_id: ID name of the expected config expression to finalize after running, default to "finalize". + allow a config to have no `finalize` logic and the ID. meta_file: filepath of the metadata file, if it is a list of file paths, the content of them will be merged. Default to "configs/metadata.json", which is commonly used for bundles in MONAI model zoo. config_file: filepath of the config file, if `None`, must be provided in `args_file`. From 024db644562d499032a9b54060e3f321e1bdbcfd Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Wed, 19 Apr 2023 17:25:38 +0800 Subject: [PATCH 4/5] [DLMED] fix CI test Signed-off-by: Nic Ma --- monai/bundle/scripts.py | 2 +- monai/bundle/workflows.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index 3220839567..0d0d9dab6c 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -625,7 +625,7 @@ def run( Args: run_id: ID name of the expected config expression to run, default to "run". - the target config must contain this ID to run. + to run the config, the target config must contain this ID. init_id: ID name of the expected config expression to initialize before running, default to "initialize". allow a config to have no `initialize` logic and the ID. final_id: ID name of the expected config expression to finalize after running, default to "finalize". diff --git a/monai/bundle/workflows.py b/monai/bundle/workflows.py index 0281a9994a..48e2944798 100644 --- a/monai/bundle/workflows.py +++ b/monai/bundle/workflows.py @@ -148,7 +148,7 @@ class ConfigWorkflow(BundleWorkflow): Args: run_id: ID name of the expected config expression to run, default to "run". - the target config must contain this ID to run. + to run the config, the target config must contain this ID. init_id: ID name of the expected config expression to initialize before running, default to "initialize". allow a config to have no `initialize` logic and the ID. final_id: ID name of the expected config expression to finalize after running, default to "finalize". @@ -212,8 +212,6 @@ def __init__( # the rest key-values in the _args are to override config content self.parser.update(pairs=override) self.init_id = init_id - if run_id not in self.parser: - raise ValueError(f"run ID '{run_id}' doesn't exist in the config file.") self.run_id = run_id self.final_id = final_id # set tracking configs for experiment management @@ -240,6 +238,8 @@ def run(self) -> Any: Run the bundle workflow, it can be a training, evaluation or inference. """ + if self.run_id not in self.parser: + raise ValueError(f"run ID '{self.run_id}' doesn't exist in the config file.") return self._run_expr(id=self.run_id) def finalize(self) -> Any: From 99d0cb1faa084367e38005c1b239cd7f966123c8 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Wed, 19 Apr 2023 18:47:52 +0800 Subject: [PATCH 5/5] [DLMED] update according to comments Signed-off-by: Nic Ma --- monai/bundle/scripts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index 0d0d9dab6c..637fbb12d8 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -627,9 +627,9 @@ def run( run_id: ID name of the expected config expression to run, default to "run". to run the config, the target config must contain this ID. init_id: ID name of the expected config expression to initialize before running, default to "initialize". - allow a config to have no `initialize` logic and the ID. + it's optional for both configs and this `run` function. final_id: ID name of the expected config expression to finalize after running, default to "finalize". - allow a config to have no `finalize` logic and the ID. + it's optional for both configs and this `run` function. meta_file: filepath of the metadata file, if it is a list of file paths, the content of them will be merged. Default to "configs/metadata.json", which is commonly used for bundles in MONAI model zoo. config_file: filepath of the config file, if `None`, must be provided in `args_file`.