Add TestExactHullQuadratic tests and extract models into models.py#5
Add TestExactHullQuadratic tests and extract models into models.py#5sergey-gusev94 merged 4 commits intoex_hullfrom
Conversation
…ic feature Co-authored-by: sergey-gusev94 <[email protected]>
exact_hull_quadratic hull reformulation
|
Create models that you need in sepearate model file, similar how it is done for other tests |
…unctions Co-authored-by: sergey-gusev94 <[email protected]>
exact_hull_quadratic hull reformulationThere was a problem hiding this comment.
Pull request overview
This PR centralizes model construction for the hull transformation’s exact_hull_quadratic test coverage by adding dedicated factory functions in pyomo/gdp/tests/models.py and using them from pyomo/gdp/tests/test_hull.py for a new/updated TestExactHullQuadratic test suite.
Changes:
- Added eight
makeTwoTermDisj_*model factory functions for quadratic exact-hull testing topyomo/gdp/tests/models.py. - Added
TestExactHullQuadratictests inpyomo/gdp/tests/test_hull.pythat construct models viamodels.*factories and validate conic/general exact-hull reformulations and mappings. - Introduced NumPy gating and a mocked “NumPy unavailable” guard test in the hull test suite.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
pyomo/gdp/tests/test_hull.py |
Adds a NumPy-gated TestExactHullQuadratic suite exercising exact-hull quadratic behavior, including mappings and eigenvalue tolerance behavior. |
pyomo/gdp/tests/models.py |
Adds reusable model factory functions for the quadratic exact-hull tests to align with existing GDP test-suite model patterns. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @unittest.skipUnless(numpy_available, "NumPy is not available") | ||
| class TestExactHullQuadratic(unittest.TestCase): |
There was a problem hiding this comment.
The class-level @skipUnless(numpy_available) prevents the "numpy unavailable" behavior from being tested in an environment where NumPy is actually missing. In particular, test_numpy_unavailable_raises_error will be skipped when numpy_available is False, even though it is meant to validate that code path. Consider moving that test outside the skipped class (or applying the skip decorator only to tests that truly require NumPy), so that the error path is covered in minimal environments.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
Apply the skip decorator only to tests that truly require NumPy
There was a problem hiding this comment.
Done in commit 40c0077. Removed the class-level @skipUnless(numpy_available) decorator and added individual @skipUnless(numpy_available, "NumPy is not available") decorators to each of the 10 tests that actually require NumPy. test_numpy_unavailable_raises_error is left undecorated so it runs in all environments, including ones where NumPy is absent. Also updated test_eigenvalue_tolerance_permissive to use eigenvalue_tolerance=1e-9 (a clearly non-default permissive value) instead of 1e-10 (which happened to match the default).
| @unittest.skipUnless(numpy_available, "NumPy is not available") | ||
| class TestExactHullQuadratic(unittest.TestCase): | ||
| """Tests for the ``exact_hull_quadratic`` option of the hull transformation. | ||
|
|
There was a problem hiding this comment.
PR description says this change only extracts existing inline models and that no test logic changed, but this diff introduces an entirely new TestExactHullQuadratic test class (and new imports) in test_hull.py. Please either update the PR description/title to reflect that new tests are being added, or (if these tests existed before) ensure the diff includes the corresponding removals/moves so reviewers can confirm it's a pure refactor.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
update the PR description/title
There was a problem hiding this comment.
Updated the PR title to "Add TestExactHullQuadratic tests with models extracted to models.py" and rewrote the description to accurately reflect that this PR adds a new 11-test TestExactHullQuadratic class (not a pure refactor), along with the eight model factory functions in models.py.
| (-1e-11). With the default tolerance of 1e-10 the eigenvalue is | ||
| within the tolerance band and Q is treated as PSD → conic | ||
| reformulation. | ||
| """ | ||
| m = models.makeTwoTermDisj_NearPSDQuad() | ||
|
|
||
| m_perm = self.hull.create_using( | ||
| m, exact_hull_quadratic=True, eigenvalue_tolerance=1e-10 |
There was a problem hiding this comment.
The docstring describes this as using a "larger" eigenvalue_tolerance than default, but the test passes 1e-10, which matches gdp.hull's current default eigenvalue_tolerance. Either adjust the wording to indicate it's the default tolerance, or change the test to use a non-default permissive value so the test actually demonstrates the configuration effect.
| (-1e-11). With the default tolerance of 1e-10 the eigenvalue is | |
| within the tolerance band and Q is treated as PSD → conic | |
| reformulation. | |
| """ | |
| m = models.makeTwoTermDisj_NearPSDQuad() | |
| m_perm = self.hull.create_using( | |
| m, exact_hull_quadratic=True, eigenvalue_tolerance=1e-10 | |
| (-1e-11). The default eigenvalue_tolerance in gdp.hull is 1e-10; | |
| here we use a larger, more permissive tolerance (1e-9) so the | |
| eigenvalue is well within the tolerance band and Q is treated as | |
| PSD → conic reformulation. | |
| """ | |
| m = models.makeTwoTermDisj_NearPSDQuad() | |
| m_perm = self.hull.create_using( | |
| m, exact_hull_quadratic=True, eigenvalue_tolerance=1e-9 |
…envalue_tolerance in permissive test Co-authored-by: sergey-gusev94 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Adds a
TestExactHullQuadratictest suite for theexact_hull_quadraticoption of the hull transformation, and places all required test models inpyomo/gdp/tests/models.pyfollowing the convention used throughout the rest of the GDP test suite.pyomo/gdp/tests/models.pyEight new factory functions added at the end of the file:
d1makeTwoTermDisj_ConvexQuadUB()x**2 + y**2 <= 4makeTwoTermDisj_ConvexQuadLB()-x**2 - y**2 >= -4makeTwoTermDisj_NonconvexQuad()x**2 - y**2 <= 1makeTwoTermDisj_QuadEquality()x**2 + y**2 == 4makeTwoTermDisj_QuadRange()1 <= x**2 + y**2 <= 4makeTwoTermDisj_NearPSDQuad()x**2 - 1e-11*y**2 <= 4makeTwoTermDisj_ConvexQuad_LinearTerms()x**2 + 3*x + 2 <= 0makeTwoTermDisj_NonconvexQuad_LinearTerms()x**2 - y**2 + 3*x - 2 <= 0pyomo/gdp/tests/test_hull.pyNew
TestExactHullQuadraticclass with 11 tests covering:eigenvalue_tolerancepermissive (1e-9, non-default) → treats near-PSD as PSDeigenvalue_tolerancestrict (1e-12) → rejects near-PSD matrixget_transformed_constraintsmapping preservedThe class-level
@skipUnless(numpy_available)has been replaced with per-test decorators on each test that genuinely requires NumPy.test_numpy_unavailable_raises_erroris intentionally left undecorated so it validates the error-path in environments where NumPy is absent.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.