Skip to content

Fixing Gurobi direct MINLP tests to work with Gurobi 14 - #4104

Merged
blnicho merged 12 commits into
Pyomo:mainfrom
emma58:gurobi-14
Nov 19, 2026
Merged

blnicho merged 12 commits into
Pyomo:mainfrom
emma58:gurobi-14

Conversation

@emma58

@emma58 emma58 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #4084

Summary/Motivation:

Nothing is actually wrong with the current MINLP writer with Gurobi 14 (though we can make it better, which I'm deferring): However, nonlinear constraints became regular citizens in a way that changed a lot of the public APIs we are using for testing. This PR updates the tests, generalizing how we get/test the nonlinear constraints into two separate (tiny) base classes, one for Gurobi versions >= 12 and < 14 and the other for versions >= 14.

Changes proposed in this PR:

  • Generalizes testing of nonlinear expression for the Gurobi direct MINLP writers
  • Adds handling for the "minus" opcode in the gurobi-to-pyomo expression writer we use for testing since in Gurobi 14, all our nonlinear constraints will come in the form "aux_var - general_nonlinear_expr == 0"
  • Reverts the change to declare Gurobi 14 an incompatible version for the writer.

AI-Use Disclosure

I used @jsiirola instead! :)

  • [X ] AI tools were NOT used during the preparation of this PR

or

  • AI tools contributed to the development of this PR

    • AI tools generated documentation (including the PR description/comments, code comments, and/or Sphinx documentation)
    • AI tools generated tests (baselines, examples, and/or code)
    • AI tools generated code (apart from tests)

    Review process (select ONE):

    • Rewritten: All AI-generated content was rewritten by me before being committed.
    • Reviewed/verified: I retained AI-generated content and verified it before committing. Verification included (as applicable):
      • Ran the code and fixed issues
      • Added and ran tests
      • Checked correctness/logic of code and tests
      • Checked for alignment with the contribution guide
      • Considered security implications
    • As-is: AI-generated content was commited directly to the repository

Notes for reviewers (optional):

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.

@blnicho blnicho moved this from Todo to Review In Progress in November 2026 Release Nov 18, 2026

@unittest.skipUnless(old_gurobipy_available, "Gurobipy >= 12 and < 14 is not available")
@unittest.pytest.mark.solver("gurobi_direct_minlp")
class TestOldGurobiMINLPWriter(GurobiMINLPWalkerTests, CommonTest):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You did this in test_gurobi_minlp_writer.py already but should this class inherit from OldGurobiTest so you don't have to duplicate the implementation of these methods?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, whoops, that is totally what I meant to do!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, whoops, that is totally what I meant to do!


@unittest.skipUnless(gurobipy_14_available, "Gurobipy >= 14 is not available")
@unittest.pytest.mark.solver("gurobi_direct_minlp")
class TestGurobi14MINLPWalker(GurobiMINLPWalkerTests, CommonTest):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You did this in test_gurobi_minlp_writer.py already but should this class inherit from Gurobi14Test so you don't have to duplicate the implementation of these methods?

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.30%. Comparing base (41182da) to head (bc63c10).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4104   +/-   ##
=======================================
  Coverage   90.30%   90.30%           
=======================================
  Files         920      920           
  Lines      109618   109612    -6     
=======================================
- Hits        98987    98984    -3     
+ Misses      10631    10628    -3     
Flag Coverage Δ
builders 29.12% <ø> (-0.01%) ⬇️
default 86.51% <ø> (?)
expensive 35.24% <ø> (?)
linux 87.85% <ø> (-1.96%) ⬇️
linux_other 87.85% <ø> (-0.01%) ⬇️
oldsolvers 28.03% <ø> (-0.01%) ⬇️
osx 83.29% <ø> (?)
win 85.57% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@jsiirola jsiirola left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In addition to @blnicho's comments, 2 other minor changes (one I think should go in, the other is an optional "nice-to-have" efficiency):

@github-project-automation github-project-automation Bot moved this from Review In Progress to Reviewer Approved in November 2026 Release Nov 19, 2026
@blnicho
blnicho merged commit 9800633 into Pyomo:main Nov 19, 2026
33 of 34 checks passed
@github-project-automation github-project-automation Bot moved this from Reviewer Approved to Done in November 2026 Release Nov 19, 2026
@emma58
emma58 deleted the gurobi-14 branch November 19, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

Add Gurobi 14 MINLP support

4 participants