-
Notifications
You must be signed in to change notification settings - Fork 105
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
Refactor tests #251
Refactor tests #251
Conversation
Codecov Report
@@ Coverage Diff @@
## master #251 +/- ##
==========================================
- Coverage 83.97% 83.44% -0.54%
==========================================
Files 22 22
Lines 3252 3250 -2
==========================================
- Hits 2731 2712 -19
- Misses 521 538 +17
Continue to review full report at Codecov.
|
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 is a major improvement! I don't see any obvious reduction in coverage other than SNOPT versions prior to 7.7.7. Is that intentional?
assert_allclose(sol_xvars, dv["xvars"], atol=tol, rtol=tol) | ||
# we check either optimum via try/except | ||
try: | ||
if optName == "SNOPT" and opt.version != "7.7.7": |
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.
The stable image is failing because these checks have been removed.
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.
Good point, will add
self.optimize_with_hotstart("PSQP", 5e-12, optOptions=optOptions) | ||
# dv = sol.getDVs() | ||
# sol_xvars = [sol.variables["xvars"][i].value for i in range(2)] | ||
# assert_allclose(sol_xvars, dv["xvars"], atol=tol, rtol=tol) |
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.
Are these commented lines supposed to be here?
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.
Ah, right these were testing sol.variables
etc. I will try to generalize these and make sure the Solution object contained the right values in different attributes.
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.
I added some tests, but not all since it's a bit harder to generalize. I've opened #256 to address this, among other things.
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.
Altright, I think I listed all the remaining comments I had. Note that some of them are not necessarily related to your edits, but additional comments/info we could add during this refactoring.
This is a substantial PR and some commits are pretty big and hard to follow, so for future PRs I would suggest to either break them further or, more in general, add a comment to the commit message to clarify the rationale behind it?
test/test_tp109.py
Outdated
|
||
# Check Solution | ||
assert_allclose(sol2.objectives["obj"].value, 0.536206927538e04, atol=1e-2, rtol=1e-2) | ||
self.assert_solution(sol2, 1e-2) |
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.
See above - Why is this tolerance so large?
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.
Hmm good point, I think the idea is that this is loose because SNOPT may not be available, so then we just assert the ALPSO answer. I will fix this.
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.
Actually ALPSO seems...kinda broken. I'll open an issue but I prefer not fixing this in this PR.
|
||
|
||
def get_dict_distance(d, d2): | ||
"""This converts a flat 1D dict to array using sorted keys, then computes the L2 distance""" |
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.
took a while to understand why this was necessary, nice trick, but are we sure it is the most robust approach?
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.
Not sure what you mean here. The code is not 100% robust because the numpy array casts aren't 100% fool proof, but the approach itself should be valid no?
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.
Yeah I was just thinking about cases where the L2 norm would not be the the best approach but I think for testing specifically this is not an issue. Good to go!
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 looks good to me other than one thing
Yeah sorry about that, I tried to break it up but as you can see, it's hard to do when I'm changing many things at once. Because I will be testing things as I develop, it's hard to keep a nice linear git history as well. I will try to make my commit messages better though, I don't think I was very good at that. Anyways, I think I addressed most of the concerns. Please take another look and let me know. |
Purpose
This PR refactors the existing tests by introducing a test class that handles various shared tasks
I also added parameterized tests etc. for efficiency.
Not all existing tests use this class however:
objfunc
is defined within the class. Absolutely no idea why..I'll keep this as a draft PR for now. The main thing I want to check is that we're not losing any coverage through this, so if reviewers can also check against the old tests and see if I missed anything. Finally, the way the tests are structured can probably improved, so any suggestions are welcome.
Type of change
What types of change is it?
Select the appropriate type(s) that describe this PR