Skip to content

Conversation

@ewu63
Copy link
Collaborator

@ewu63 ewu63 commented Mar 12, 2025

Purpose

Closes #374, and hopefully addresses some of the issues we've been having. I also added the long-awaited numpy2 test on CI (with windows).

Some to dos:

  • decide whether we want to specify cyipopt as a dependency
  • check options, setups, etc. to cyipopt and compare against previous code
  • update documentation

Expected time until merged

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (non-backwards-compatible fix or feature)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Documentation update
  • Maintenance update
  • Other (please describe)

Testing

Checklist

  • I have run flake8 and black to make sure the Python code adheres to PEP-8 and is consistently formatted
  • I have formatted the Fortran code with fprettify or C/C++ code with clang-format as applicable
  • I have run unit and regression tests which pass locally with my changes
  • I have added new tests that prove my fix is effective or that my feature works
  • I have added necessary documentation

@codecov
Copy link

codecov bot commented Mar 12, 2025

Codecov Report

Attention: Patch coverage is 84.44444% with 7 lines in your changes missing coverage. Please review.

Project coverage is 75.02%. Comparing base (7952e1c) to head (14734ab).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
pyoptsparse/pyIPOPT/pyIPOPT.py 84.44% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #425      +/-   ##
==========================================
+ Coverage   74.98%   75.02%   +0.03%     
==========================================
  Files          22       22              
  Lines        3338     3331       -7     
==========================================
- Hits         2503     2499       -4     
+ Misses        835      832       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ewu63 ewu63 force-pushed the switch-to-cyipopt branch 2 times, most recently from 0b59cb5 to 10af64a Compare April 2, 2025 05:13
@ewu63 ewu63 marked this pull request as ready for review April 2, 2025 05:58
@ewu63 ewu63 requested a review from a team as a code owner April 2, 2025 05:58
@ewu63 ewu63 requested review from ArshSaja and lamkina April 2, 2025 05:58
@ewu63 ewu63 mentioned this pull request Apr 2, 2025
13 tasks
@ewu63 ewu63 changed the title WIP: Switch to cyipopt Switch to cyipopt Apr 2, 2025
@ewu63 ewu63 requested a review from marcomangano April 3, 2025 18:20
@ewu63
Copy link
Collaborator Author

ewu63 commented Apr 3, 2025

@kanekosh are you still using IPOPT? It would be nice if you can try out the changes here and see if they give similar results as before

@ewu63 ewu63 force-pushed the switch-to-cyipopt branch from 346e31b to bae881a Compare April 3, 2025 18:20
@kanekosh
Copy link
Contributor

kanekosh commented Apr 5, 2025

Thanks @ewu63! I tested cyipopt (both one from conda-force and pip-installed one with my pre-build IPOPT) and it works almost identical to my previous IPOPT installation (I sometimes see very minor difference as a results of different IPOPT and MUMPS versions).

One minor fix: I happened to have a bad optimization problem where a constraint function call fails and IPOPT does "Cutting back alpha due to evaluation error" and goes on (and magically converges after that). When the evaluation error occurs, we used to return np.array(np.NaN) regardless of the number of constraints and that made IPOPT do alpha cut back. Now with cyipopt, returning np.array(np.NaN) causes an unexpected error in cyipopt because of these lines, and cyipopt sends user termination signal instead of passing NaNs to IPOPT.
Instead, we need to pass the correct shape of NaNs under the evaluation failure. This array of NaNs goes into IPOPT and triggers alpha cut back as we intend. I just pushed a change to do so.

I believe it's the same for gradient and jacobian callbacks, so I made changes to return array of NaNs. However I haven't tested these so not 100% sure...

@ewu63
Copy link
Collaborator Author

ewu63 commented Apr 5, 2025

I will cleanup the meson files (either here or in #431). Yeah since we are not going to use meson to install the python files I'll just remove most of the lines.

Thanks for testing this out! Do you think you can add a test for the condition you described? I'm surprised we don't have one on eval failure but I suppose that part isn't very well tested.

@kanekosh
Copy link
Contributor

kanekosh commented Apr 5, 2025

Sounds good! Just added a few tests.
The new test (test_func_eval_failure) currently only tests SNOPT and IPOPT (two most robust optimizers) as other optimizers can fail depending on the environment. SLSQP and PSQP passed the test on my machine but failed on some images. NLPQLP and ParOpt passed on all images so I could add them back, although I'm not sure if we should do so.

@ewu63
Copy link
Collaborator Author

ewu63 commented Apr 5, 2025

Sounds good! Just added a few tests. The new test (test_func_eval_failure) currently only tests SNOPT and IPOPT (two most robust optimizers) as other optimizers can fail depending on the environment. SLSQP and PSQP passed the test on my machine but failed on some images. NLPQLP and ParOpt passed on all images so I could add them back, although I'm not sure if we should do so.

This is fine, I only know SNOPT and IPOPT support failed evaluations so I'm not surprised some of the others failed. Left a few small comments but otherwise this looks good to go.

Copy link
Collaborator

@marcomangano marcomangano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!! I haven't tested the code myself but I went through the changes and they look straightforward. The docs are clear and @kanekosh 's updated tests look good - nice job with the comments.

I wonder if this PR warrants a minor release?

@ewu63
Copy link
Collaborator Author

ewu63 commented Apr 7, 2025

I personally would prefer not bumping the version here, and instead wait until #431 to bump the minor version together. If we think #431 will take a while then I'm okay with making a minor release here. CC @whophil

@marcomangano
Copy link
Collaborator

I personally would prefer not bumping the version here, and instead wait until #431 to bump the minor version together. If we think #431 will take a while then I'm okay with making a minor release here. CC @whophil

That is fine with me!

@ewu63 ewu63 merged commit e3b9417 into main Apr 9, 2025
15 checks passed
@ewu63 ewu63 deleted the switch-to-cyipopt branch April 9, 2025 01:32
This was referenced Apr 13, 2025
@kanekosh kanekosh mentioned this pull request Jul 28, 2025
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linking pyoptsparse to cyipopt

4 participants