Skip to content
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

Added linear constraint check and updated documentation #410

Merged
merged 6 commits into from
Jul 6, 2024

Conversation

kanekosh
Copy link
Contributor

Purpose

pyOptSparse computes the linear constraints exclusively based on jac, lower, and upper entries of addConGroup, and it ignores the linear constraint value returned by the user-defined obj/con function. This is confusing and can result in unexpected behavior (see related #296).

This PR adds a linear constraint checkerto make sure that a user-defined obj/con function does not return linear constraint values. If it does, pyOptSparse will raise an error. I also updated the documentation accordingly.

I fixed a few existing tests that have been computing linear constraint values in the obj/con function (which we should not). I also added a test to check if pyOptSparse raises an error as expected.

This change will break some existing runscripts that return linear constraint values in the user-defined function. OpenMDAO's pyOptSparseDriver will be fine. Not sure about MACH runscripts (haven't checked).

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

Copy link

codecov bot commented Jun 26, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 63.39%. Comparing base (7376d71) to head (89e4935).

Files Patch % Lines
pyoptsparse/pyOpt_optimizer.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #410       +/-   ##
===========================================
- Coverage   74.49%   63.39%   -11.10%     
===========================================
  Files          22       22               
  Lines        3317     3325        +8     
===========================================
- Hits         2471     2108      -363     
- Misses        846     1217      +371     

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

@kanekosh kanekosh marked this pull request as ready for review June 26, 2024 20:29
@kanekosh kanekosh requested a review from a team as a code owner June 26, 2024 20:29
Copy link
Contributor

@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.

No additional comments on the check we came up with, thanks for fixing the tests!!

return funcs, fail


def objfunc_no_con(xdict):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch, I assume the new check had these tests failing right away, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you're right

@marcomangano marcomangano mentioned this pull request Jul 3, 2024
13 tasks
@marcomangano
Copy link
Contributor

@lamkina @ewu63 @sseraj can you check and merge this soon so we can go ahead and make a new release?

@lamkina
Copy link
Contributor

lamkina commented Jul 4, 2024

Do we have a unit test that confirms the standard way of adding linear constraints is working as expected? If not, can that be added to this PR? If it exists and I missed it, then point me to the test and I'll approve this PR.

This would just be as simple as adding a few linear constraints to a valid opt prob and then making sure the number of linear constraints and the Jacobian are correct.

@kanekosh
Copy link
Contributor Author

kanekosh commented Jul 6, 2024

I don't know if there's a test that checks the number of linear constraints, but we already have a few tests that include linear constraints and assert equal on the optimal solution, which validates that linear constraints are properly imposed.

@lamkina
Copy link
Contributor

lamkina commented Jul 6, 2024

That's good enough for me. Thanks for the double check!

@lamkina lamkina merged commit d96a398 into mdolab:main Jul 6, 2024
12 of 13 checks passed
@kanekosh kanekosh deleted the lincon_docs branch July 8, 2024 22:01
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.

4 participants