-
Notifications
You must be signed in to change notification settings - Fork 36
Don't trigger neighbor list warnings on ignored constant keys that are actually present #1121
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
Merged
+167
−1
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
593eb26
Add additional tests
cbkerr 6a3c355
Add test iterating over neighborlist structure
cbkerr 3aa0c61
Add test for constant values to not appear in neighbor list
cbkerr 98473c7
neighborlist: Fixes for constant state point parameters
cbkerr 300d18f
Format and remove print statements
cbkerr 7aab316
Remove a print
cbkerr a7e5eed
Add another check for constant not in nl
cbkerr 25deea4
Run prek
cbkerr f6b57b6
Show no neighbors detected between jobs differing via added/rm keys
cbkerr d28a95c
Update added/removed sp key test
cbkerr 73f798d
Use dict comprehension for performance
cbkerr ff14225
Formatting
cbkerr 56cbaaf
Wrap lines
cbkerr 6e8bb07
Format
cbkerr fe903d0
Update changelog
cbkerr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -52,6 +52,8 @@ def test_neighbors(self): | |||
| ) | ||||
| with pytest.warns(RuntimeWarning, match="not_present"): | ||||
| self.project.get_neighbors(ignore=["not_present"]) | ||||
| with pytest.warns(RuntimeWarning, match="not_present"): | ||||
| self.project.get_neighbors(ignore=["not_present", "another_not_present"]) | ||||
|
|
||||
| def test_neighbors_ignore(self): | ||||
| b_vals = [3, 4, 5] | ||||
|
|
@@ -87,6 +89,139 @@ def test_neighbors_ignore(self): | |||
| == self.project.open_job({"b": 4, "2b": 8}).id | ||||
| ) | ||||
|
|
||||
| def test_neighbors_ignore_constant(self): | ||||
| b_vals = [3, 4, 5] | ||||
| for b in b_vals: | ||||
| self.project.open_job({"b": b, "2b": 2 * b, "constant": 1}).init() | ||||
|
|
||||
| neighbor_list = self.project.get_neighbors(ignore="2b") | ||||
| assert "constant" not in neighbor_list | ||||
|
|
||||
| neighbor_list = self.project.get_neighbors(ignore=["2b", "constant"]) | ||||
| for b in b_vals: | ||||
| job = self.project.open_job({"b": b, "2b": 2 * b, "constant": 1}) | ||||
| neighbors_job = job._get_neighbors(ignore=["2b", "constant"]) | ||||
|
|
||||
| this_neighbors = neighbor_list[job.id] | ||||
| assert this_neighbors == neighbors_job | ||||
|
|
||||
| if b == 3: | ||||
| assert ( | ||||
| this_neighbors["b"][4] | ||||
| == self.project.open_job({"b": 4, "2b": 8, "constant": 1}).id | ||||
| ) | ||||
| elif b == 4: | ||||
| assert ( | ||||
| this_neighbors["b"][3] | ||||
| == self.project.open_job({"b": 3, "2b": 6, "constant": 1}).id | ||||
| ) | ||||
| assert ( | ||||
| this_neighbors["b"][5] | ||||
| == self.project.open_job({"b": 5, "2b": 10, "constant": 1}).id | ||||
| ) | ||||
| elif b == 5: | ||||
| assert ( | ||||
| this_neighbors["b"][4] | ||||
| == self.project.open_job({"b": 4, "2b": 8, "constant": 1}).id | ||||
| ) | ||||
|
|
||||
| with pytest.warns(RuntimeWarning, match="not_present"): | ||||
| self.project.get_neighbors(ignore=["not_present", "2b"]) | ||||
| with pytest.warns(RuntimeWarning, match="not_present"): | ||||
| self.project.get_neighbors(ignore=["not_present", "constant"]) | ||||
|
|
||||
| def test_neighbors_no_neighbors(self): | ||||
| job = self.project.open_job({"constant": 1, "constant_2": 2}).init() | ||||
| neighbor_list = self.project.get_neighbors() | ||||
| assert neighbor_list[job.id] == {} | ||||
|
|
||||
| neighbor_list = self.project.get_neighbors(ignore="constant") | ||||
| assert neighbor_list[job.id] == {} | ||||
|
|
||||
| def test_neighborlist_structure(self): | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| for a, b in product([1, 2, 3], [5, 6, 7]): | ||||
| self.project.open_job({"a": a, "b": b, "2b": 2 * b}).init() | ||||
|
|
||||
| for b in [8, 9, 10]: | ||||
| self.project.open_job({"a": 1, "b": b}).init() | ||||
|
|
||||
| # works across data types | ||||
| for b in ["eight", "nine", None]: | ||||
| self.project.open_job({"a": 1, "b": b}).init() | ||||
|
|
||||
| # see isolated jobs | ||||
| self.project.open_job({"a": 1, "c": True, "b": "eight"}).init() | ||||
|
|
||||
| for c, b in product([True, False], ["eight", "nine"]): | ||||
| self.project.open_job({"c": c, "b": b}).init() | ||||
|
|
||||
| # works on lists | ||||
| for c, b in product([True, False], [[1, 2], [1, 5]]): | ||||
| self.project.open_job({"c": c, "b": b}).init() | ||||
|
|
||||
| # works on nested values | ||||
| # although they appear in the neighbor list like nl[id]["x.n"] because of internal limitations with schema | ||||
| for x in [{"n": "nested"}, {"n": "values"}]: | ||||
| self.project.open_job({"x": x}).init() | ||||
|
|
||||
| neighbor_list = self.project.get_neighbors(ignore=["2b"]) | ||||
|
|
||||
| for job in self.project: | ||||
| neighbors = neighbor_list[job.id] | ||||
| for key, neighbor_vals in neighbors.items(): | ||||
| for neighbor_value, neighbor_job_id in neighbor_vals.items(): | ||||
| if neighbor_job_id == "47c6f9a7c0d88ab60a9e8de4ed002e6f": | ||||
| # that's job with b:None | ||||
| print(f"ignoring {neighbor_value=} and {neighbor_job_id=}") | ||||
| else: | ||||
| assert neighbor_value is not None | ||||
| assert neighbor_job_id | ||||
| assert key | ||||
|
|
||||
| def test_neighborlist_structure_with_constant(self): | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| for a, b in product([1, 2, 3], [5, 6, 7]): | ||||
| self.project.open_job({"constant": 1, "a": a, "b": b, "2b": 2 * b}).init() | ||||
|
|
||||
| for b in [8, 9, 10]: | ||||
| self.project.open_job({"constant": 1, "a": 1, "b": b}).init() | ||||
|
|
||||
| # works across data types | ||||
| for b in ["eight", "nine", None]: | ||||
| self.project.open_job({"constant": 1, "a": 1, "b": b}).init() | ||||
|
|
||||
| # see isolated jobs | ||||
| self.project.open_job({"constant": 1, "a": 1, "c": True, "b": "eight"}).init() | ||||
|
|
||||
| for c, b in product([True, False], ["eight", "nine"]): | ||||
| self.project.open_job({"constant": 1, "c": c, "b": b}).init() | ||||
|
|
||||
| # works on lists | ||||
| for c, b in product([True, False], [[1, 2], [1, 5]]): | ||||
| self.project.open_job({"constant": 1, "c": c, "b": b}).init() | ||||
|
|
||||
| # works on nested values | ||||
| # although they appear in the neighbor list like nl[id]["x.n"] because of internal limitations with schema | ||||
| for x in [{"n": "nested"}, {"n": "values"}]: | ||||
| self.project.open_job({"constant": 1, "x": x}).init() | ||||
|
|
||||
| neighbor_list = self.project.get_neighbors(ignore=["2b"]) | ||||
|
|
||||
| assert "constant" not in neighbor_list | ||||
|
|
||||
| for job in self.project: | ||||
| neighbors = neighbor_list[job.id] | ||||
| for key, neighbor_vals in neighbors.items(): | ||||
| for neighbor_value, neighbor_job_id in neighbor_vals.items(): | ||||
| if neighbor_job_id == "1db325b31be7b4e378e7daf95ba1275e": | ||||
| # that's job with b:None | ||||
| print(f"ignoring {neighbor_value=} and {neighbor_job_id=}") | ||||
| else: | ||||
| assert neighbor_value is not None | ||||
| assert neighbor_job_id | ||||
| assert key | ||||
|
|
||||
| def test_neighbors_ignore_nested(self): | ||||
| a_vals = [{"b": 2, "c": 2}, {"b": 3, "c": 3}] | ||||
| for a in a_vals: | ||||
|
|
||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.