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

6721 bundle syntax # as alias of :: #6955

Merged
merged 6 commits into from
Sep 8, 2023
Merged

Conversation

wyli
Copy link
Contributor

@wyli wyli commented Sep 6, 2023

fixes #6721

Description

compatible syntax by normalising any # in ids to ::

from monai.bundle import ConfigParser

config = {
    "my_dims": 2,
    "dims_1": "$@my_dims + 1",
    "my_net": {"_target_": "BasicUNet", "spatial_dims": "@dims_1", "in_channels": 1, "out_channels": 4},
}
# in the example $@my_dims + 1 is an expression, which adds 1 to the value of @my_dims
parser = ConfigParser(config)
print(parser.get_parsed_content("my_net::spatial_dims"))  # returns 3
print(parser.get_parsed_content("my_net#spatial_dims"))  # returns 3

new test cases:

def test_slicing(self):
config = {"test": [1, 2, 3, 4], "test1": "$@test[::]", "test2": "$@test[::-1]", "st": "aten::relu"}
self.assertEqual(ConfigParser(config).test1, [1, 2, 3, 4])
self.assertEqual(ConfigParser(config).test2, [4, 3, 2, 1])
self.assertEqual(ConfigParser(config).st, "aten::relu")

Types of changes

  • 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.

@wyli wyli mentioned this pull request Sep 6, 2023
@ericspod
Copy link
Member

ericspod commented Sep 7, 2023

This is a simple solution but it appears to work just fine, we can assume there won't be comments ever so there's no issue removing #. An alternative is to use re.split(f"#|{ID_SEP_KEY}", str(id)) or something like this but it doesn't seem necessary.

Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
@wyli wyli marked this pull request as ready for review September 7, 2023 20:33
@wyli
Copy link
Contributor Author

wyli commented Sep 7, 2023

/integration-test

Copy link
Contributor

@KumoLiu KumoLiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me.

monai/bundle/reference_resolver.py Show resolved Hide resolved
@wyli
Copy link
Contributor Author

wyli commented Sep 8, 2023

/build

1 similar comment
@wyli
Copy link
Contributor Author

wyli commented Sep 8, 2023

/build

@wyli wyli merged commit 8040aa2 into Project-MONAI:dev Sep 8, 2023
31 of 32 checks passed
@wyli wyli deleted the 6721-replace branch September 8, 2023 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Syntax of Sigils
3 participants