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

Deep update of specs in Lancium adapter #276

Merged
merged 19 commits into from
Jan 13, 2023

Conversation

giffels
Copy link
Member

@giffels giffels commented Jan 9, 2023

Currently, the spec dictionary in the Lancium adapter is not "deeply" updated. For example:

TARDIS is setting up the Drone specific environment in the spec dictionary:

spec = {"environment": [{"value": "8", "variable": "TardisDroneCores"},
                                        {"value": "20", "variable": "TardisDroneMemory"},
                                        {"value": "20", "variable": "TardisDroneDisk"},
                                        {"value": "testsite-089123", "variable": "TardisDroneUuid"}]
            }

However, if the user decides to set-up a specific environment in the configuration, like:

spec = {"environment": {"value": "T1_DE_KIT/KIT-Lancium",
                                        "variable": "SITECONFIG_PATH"},
            }

this is currently going to overwrite the environment specfied by TARDIS.

This pull request uses a deep update function to ensure, that the environment is updated instead of being overwritten.

@giffels giffels force-pushed the fix-lancium-adapter branch 3 times, most recently from 4545341 to 124ba18 Compare January 9, 2023 15:59
@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2023

Codecov Report

Base: 98.88% // Head: 98.88% // No change to project coverage 👍

Coverage data is based on head (a6566c4) compared to base (3f88e76).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #276   +/-   ##
=======================================
  Coverage   98.88%   98.88%           
=======================================
  Files          56       56           
  Lines        2325     2325           
=======================================
  Hits         2299     2299           
  Misses         26       26           
Impacted Files Coverage Δ
tardis/adapters/sites/lancium.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@giffels giffels marked this pull request as ready for review January 9, 2023 16:09
@giffels giffels requested review from a team, rfvc, RHofsaess and maxfischer2781 and removed request for a team January 9, 2023 16:09
Copy link
Member

@maxfischer2781 maxfischer2781 left a comment

Choose a reason for hiding this comment

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

I've added some comments on the deep_update implementations. I'm very certain on the typing considerations but feel free to ignore the algorithm suggestions/changes.

tardis/utilities/utils.py Outdated Show resolved Hide resolved
Comment on lines 74 to 75
original_mapping: Mapping[KeyType, Any],
mapping_update: Mapping[KeyType, Any],
Copy link
Member

Choose a reason for hiding this comment

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

I think technically the original must be MutableMapping since we need to change items in the copy. Consider to even restrict it to Dict since that's what is substituted at some points and you also special-case List (instead of Sequence).
For mapping_update it's fine.

In the interest of generality, you might want to support List as well – that would allow a recursive deep_update into lists as well. Only if you want the extra work, though...

Copy link
Member Author

Choose a reason for hiding this comment

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

I have changed the original to MutableMapping. I thought to support List's as well, however I concluded that there is currently no need for it , so I decided to implement only the minimal solution working for us.

tardis/utilities/utils.py Outdated Show resolved Hide resolved
tardis/utilities/utils.py Outdated Show resolved Hide resolved
tardis/utilities/utils.py Outdated Show resolved Hide resolved
tardis/utilities/utils.py Outdated Show resolved Hide resolved
tardis/utilities/utils.py Outdated Show resolved Hide resolved
tests/utilities_t/test_utils.py Outdated Show resolved Hide resolved
tests/utilities_t/test_utils.py Outdated Show resolved Hide resolved
@giffels
Copy link
Member Author

giffels commented Jan 10, 2023

I've added some comments on the deep_update implementations. I'm very certain on the typing considerations but feel free to ignore the algorithm suggestions/changes.

Thank you @maxfischer2781 for the in depth review. I will change things or reply to the inline comments otherwise.

maxfischer2781
maxfischer2781 previously approved these changes Jan 11, 2023
Copy link
Member

@maxfischer2781 maxfischer2781 left a comment

Choose a reason for hiding this comment

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

Feel free to update the master.

maxfischer2781
maxfischer2781 previously approved these changes Jan 11, 2023
Copy link
Member

@maxfischer2781 maxfischer2781 left a comment

Choose a reason for hiding this comment

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

maxfischer2781 force-approved the fix-lancium-adapter branch

elif isinstance(value, list):
updated_mapping[key] = deepcopy(original_mapping.get(key, []))
# do not duplicate entries which are already in the list
updated_mapping[key].extend(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is extend really what I expect deep_update to do? Running

original_mapping = {"foo": [1, 2, 3], "bar": "baz"}
mapping_update = {"foo": [4, 5, 6]}
updated_mapping = deep_update(original_mapping, mapping_update)

I naively would expect updated_mapping to be {"foo": [4, 5, 6], "bar": "baz"} and not {"foo": [1, 2, 3, 4, 5, 6], "bar": "baz"}. This behavior I could achieve by explicitly running

original_mapping = {"foo": [1, 2, 3], "bar": "baz"}
mapping_update = {"foo": list(set(original_mapping["foo"] + [4, 5, 6]))}
updated_mapping = deep_update(original_mapping, mapping_update)

Maybe this can be accomplished by explicitly setting some extend_lists-flag (possibly with True as default) in the call of deep_update?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think to implement deep_update was not a very wise idea and I am not happy with it as well. It seems to be prone to errors and to misunderstandings. Since, we know exactly what needs to be appended or overwritten in the Lancium SiteAdapter, I will implement it "manually" in the adapter itself following KISS.

Copy link
Member

Choose a reason for hiding this comment

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

Have to agree that using an implementation specific to Lancium instead of trying to formulate a generic case seems more appropriate, given how many edge cases we run into otherwise. 😕

@giffels giffels force-pushed the fix-lancium-adapter branch from 37b6d03 to a6566c4 Compare January 13, 2023 09:11
Copy link
Member

@maxfischer2781 maxfischer2781 left a comment

Choose a reason for hiding this comment

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

That's... simpler. 😁

Copy link
Contributor

@rfvc rfvc left a comment

Choose a reason for hiding this comment

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

I agree with @maxfischer2781, that looks a lot simpler 😅 Thanks @giffels!

@giffels giffels merged commit a7c4c30 into MatterMiners:master Jan 13, 2023
@giffels giffels deleted the fix-lancium-adapter branch January 13, 2023 12:35
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.

4 participants