Skip to content
Merged
3 changes: 3 additions & 0 deletions monai/bundle/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,11 @@ def run(

Args:
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.
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`.
Expand Down
5 changes: 5 additions & 0 deletions monai/bundle/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ class ConfigWorkflow(BundleWorkflow):

Args:
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.
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.
Expand Down Expand Up @@ -235,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:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_integration_bundle_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down