-
-
Notifications
You must be signed in to change notification settings - Fork 553
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
Issue 3114 check coord #3394
Issue 3114 check coord #3394
Conversation
sorry I accidentally create another one |
Thank you so much for the kind suggestion. Reopen now. |
Co-authored-by: Eric G. Kratz <[email protected]>
…ue_3114_check_coord
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #3394 +/- ##
===========================================
- Coverage 99.58% 99.57% -0.01%
===========================================
Files 256 256
Lines 20131 20137 +6
===========================================
+ Hits 20048 20052 +4
- Misses 83 85 +2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks! Before I can approve, can you add a line to the CHANGELOG?
You can copy the format of one of the other lines, but you will need to add it under the "Unreleased" section rather than 23.9.
@all-contributors please add @RuiheLi for code and tests |
This project's configuration file has malformed JSON: .all-contributorsrc. Error:: Unexpected token ] in JSON at position 18423 |
@all-contributors please add @RuiheLi for code and tests |
I've put up a pull request to add @RuiheLi! 🎉 |
elif coord_sys is not None: | ||
raise ValueError( | ||
f"Coordinate system is {coord_sys}, not in" | ||
" cartesian, cylindrical polar, spherical polar, None") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more minor change. It is generally best to end an if-else block with an else. That way future developers know the branches were meant to end there and that something was not just forgotten.
elif coord_sys is not None: | |
raise ValueError( | |
f"Coordinate system is {coord_sys}, not in" | |
" cartesian, cylindrical polar, spherical polar, None") | |
else: | |
if coord_sys is not None: | |
raise ValueError( | |
f"Coordinate system is {coord_sys}, not in" | |
" cartesian, cylindrical polar, spherical polar, None" | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note that this line is not covered so an additional test is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, that comes something I am very weak now. Just reading the test_finite_volume.py file and only come up with:
def test_divergence(self):
whole_cell = ["negative electrode", "separator", "positive electrode"]
var = pybamm.Variable("var", domain=whole_cell)
x = pybamm.SpatialVariableEdge(
"x_s",
domain=["separator"],
auxiliary_domains={"secondary": "current collector"},
coord_sys="cartesian_2",
)
with self.assertRaises(ValueError):
pybamm.SpatialMethod.divergence(var,x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I am pretty sure this won't work, so just to raise a question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is similar to the one you have, which is necessary because it checks the error is raised in independent_variable.py
. You need another test that calls directly the divergence
method in finite_volume.py
. However, I am not sure we can do that test without triggering the other error before. That's because in order to define the symbol to pass to divergence
we need to give it a domain with its own coordinate system. @kratman, any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the kind reply. @brosaplanella That's something I am a bit struggled as well. Though I notice that I can get some mesh by mesh = get_mesh_for_testing()
. If I look closer at get_mesh_for_testing
, they already assign coordinate system, and I don't know how to change that.
Please update the PR description so that 3114 gets closed by this change (use the fixes tag in the template) |
@RuiheLi Are you still working on this? |
I have added the final else as suggested. But I had a try and still cannot write a proper test for the |
@kratman what's the best way to approach that? Should we add a |
I will take a look at this closer in the afternoon and give my opinion on the tests |
out = divergence_matrix @ (r_edges * discretised_symbol) | ||
else: | ||
elif coord_sys == "cartesian": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are a few other places where there is similar logic that should be updated (do a search for submesh.coord_sys in ["cylindrical polar", "spherical polar"]
)
now that the coordinate system is already checked should the logic in discretisation be changed? i.e. we don't need to throw that error and the final else can just be the Cartesian case? alternatively, if we want to keep the error and have a test you could create a spatial variable with the correct domain, then manually overwrite |
@RuiheLi Sorry it took so long for me to respond, but I think there is a nice workaround to test this change without ignoring any lines. If you are having trouble testing that function, then it might get easier if you create a function for the block in question. If you create a function called something along the lines of "check_coordinate_system()" for the if-elif-else block, then it can take all things it is supposed to check as arguments. That might make it easier to write a test without adding making the test too complicated. I did something similar in this commit: fa6bdc2 In general short functions are easy to test. So breaking up complicated functions is probably a good thing anyway. Whenever it is difficult to test a function and we consider adding a pragma to ignore it. It is often a sign that we need to break up the function into smaller testable methods. |
thanks @kratman, i like this approach as we check coordinates a few times in that file, so will reduce duplication too |
@RuiheLi Are you still working on this? |
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes #3114
Type of change
Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.
Key checklist:
$ pre-commit run
(or$ nox -s pre-commit
) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)$ python run-tests.py --all
(or$ nox -s tests
)$ python run-tests.py --doctest
(or$ nox -s doctests
)You can run integration tests, unit tests, and doctests together at once, using
$ python run-tests.py --quick
(or$ nox -s quick
).Further checks: