Skip to content

Fix/ldsda fix#2

Merged
bernalde merged 18 commits intoSECQUOIA:mainfrom
Toflamus:fix/ldsda-fix
Feb 2, 2026
Merged

Fix/ldsda fix#2
bernalde merged 18 commits intoSECQUOIA:mainfrom
Toflamus:fix/ldsda-fix

Conversation

@Toflamus
Copy link
Copy Markdown

Fixes # .

Summary/Motivation:

Description

Fixed a bug in ldsda.py where the line_search method failed to correctly unpack the tuple return value from _solve_GDP_subproblem.

Testing

Ran pytest locally on the new test file.

Verified code coverage passes requirements.

Formatted code using black.

Changes proposed in this PR:

  • Modified line_search in pyomo/contrib/gdpopt/ldsda.py to unpack (primal_improved, primal_bound).
  • Added a unit test TestLDSDAUnit in pyomo/contrib/gdpopt/tests/test_ldsda.py to verify the logic handles tuple returns correctly without infinite loops.

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

Copy link
Copy Markdown
Member

@bernalde bernalde left a comment

Choose a reason for hiding this comment

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

What is the coverage on the ldsda after this change?

Copy link
Copy Markdown
Member

@AlbertLee125 AlbertLee125 left a comment

Choose a reason for hiding this comment

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

I would strongly recommend restoring test_ldsda.py by removing MagicMock.

Copy link
Copy Markdown
Member

@AlbertLee125 AlbertLee125 left a comment

Choose a reason for hiding this comment

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

Return test_ldsda.py back to its original code.

@AlbertLee125
Copy link
Copy Markdown
Member

There was a bug in the line_search function in Pyomo’s GDPopt LDSDA implementation (ldsda.py, line 435).
Since _solve_GDP_subproblem function returns both Boolean and non-Boolean values, we changed the assignment from primal_improved = _solve_GDP_subproblem to primal_improved, _ = _solve_GDP_subproblem` to prevent non-Boolean objects from propagating through the algorithms.

@bernalde
Copy link
Copy Markdown
Member

I think it might make sense to increase LDSDA tests to improve coverage, if that is something we want to do. Before just having a coding agent add new code, let's quantify how much coverage we would increase with these changes to the tests. Moreover, we need to test the bug that is being fixed by adding a new test that, with the previous implementation, would have failed (therefore revealing the bug) and now passes.

Copy link
Copy Markdown
Member

@bernalde bernalde left a comment

Choose a reason for hiding this comment

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

I approve this PR with the given changes, I would still want you to address the comments I have made to clean it up and will rerun a copilot review on it to be sure

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an LD-SDA implementation bug where line_search() incorrectly handled the tuple return value from _solve_GDP_subproblem(), and adds unit tests to prevent regressions.

Changes:

  • Update GDP_LDSDA_Solver.line_search() to unpack (primal_improved, primal_bound) and use the boolean flag correctly.
  • Expand test_ldsda.py with unit tests that exercise tuple-unpacking behavior and additional internal branches.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
pyomo/contrib/gdpopt/ldsda.py Fixes line_search() to correctly unpack _solve_GDP_subproblem() return values; adds/updates docstrings.
pyomo/contrib/gdpopt/tests/test_ldsda.py Adds new unit tests validating tuple-unpacking behavior and exercising additional LD-SDA branches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bernalde
Copy link
Copy Markdown
Member

bernalde commented Feb 1, 2026

Besides, this PR is failing the lint test, please follow the instructions here regarding black https://pyomo.readthedocs.io/en/stable/contribution_guide.html

AlbertLee125 and others added 6 commits February 2, 2026 09:01
Removed the documentation from the class docstring.

Co-authored-by: Copilot <[email protected]>
capitalized the notations.

Co-authored-by: Copilot <[email protected]>
Refine test class docstring to clarify focus on critical control-flow and validation.
Refine test description for clarity and focus.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

    * the test docstring/comment no longer references specific source line numbers.
    * unused test attribute (self.number_of_external_variables) removed.

2. Changed ldsda.py:
    * update the wording to “squared Euclidean distance” in the comment describing the tiebreaker logic.
@Toflamus
Copy link
Copy Markdown
Author

Toflamus commented Feb 2, 2026

Besides, this PR is failing the lint test, please follow the instructions here regarding black https://pyomo.readthedocs.io/en/stable/contribution_guide.html

image The current lint test problems come from other files

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…ailure

Previously, primal_bound was computed even when the solver returned an
unsuccessful termination condition. Now primal_bound is only computed
when primal_improved is True, making the behavior consistent with the
docstring that states primal_bound is None when the subproblem is infeasible.
Replace tabulate-based reformulation summary with simple logger output,
consistent with other GDPopt solvers. This avoids adding an unnecessary
dependency to the package.
@bernalde
Copy link
Copy Markdown
Member

bernalde commented Feb 2, 2026

Hi — I pushed two fixes to the fork branch SECQUOIA/pr-2:

  • Removed the tabulate dependency and replaced it with simple logger output.
  • Fixed _solve_GDP_subproblem so primal_bound is None when the solver fails (not just on preprocessing infeasibility).

All pyomo/contrib/gdpopt/tests/test_ldsda.py tests pass locally (10/10) and ldsda.py shows 100% coverage.

The branch with the fixes is: https://github.com/SECQUOIA/pyomo/tree/pr-2

Could you pull these changes into your Toflamus:fix/ldsda-fix branch so PR #2 is updated? Thanks!

@bernalde
Copy link
Copy Markdown
Member

bernalde commented Feb 2, 2026

I also created a PR directly into the branch that sets up this one, if you merge that PR, we should be good to go Toflamus#1

Removed the tabulate dependency and replaced it with simple logger output.
Fixed _solve_GDP_subproblem so primal_bound is None when the solver fails (not just on preprocessing infeasibility).
@bernalde bernalde requested a review from Copilot February 2, 2026 19:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bernalde bernalde merged commit e20f14c into SECQUOIA:main Feb 2, 2026
AlbertLee125 pushed a commit that referenced this pull request Feb 11, 2026
Address review feedback: use LinearRepnVisitor and fix var_name_dict
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