From edb038b10623733799a36b0cd51be7d3ee3906a6 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 29 Feb 2024 12:47:49 -0500 Subject: [PATCH] Improving tests for degeneracy hunter --- .../core/util/tests/test_model_diagnostics.py | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/idaes/core/util/tests/test_model_diagnostics.py b/idaes/core/util/tests/test_model_diagnostics.py index a585159a80..9d6be1fe36 100644 --- a/idaes/core/util/tests/test_model_diagnostics.py +++ b/idaes/core/util/tests/test_model_diagnostics.py @@ -2002,23 +2002,32 @@ def test_solve_candidates_milp(self, model, scip_solver): dh._prepare_candidates_milp() dh._solve_candidates_milp() + assert dh.degenerate_set == { + model.con2: value(dh.candidates_milp.nu[0]), + model.con5: value(dh.candidates_milp.nu[1]), + } + assert abs(value(dh.candidates_milp.nu[0])) == pytest.approx(1e-05, rel=1e-5) assert abs(value(dh.candidates_milp.nu[1])) == pytest.approx(1e-05, rel=1e-5) - assert value(dh.candidates_milp.y_pos[0]) == pytest.approx(0, abs=1e-5) - assert value(dh.candidates_milp.y_pos[1]) == pytest.approx(0, rel=1e-5) + # One must be positive and one must be negative, so produce will be negative + assert value( + dh.candidates_milp.nu[0] * dh.candidates_milp.nu[1] + ) == pytest.approx(-1e-10, rel=1e-5) - assert value(dh.candidates_milp.y_neg[0]) == pytest.approx(0, abs=1e-5) - assert value(dh.candidates_milp.y_neg[1]) == pytest.approx(1, abs=1e-5) + assert ( + value( + dh.candidates_milp.y_pos[0] + + dh.candidates_milp.y_pos[1] + + dh.candidates_milp.y_neg[0] + + dh.candidates_milp.y_neg[1] + ) + >= 1 + ) assert value(dh.candidates_milp.abs_nu[0]) == pytest.approx(1e-05, rel=1e-5) assert value(dh.candidates_milp.abs_nu[1]) == pytest.approx(1e-05, rel=1e-5) - assert dh.degenerate_set == { - model.con2: value(dh.candidates_milp.nu[0]), - model.con5: value(dh.candidates_milp.nu[1]), - } - @pytest.mark.unit def test_prepare_ids_milp(self, model): dh = DegeneracyHunter2(model)