-
Notifications
You must be signed in to change notification settings - Fork 19
raise ValueError if the the number of regression points is less than the number of parameters in _residual
#249
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
Conversation
…n the number of parameters in `_residual`
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #249 +/- ##
==========================================
+ Coverage 99.22% 99.92% +0.70%
==========================================
Files 23 23
Lines 1285 1318 +33
==========================================
+ Hits 1275 1317 +42
+ Misses 10 1 -9
🚀 New features to boost your workflow:
|
|
@sbillinge, it's ready for review. |
|
Make sure that the argument parser captures the error in I would also like it if there was a test that this error is indeed being captured? Maybe one test for the CLI side and one for the morphpy side? |
|
@ycexiao @Sparks29032 I don't really mind where the error is caught in python or in CLI as long as the help message helps the user as much as possible to come up with a fix. Saying "adjust somethihng" is not so helpful because what do I adjust it to? or how do I figure out what to adjust it to? @Sparks29032 is there a way to know and suggest what adjustment will fix this? If it is trial and error to try and fix it, or the user can plot the polynomial and see where it goes negative or some such thing, this is helpful information to help them debug. We don't want to write a book, but some brief and hdlpful explanation would be good. Yes, we need a test for this. If we implement it as a check in the CLI we could test that there too. As a rule we have not been doing much validation at all in the CLI. The main reason is just not enough time in the day. So I would not really prioritize that that atm unless it is quick and painless. |
|
What I am saying is that the error is not going to display to a CLI user if we do not exit. We want a wrapper around the refine call in the |
|
aren't we raising an exception? Are saying the exception gets caught and handled somewhere higher up in the code stack? If not then it will crash with the exception (which would be the desired behavior)? |
How about "Please make sure the overlapping domain between the morphed function and the target function is sufficiently large, or reduce the number of parameters?"
I will make sure both the CLI user and the scripts user will see the error message.
Yes, I will add a test for it. |
|
Sounds good for the adjustment. Would also be helpful to mention the size of the function and number of parameters you are optimizing to the user so they can see exactly how many more parameters they must reduce by. |
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.
@sbillinge @Sparks29032, it's ready for review.
src/diffpy/morph/refine.py
Outdated
|
|
||
| if len(rvec) < len(pvals): | ||
| raise ValueError( | ||
| f"\nNumber of shared grid points: {len(rvec)}\n" |
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.
Print the size of the function and the number of parameters.
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.
nice work everyone
src/diffpy/morph/refine.py
Outdated
| raise ValueError( | ||
| "Not enough shared grid points between morphed function " | ||
| "and target function to fit the chosen parameters. " | ||
| "Please adjust the functions or " |
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.
Nicely done. Is there a way to give guidance on how the to "adjust the functions"?
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 current error message is: "Please make sure the overlapping domain between the morphed function and the target function is sufficiently large, or reduce the number of parameters."
src/diffpy/morph/refine.py
Outdated
| "Not enough shared grid points between morphed function " | ||
| "and target function to fit the chosen parameters. " | ||
| "Please adjust the functions or " | ||
| "between morphed function and target function to fit " |
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.
please check, is "between morphed function" repeated 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.
Yes, it is a typo. It is fixed in a newer commit.
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.
@sbillinge @Sparks29032, it's ready for review.
|
I'm not sure the following lines are being run in the test (see CodeCov). When the error is thrown and Pytest catches it, the lines below where the error is thrown are not run. You will need some other way to check the error message is correct. Otherwise, I have no other comments, seems good. |
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.
@sbillinge @Sparks29032, it's ready for review.
| ValueError, | ||
| ) as error: | ||
| refiner.refine(*refpars) | ||
| actual_error_message = str(error.value) |
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.
These two lines were skipped because of the wrong indentation. It is fixed now.
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 am not sure I like this. Why are we doing this? Lot's of extra complicated code to maintain, but what benefit does it get us exactly? Let's discuss a bit. I am happy to be convinced, but in general, simpler is better for a research group like ours.....
|
Two main reasons why I'd like this PR: |
@sbillinge, are you referring to the commit "use a custom error to stop leatsq"? Actually, it is not a good fix and it is reverted. The actual modification is from chore: fix the code indentation. where only the code indentation is changed so it is not complicated. |
|
ok, sounds good all around |
What problem does this PR address?
Address the second item in #241.
What should the reviewer(s) do?
Please check the modifications.