pyoptsparse icon indicating copy to clipboard operation
pyoptsparse copied to clipboard

Added linear constraint check and updated documentation

Open kanekosh opened this issue 8 months ago • 3 comments

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

  • [x] 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)
  • [x] 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
  • [x] I have run unit and regression tests which pass locally with my changes
  • [x] I have added new tests that prove my fix is effective or that my feature works
  • [x] I have added necessary documentation

kanekosh avatar Jun 26 '24 20:06 kanekosh