@@ -51,7 +51,7 @@ class BundleWorkflow(ABC):
5151 default to `None` for common workflow.
5252 properties_path: the path to the JSON file of properties. If `workflow_type` is specified, properties will be
5353 loaded from the file based on the provided `workflow_type` and meta. If no `workflow_type` is specified,
54- properties will default to loading from "train ". If the specified file is unavailable, default properties
54+ properties will default to loading from "meta ". If the specified file is unavailable, default properties
5555 will be sourced from "monai/bundle/properties.py" based on the workflow_type:
5656 For a training workflow, properties load from `TrainProperties` and `MetaProperties`.
5757 For a inference workflow, properties load from `InferProperties` and `MetaProperties`.
@@ -116,8 +116,7 @@ def __init__(
116116 if not properties_path .is_file ():
117117 raise ValueError (f"Property file { properties_path } does not exist." )
118118 if workflow_type is None :
119- workflow_type = "train"
120- logger .info ("No workflow type specified, default to 'train' for property file loading." )
119+ logger .info ("No workflow type specified, default to load meta properties from property file." )
121120 with open (properties_path ) as json_file :
122121 try :
123122 properties = json .load (json_file )
@@ -249,9 +248,13 @@ def check_properties(self) -> list[str] | None:
249248class PythonicWorkflow (BundleWorkflow ):
250249 """
251250 Base class for the pythonic workflow specification in bundle, it can be a training, evaluation or inference workflow.
252- It defines the basic interfaces for the bundle workflow behavior: `initialize`, `run`, ` finalize`, etc.
251+ It defines the basic interfaces for the bundle workflow behavior: `initialize`, `finalize`, etc.
253252 This also provides the interface to get / set public properties to interact with a bundle workflow through
254253 defined `get_<property>` accessor methods or directly defining members of the object.
254+ For how to set the properties, users can define the `_set_<property>` methods or directly set the members of the object.
255+ The `initialize` method is called to set up the workflow before running. This method sets up internal state and prepares properties.
256+ If properties are modified after the workflow has been initialized, `self._is_initialized` is set to `False`. Before running the
257+ workflow again, `initialize` should be called to ensure that the workflow is properly set up with the new property values.
255258
256259 Args:
257260 workflow_type: specifies the workflow type: "train" or "training" for a training workflow,
@@ -264,7 +267,7 @@ class PythonicWorkflow(BundleWorkflow):
264267 default to `None` for common workflow.
265268 properties_path: the path to the JSON file of properties. If `workflow_type` is specified, properties will be
266269 loaded from the file based on the provided `workflow_type` and meta. If no `workflow_type` is specified,
267- properties will default to loading from "train ". If the specified file is unavailable, default properties
270+ properties will default to loading from "meta ". If the specified file is unavailable, default properties
268271 will be sourced from "monai/bundle/properties.py" based on the workflow_type:
269272 For a training workflow, properties load from `TrainProperties` and `MetaProperties`.
270273 For a inference workflow, properties load from `InferProperties` and `MetaProperties`.
@@ -302,12 +305,14 @@ def __init__(
302305
303306 # the rest key-values in the _args are to override config content
304307 self .parser .update (pairs = override )
308+ self ._is_initialized : bool = False
305309
306310 def initialize (self , * args : Any , ** kwargs : Any ) -> Any :
307311 """
308312 Initialize the bundle workflow before running.
309313 """
310314 self ._props_vals = {}
315+ self ._is_initialized = True
311316
312317 def _get_property (self , name : str , property : dict ) -> Any :
313318 """
@@ -320,6 +325,8 @@ def _get_property(self, name: str, property: dict) -> Any:
320325 name: the name of target property.
321326 property: other information for the target property, defined in `TrainProperties` or `InferProperties`.
322327 """
328+ if not self ._is_initialized :
329+ raise RuntimeError ("Please execute 'initialize' before getting any properties." )
323330 value = None
324331 if name in self ._set_props_vals :
325332 value = self ._set_props_vals [name ]
@@ -343,7 +350,7 @@ def _get_property(self, name: str, property: dict) -> Any:
343350 def _set_property (self , name : str , property : dict , value : Any ) -> Any :
344351 """
345352 With specified property name and information, set value for the expected property.
346- Stores user-reset initialized objects that should not be re-initialized.
353+ Stores user-reset initialized objects that should not be re-initialized and marks the workflow as not initialized .
347354
348355 Args:
349356 name: the name of target property.
@@ -352,6 +359,7 @@ def _set_property(self, name: str, property: dict, value: Any) -> Any:
352359
353360 """
354361 self ._set_props_vals [name ] = value
362+ self ._is_initialized = False
355363
356364
357365class ConfigWorkflow (BundleWorkflow ):
0 commit comments