-
Notifications
You must be signed in to change notification settings - Fork 3
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
Improve error messages when necessary optimization library is not loaded #69
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #69 +/- ##
===========================================
+ Coverage 69.65% 83.09% +13.44%
===========================================
Files 18 18
Lines 201 207 +6
===========================================
+ Hits 140 172 +32
+ Misses 61 35 -26 ☔ View full report in Codecov by Sentry. |
@salbalkus appreciate your efforts to address various error messages at once with additional code and logic, but as discussed in the issue, we just need a simple patch release with better error messages (strings inside Can you please simplify the PR to only improve the error messages? |
@juliohm The reason for my contribution is to fix the problem I described in #68 , which will not be addressed by simply changing the The However, it does not occur if the user calls the DensityRatioEstimator with an optimization library that is implemented but is not yet loaded. For example, if the user calls The problem is, as mentioned in #68 , the error that is thrown is I'm definitely open to implementing your feedback and changes on this PR regarding how to design functionality that actually fixes the problem above in a more maintainable way. One improvement, rather than casting the library name into a string and subsetting it (which might break in future releases if the names change), might be to define a dictionary as a global object that maps the object names into package names, i.e. |
This is the error message I get from the MWE in #69 : It is calling the |
That seems like a separate issue, which we should address in a separate PR. The fix could be as simple as improving the error message too. Just mentioning that the error may occur when the library is not loaded. No need for additional logic I think, but please let me know if I am missing something. |
My apologies, @juliohm. It think the MWE from #68 was not showing the "not implemented" error due to an issue with my VSCode setup not properly displaying logs, which I am unable to reproduce; when I run it in the terminal I get the same result as you. That being said, a similar situation actually does occur with KMM; the "not implemented" error message doesn't appear if one runs
yielding
since KMM is missing a "default" function for In this case, is there a reason that |
No reason to use @error. Appreciate if you can throw an error properly.
Em seg., 8 de jul. de 2024, 12:41, Salvador Balkus ***@***.***>
escreveu:
… This is the error message I get from the MWE in #69
<#69> :
[image: image]
<https://private-user-images.githubusercontent.com/3345261/346569959-87c2db2b-c4aa-415c-8b7f-ded8ec3e287e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA0NTA1NDcsIm5iZiI6MTcyMDQ1MDI0NywicGF0aCI6Ii8zMzQ1MjYxLzM0NjU2OTk1OS04N2MyZGIyYi1jNGFhLTQxNWMtOGI3Zi1kZWQ4ZWMzZTI4N2UucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDhUMTQ1MDQ3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzY4MWQwYmQxMGExODEwOWZlMTUyMGQyOGNhN2VkYjVmZjZmOTQzZjE5YmYxNzRlMWIwMmMzZDA1N2I3YzA4ZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.0_CZMXZvcQA38LrqooEEXw29eanpj_zAri8D5DX8W6Y>
It is calling the @error correctly, just the message that needs to be
improved. Can you please share the error message you are getting? Why is it
not hitting the same code?
My apologies, @juliohm <https://github.com/juliohm>. It think the MWE
from #68 <#68>
was not showing the "not implemented" error due to an issue with my VSCode
setup not properly displaying logs, which I am unable to reproduce; when I
run it in the terminal I get the same result as you. That being said, a
similar situation actually does occur with KMM; the "not implemented" error
message doesn't appear if one runs
using DensityRatioEstimation
densratio([0], [0], KMM())
yielding
ERROR: MethodError: no method matching _kmm_ratios(::Matrix{Float64}, ::Matrix{Float64}, ::KMM{Float64}, ::Type{JuMPLib})
Closest candidates are:
_kmm_ratios(::Any, ::Any, ::uKMM, ::Type{JuliaLib})
@ DensityRatioEstimation C:\Users\salba\.julia\packages\DensityRatioEstimation\1Mu92\src\kmm\julia.jl:5
since KMM is missing a "default" function for _kmm_ratios to throw the
error.
In this case, is there a reason that @error is used to print an error
*log* instead of throwing an exception using error or throw? From the docs
***@***.***> the
@error macro is intended for "nonfatal errors", though obviously failing
to load the correct optimization package should result in a fatal error.
Can I open a new pull request and replace @error "msg" with error("msg")
with improved messages? This should also make it easier to test using
@test_throws.
—
Reply to this email directly, view it on GitHub
<#69 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZQW3KYUVJBJPWHJ5SP3E3ZLKXKBAVCNFSM6AAAAABKP3YJIGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJUGQ3TIMJZGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@salbalkus did you have a chance to take a look into this? We just need to throw and actual error with a more informative error message. |
Yes, I've written more informative error messages. Currently I'm setting up unit tests to make sure the code is properly covered and they're being thrown in the right situation. I can open a pull request tonight. |
This new commit reverts my previous change to check if the necessary libraries are loaded and adds more maintainable error throwing.
|
That is really good! Thanks for the awesome contribution! Merging and releasing a patch 👍🏽 |
Thank you @juliohm - happy to help! |
Addresses #68 , which arises when the user specifies an optimization library using the
optlib
parameter that is supported, but they have not currently loaded the library that they have specified.This PR adds a function that checks if the package specified by
optlib
has been loaded by the user. It also adds a function to throw an error informing the user that package corresponding to theoptlib
has not been loaded and to either runusing [PackageName]
or otherwise specify the correct library. Thedensratio
anddensratiofunc
functions have been updated to throw the corresponding error in these cases, and unit tests for these cases have been included inruntests.jl
.Additionally, other existing error messages related to the specification of optimization libraries have been made slightly more descriptive and verbose.