Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename optional_packages_version to required_packages_version #7253

Merged
merged 16 commits into from
Jul 30, 2024
4 changes: 2 additions & 2 deletions monai/bundle/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(
self.ref_resolver = ReferenceResolver()
if config is None:
config = {self.meta_key: {}}
self.set(config=config)
self.set(config=self.ref_resolver.normalize_meta_id(config))

def __repr__(self):
return f"{self.config}"
Expand Down Expand Up @@ -221,7 +221,7 @@ def set(self, config: Any, id: str = "", recursive: bool = True) -> None:
if isinstance(conf_, dict) and k not in conf_:
conf_[k] = {}
conf_ = conf_[k if isinstance(conf_, dict) else int(k)]
self[ReferenceResolver.normalize_id(id)] = config
self[ReferenceResolver.normalize_id(id)] = self.ref_resolver.normalize_meta_id(config)

def update(self, pairs: dict[str, Any]) -> None:
"""
Expand Down
19 changes: 18 additions & 1 deletion monai/bundle/reference_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import Any, Iterator

from monai.bundle.config_item import ConfigComponent, ConfigExpression, ConfigItem
from monai.bundle.utils import ID_REF_KEY, ID_SEP_KEY
from monai.bundle.utils import DEPRECATED_ID_MAPPING, ID_REF_KEY, ID_SEP_KEY
from monai.utils import allow_missing_reference, look_up_option

__all__ = ["ReferenceResolver"]
Expand Down Expand Up @@ -202,6 +202,23 @@ def normalize_id(cls, id: str | int) -> str:
"""
return str(id).replace("#", cls.sep) # backward compatibility `#` is the old separator

def normalize_meta_id(self, config: Any) -> Any:
"""
Update deprecated identifiers in `config` using `DEPRECATED_ID_MAPPING`.
This will replace names that are marked as deprecated with their replacement.

Args:
config: input config to be updated.
"""
if isinstance(config, dict):
for _id, _new_id in DEPRECATED_ID_MAPPING.items():
if _id in config.keys():
warnings.warn(
f"Detected deprecated name '{_id}' in configuration file, replacing with '{_new_id}'."
)
config[_new_id] = config.pop(_id)
return config

@classmethod
def split_id(cls, id: str | int, last: bool = False) -> list[str]:
"""
Expand Down
4 changes: 3 additions & 1 deletion monai/bundle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"monai_version": _conf_values["MONAI"],
"pytorch_version": str(_conf_values["Pytorch"]).split("+")[0].split("a")[0], # 1.9.0a0+df837d0 or 1.13.0+cu117
"numpy_version": _conf_values["Numpy"],
"optional_packages_version": {},
"required_packages_version": {},
"task": "Describe what the network predicts",
"description": "A longer description of what the network does, use context, inputs, outputs, etc.",
"authors": "Your Name Here",
Expand Down Expand Up @@ -157,6 +157,8 @@

DEFAULT_EXP_MGMT_SETTINGS = {"mlflow": DEFAULT_MLFLOW_SETTINGS} # default experiment management settings

DEPRECATED_ID_MAPPING = {"optional_packages_version": "required_packages_version"}


def load_bundle_config(bundle_path: str, *config_names: str, **load_kw_args: Any) -> Any:
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/testing_data/data_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@
},
"configs": {
"test_meta_file": {
"url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
"url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json",
"hash_type": "md5",
"hash_val": "662135097106b71067cd1fc657f8720f"
"hash_val": "06954cad2cc5d3784e72077ac76f0fc8"
}
}
}
4 changes: 2 additions & 2 deletions tests/testing_data/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json",
"version": "0.1.0",
"changelog": {
"0.1.0": "complete the model package",
Expand All @@ -8,7 +8,7 @@
"monai_version": "0.9.0",
"pytorch_version": "1.10.0",
"numpy_version": "1.21.2",
"optional_packages_version": {
"required_packages_version": {
"nibabel": "3.2.1"
},
"task": "Decathlon spleen segmentation",
Expand Down
Loading