Skip to content

Remove dummy constraiint for when SNOPT only has linear constrants - #496

Draft
ewu63 wants to merge 3 commits into
mainfrom
fix/snopt-all-linear-nncon-zero
Draft

ewu63 wants to merge 3 commits into
mainfrom
fix/snopt-all-linear-nncon-zero

Conversation

@ewu63

@ewu63 ewu63 commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Purpose

For problems with only linear constraints, pySNOPT converted the first row into a nonlinear constraint since supplying only linear constraints did not work (this was added in commit 1a8df3c). This fake row always took the first constraint, in the order that it was added (jacIndices = [0]). But the bounds and Jacobian rows passed to SNOPT are reordered and come from getOrdering(["ne", "ni", "le", "li"]), which puts linear equalities before linear inequalities. If a linear inequality was added before a linear equality, SNOPT's first row got the inequality's value but the equality's bounds. TestSNOPTBug.test_opt_all_linear_inequality_before_equality reproduces this bug.

However, instead of fixing this bug directly, I realized that we probably didn't actually need this fake nonlinear constraint in the first place. SNOPT does in fact allow only linear constraints, you just have to pass nnCon = 0, nnJac=0, and neGcon = 0. We still need size-1 return from _user_fg_wrap because of how f2py callbacks are set up, but it's fine. The separate dummy row for fully unconstrained problems (optProb.dummyConstraint) is unchanged, that one is still required.

Expected time until merged

No rush, should probably wait for #495 to be merged first. A follow-on PR will add Lagrange multipliers for the linear constraints (with the previous hacky fix, the first row of linear constraints at least got the Lagrange multipliers).

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 27, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #496   +/-   ##
=======================================
  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.

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.

1 participant