Skip to content

Commit f1ef3e8

Browse files
KumoLiuericspodmingxin-zheng
authored
Rename optional_packages_version to required_packages_version (#7253)
Fixes #6959. ### Description A few sentences describing the changes proposed in this pull request. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: KumoLiu <[email protected]> Signed-off-by: YunLiu <[email protected]> Co-authored-by: Eric Kerfoot <[email protected]> Co-authored-by: Mingxin Zheng <[email protected]>
1 parent 54019e4 commit f1ef3e8

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

monai/bundle/config_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def __init__(
118118
self.ref_resolver = ReferenceResolver()
119119
if config is None:
120120
config = {self.meta_key: {}}
121-
self.set(config=config)
121+
self.set(config=self.ref_resolver.normalize_meta_id(config))
122122

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

226226
def update(self, pairs: dict[str, Any]) -> None:
227227
"""

monai/bundle/reference_resolver.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from typing import Any, Iterator
1818

1919
from monai.bundle.config_item import ConfigComponent, ConfigExpression, ConfigItem
20-
from monai.bundle.utils import ID_REF_KEY, ID_SEP_KEY
20+
from monai.bundle.utils import DEPRECATED_ID_MAPPING, ID_REF_KEY, ID_SEP_KEY
2121
from monai.utils import allow_missing_reference, look_up_option
2222

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

205+
def normalize_meta_id(self, config: Any) -> Any:
206+
"""
207+
Update deprecated identifiers in `config` using `DEPRECATED_ID_MAPPING`.
208+
This will replace names that are marked as deprecated with their replacement.
209+
210+
Args:
211+
config: input config to be updated.
212+
"""
213+
if isinstance(config, dict):
214+
for _id, _new_id in DEPRECATED_ID_MAPPING.items():
215+
if _id in config.keys():
216+
warnings.warn(
217+
f"Detected deprecated name '{_id}' in configuration file, replacing with '{_new_id}'."
218+
)
219+
config[_new_id] = config.pop(_id)
220+
return config
221+
205222
@classmethod
206223
def split_id(cls, id: str | int, last: bool = False) -> list[str]:
207224
"""

monai/bundle/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"monai_version": _conf_values["MONAI"],
3737
"pytorch_version": str(_conf_values["Pytorch"]).split("+")[0].split("a")[0], # 1.9.0a0+df837d0 or 1.13.0+cu117
3838
"numpy_version": _conf_values["Numpy"],
39-
"optional_packages_version": {},
39+
"required_packages_version": {},
4040
"task": "Describe what the network predicts",
4141
"description": "A longer description of what the network does, use context, inputs, outputs, etc.",
4242
"authors": "Your Name Here",
@@ -157,6 +157,8 @@
157157

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

160+
DEPRECATED_ID_MAPPING = {"optional_packages_version": "required_packages_version"}
161+
160162

161163
def load_bundle_config(bundle_path: str, *config_names: str, **load_kw_args: Any) -> Any:
162164
"""

tests/testing_data/data_config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@
162162
},
163163
"configs": {
164164
"test_meta_file": {
165-
"url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
165+
"url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json",
166166
"hash_type": "md5",
167-
"hash_val": "662135097106b71067cd1fc657f8720f"
167+
"hash_val": "06954cad2cc5d3784e72077ac76f0fc8"
168168
}
169169
}
170170
}

tests/testing_data/metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
2+
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json",
33
"version": "0.1.0",
44
"changelog": {
55
"0.1.0": "complete the model package",
@@ -8,7 +8,7 @@
88
"monai_version": "0.9.0",
99
"pytorch_version": "1.10.0",
1010
"numpy_version": "1.21.2",
11-
"optional_packages_version": {
11+
"required_packages_version": {
1212
"nibabel": "3.2.1"
1313
},
1414
"task": "Decathlon spleen segmentation",

0 commit comments

Comments
 (0)