Skip to content

SNOPT linear constraints have incorrect bounds with offset - #495

Open
ewu63 wants to merge 12 commits into
mainfrom
bugfix/offset-snopt
Open

ewu63 wants to merge 12 commits into
mainfrom
bugfix/offset-snopt

Conversation

@ewu63

@ewu63 ewu63 commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Purpose

This is a bug on passing the bounds of linear constraints to SNOPT, when using offset.

In this case, we must pass lb <= Ax <= ub. However, with x in opt space, we have lb' <= A' x' <= ub' as passed to SNOPT, where

  • x' = (x - offset) * scale
  • A' = scale * A
  • lb' = lb - 1/scale * A * offset
    It is this -1/scale * A * offset that was missing for linear constraints. Thankfully I think we almost never use offset, but still a very scary bug. This is now reproduced and fixed.

Conditions where this bug will affect optmization results (all must apply):

  1. Optimizer is SNOPT.
  2. Some non-zero offset exists, and that corresponding DV has an active constraint whose linear Jacobian is nonzero
  3. There is more than one linear constraint, or there is exactly one constraint but there was at least one nonlinear constraint.

Expected time until merged

A few days.

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 ruff check and ruff format 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

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.22%. Comparing base (c791384) to head (b3c7bd1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #495   +/-   ##
=======================================
  Coverage   54.22%   54.22%           
=======================================
  Files           1        1           
  Lines         225      225           
=======================================
  Hits          122      122           
  Misses        103      103           

☔ View full report in Codecov by Harness.
📢 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.

marcomangano
marcomangano previously approved these changes Sep 25, 2026

@marcomangano marcomangano left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good stuff! Let me know how I can help

Comment thread pyoptsparse/pyOpt_utils.py Resolved
Comment thread pyoptsparse/pySNOPT/pySNOPT.py Resolved
Comment thread tests/test_snopt_bugfix.py Resolved
@ewu63
ewu63 marked this pull request as ready for review September 26, 2026 23:50
@marcomangano
marcomangano requested a review from a team as a code owner November 17, 2026 17:21
@marcomangano
marcomangano requested a review from mpdutta November 17, 2026 17:21
@ewu63

ewu63 commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

@mpdutta @sanjan98 can one of you review this PR?

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.

2 participants