Repository: Project-MONAI/MONAI

Issue:
Modify `TrainProperties` in `monai.bundle.properties`
"train_dataset_data.BundleProperty.REQUIRED" should be `False` to support datasets in `monai.apps.datasets`.

related discussion:
https://github.com/Project-MONAI/model-zoo/pull/452#issuecomment-1584810096


Discussion:
same for `dataset_data` in `InferProperties`
An issue in:
https://github.com/Project-MONAI/MONAI/blob/e6ec945e4b87b90835cdad29ea64b1f27b8accda/monai/bundle/workflows.py#L374

local variable `ref` may not be assigned, but has to be referenced.

Resolving patch:
diff --git a/monai/bundle/properties.py b/monai/bundle/properties.py
--- a/monai/bundle/properties.py
+++ b/monai/bundle/properties.py
@@ -58,16 +58,17 @@
         BundleProperty.REQUIRED: True,
         BundlePropertyConfig.ID: f"train{ID_SEP_KEY}dataset",
     },
-    "train_dataset_data": {
-        BundleProperty.DESC: "data source for the training dataset.",
-        BundleProperty.REQUIRED: True,
-        BundlePropertyConfig.ID: f"train{ID_SEP_KEY}dataset{ID_SEP_KEY}data",
-    },
     "train_inferer": {
         BundleProperty.DESC: "MONAI Inferer object to execute the model computation in training.",
         BundleProperty.REQUIRED: True,
         BundlePropertyConfig.ID: f"train{ID_SEP_KEY}inferer",
     },
+    "train_dataset_data": {
+        BundleProperty.DESC: "data source for the training dataset.",
+        BundleProperty.REQUIRED: False,
+        BundlePropertyConfig.ID: f"train{ID_SEP_KEY}dataset{ID_SEP_KEY}data",
+        BundlePropertyConfig.REF_ID: None,  # no reference to this ID
+    },
     "train_handlers": {
         BundleProperty.DESC: "event-handlers for the training logic.",
         BundleProperty.REQUIRED: False,
@@ -169,11 +170,6 @@
         BundleProperty.REQUIRED: True,
         BundlePropertyConfig.ID: "dataset",
     },
-    "dataset_data": {
-        BundleProperty.DESC: "data source for the inference / evaluation dataset.",
-        BundleProperty.REQUIRED: True,
-        BundlePropertyConfig.ID: f"dataset{ID_SEP_KEY}data",
-    },
     "evaluator": {
         BundleProperty.DESC: "inference / evaluation workflow engine.",
         BundleProperty.REQUIRED: True,
@@ -189,6 +185,12 @@
         BundleProperty.REQUIRED: True,
         BundlePropertyConfig.ID: "inferer",
     },
+    "dataset_data": {
+        BundleProperty.DESC: "data source for the inference / evaluation dataset.",
+        BundleProperty.REQUIRED: False,
+        BundlePropertyConfig.ID: f"dataset{ID_SEP_KEY}data",
+        BundlePropertyConfig.REF_ID: None,  # no reference to this ID
+    },
     "handlers": {
         BundleProperty.DESC: "event-handlers for the inference / evaluation logic.",
         BundleProperty.REQUIRED: False,
diff --git a/monai/bundle/workflows.py b/monai/bundle/workflows.py
--- a/monai/bundle/workflows.py
+++ b/monai/bundle/workflows.py
@@ -371,6 +371,7 @@ def _check_optional_id(self, name: str, property: dict) -> bool:
             # no ID of reference config item, skipping check for this optional property
             return True
         # check validation `validator` and `interval` properties as the handler index of ValidationHandler is unknown
+        ref: str | None = None
         if name in ("evaluator", "val_interval"):
             if f"train{ID_SEP_KEY}handlers" in self.parser:
                 for h in self.parser[f"train{ID_SEP_KEY}handlers"]:
diff --git a/monai/utils/enums.py b/monai/utils/enums.py
--- a/monai/utils/enums.py
+++ b/monai/utils/enums.py
@@ -671,6 +671,7 @@ class BundlePropertyConfig(StrEnum):
     additional bundle property fields for config based bundle workflow:
     `ID` is the config item ID of the property.
     `REF_ID` is the ID of config item which is supposed to refer to this property.
+    For properties that do not have `REF_ID`, `None` should be set.
     this field is only useful to check the optional property ID.
     """
 


Test patch: