-
Notifications
You must be signed in to change notification settings - Fork 557
New KNITRO direct solver interface #3707
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
base: main
Are you sure you want to change the base?
Conversation
611fb3b
to
0d7a162
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3707 +/- ##
==========================================
+ Coverage 89.31% 89.34% +0.02%
==========================================
Files 896 906 +10
Lines 103687 104446 +759
==========================================
+ Hits 92609 93316 +707
- Misses 11078 11130 +52
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Hi @eminyouskn - okay, so, the tests are running but a large number of them are failing. Here is part of the stacktrace:
Most of the failures are just tolerance problems / the tolerance needs to be loosened. |
One-off failures:
Second one-off:
|
Thanks @mrmundt for the report. I didn’t run these tests locally since I didn’t have NumPy installed, and in that case, the tests are skipped. I’ll make sure to check them before pushing code from now on. I do have a question: is there a way to adjust the tolerance for all these tests at once? Ideally, we’d only change it for Knitro, but I imagine that might be more complicated. Regarding the two remaining failures, I’ve already fixed the one related to the objective. However, I’m not sure how to address the stale one, it’s not clear to me what exactly that test is supposed to check. |
Thanks @mrmundt for the quick and thorough review. As you mentioned, I didn’t use the logger, everything requiring user attention is either handled directly or raised an error, in which case the higher-level code is responsible for communicating it to the user. |
However, your point about debugging is valid. I need to consider whether there are parts that should be logged specifically for debugging purposes. |
@mrmundt One of the two failing tests doesn’t seem related to Knitro. For the other one, could you share the output so I can work on fixing it? |
Yup, this one should be an easy fix:
Just update |
Thanks @mrmundt for the report. I’d prefer not to change the test since it should pass as is. I believe I found the cause of the failure, so I’ll add a fix. |
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.
@eminyouskn - I realized one thing is definitely missing! Can you please update the docs to include knitro? https://github.com/Pyomo/pyomo/blob/main/doc/OnlineDocs/explanation/experimental/solvers.rst
@mrmundt done! |
Co-authored-by: Miranda Mundt <55767766+mrmundt@users.noreply.github.com>
|
||
|
||
def get_version() -> str: | ||
if not bool(KNITRO_AVAILABLE): |
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.
FYI, explicitly casting the flag to bool is unnecessary. You don't need to change it, but the following works:
if not bool(KNITRO_AVAILABLE): | |
if not KNITRO_AVAILABLE: |
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 will change it then.
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.
by the way my linter is not happy about removing the bool. So I think I will keep it.
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.
What is the linter complaining about?
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.
it says the following:
Invalid conditional operand of type "DeferredImportIndicator | bool"
Method __bool__ for type "DeferredImportIndicator" returns type "bool | None" rather than "bool"
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.
Ahh... does the following patch resolve the linter's complaint:
diff --git a/pyomo/common/dependencies.py b/pyomo/common/dependencies.py
index 27167f12f..73b86bba6 100644
--- a/pyomo/common/dependencies.py
+++ b/pyomo/common/dependencies.py
@@ -344,7 +344,7 @@ class DeferredImportIndicator(_DeferredImportIndicatorBase):
if callback is not None:
DeferredImportCallbackFinder._callbacks.setdefault(name, []).append(self)
- def __bool__(self):
+ def __bool__(self) -> bool:
self.resolve()
return self._available
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 would say that this patch fixes the issue, but the linter will still complain because the return type of that function doesn’t match the returned value. In #3746, I addressed this by wrapping available with bool.
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 linter is unfortunately not correct. The return type is always a bool
(it has to be: returning anything other than a bool
from __bool__()
will generate a TypeError
). In this case, a side effect of resolve()
is to resolve the _indicator
to its bool 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.
I totally agree. I think since the type inferring is static, the linter is not able to detect that the _available
will be always a bool
after the resolve()
call.
Fixes NA
Summary/Motivation:
This PR introduced a new KNITRO direct solver interface.
Changes proposed in this PR:
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: