-
Notifications
You must be signed in to change notification settings - Fork 109
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
Fix SNOPT printout encoding and skip printing import warnings #392
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #392 +/- ##
===========================================
- Coverage 73.75% 61.66% -12.10%
===========================================
Files 22 22
Lines 3296 3292 -4
===========================================
- Hits 2431 2030 -401
- Misses 865 1262 +397 ☔ 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.
Can you update the PR title/description to mention the new flag? I am also not sure if this is the way to go, see below.
The cw
update is good stuff!
@@ -600,7 +605,7 @@ def try_import_compiled_module_from_path(module_name: str, path: Optional[str] = | |||
try: | |||
module = importlib.import_module(module_name) | |||
except ImportError as e: | |||
if path is not None: | |||
if raise_warning: |
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 are the scenarios where we don't want to raise a warning when the import fails? Even if it's from THIS_DIR
we should probably raise an error
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.
Right now on the main branch, running e.g. example/hs015.py
will emit the following warnings for me:
.../pyoptsparse/pyoptsparse/pyIPOPT/pyIPOPT.py:28: UserWarning: pyipoptcore module could not be imported from .../repos/pyoptsparse/pyoptsparse/pyIPOPT.
pyipoptcore = try_import_compiled_module_from_path("pyipoptcore", THIS_DIR)
.../pyoptsparse/pyoptsparse/pyNLPQLP/pyNLPQLP.py:20: UserWarning: nlpqlp module could not be imported from .../pyoptsparse/pyoptsparse/pyNLPQLP.
nlpqlp = try_import_compiled_module_from_path("nlpqlp", THIS_DIR)
Without the changes in this PR, we always print warnings (at import time) if we cannot import these libraries. Given that they are optional and not installed by pyOptSparse, I don't think we will want this for end users. The PR changes this behaviour so that warnings are not emitted by default. Note that errors are raised at instantiation time if import fails and this PR does not change that behaviour.
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 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 can confirm that this fixes the non-UTF8 characters in the SNOPT print file. The import changes also look good.
Purpose
Closes #379.
Turns out we just forgot to initialize the
cw
array to" "
. Also can get rid ofcdummy
now.Also cleaned up import warnings for compiled libraries -- they are now no longer printed by default at import time for non-default libraries.
Expected time until merged
Type of change
Testing
Checklist
flake8
andblack
to make sure the Python code adheres to PEP-8 and is consistently formattedfprettify
or C/C++ code withclang-format
as applicable