Skip to content

Commit

Permalink
Make DegeneracyHunter tests more robust wrt different solutions (#1360
Browse files Browse the repository at this point in the history
)

* Improving tests for degeneracy hunter

* Restore SCIP installation step w/o version pinning in setup-idaes Action
  • Loading branch information
lbianchi-lbl authored Mar 1, 2024
1 parent 9de79c6 commit e1430e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
11 changes: 6 additions & 5 deletions .github/actions/setup-idaes/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ inputs:
description: 'Command to use to install `install-target`'
required: false
default: pip --no-cache-dir install --progress-bar off
ampl-scip-version:
description: Version of AMPL Scip solver to install
ampl-scip-pip-target:
description: pip install target (dist name and optionally version constraint) of AMPL SCIP solver to install
required: false
default: '20240121'
default: ampl-module-scip
runs:
using: "composite"
steps:
Expand Down Expand Up @@ -46,9 +46,10 @@ runs:
echo '::group::Output of "idaes get-extensions" command'
idaes get-extensions --extra petsc --verbose
echo '::endgroup::'
- name: Install SCIP from AMPL
- name: Install AMPL SCIP (${{ inputs.ampl-scip-pip-target }})
if: inputs.ampl-scip-pip-target
shell: bash -l {0}
run: |
echo '::group::Output of "pip install ampl_module_scip" command'
${{ inputs.install-command }} --index-url https://pypi.ampl.com ampl_module_scip==${{ inputs.ampl-scip-version }}
${{ inputs.install-command }} --index-url https://pypi.ampl.com ${{ inputs.ampl-scip-pip-target }}
echo '::endgroup::'
31 changes: 20 additions & 11 deletions idaes/core/util/tests/test_model_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1974,23 +1974,32 @@ def test_solve_candidates_milp(self, model, scip_solver):
dh._prepare_candidates_milp()
dh._solve_candidates_milp()

assert value(dh.candidates_milp.nu[0]) == pytest.approx(1e-05, rel=1e-5)
assert value(dh.candidates_milp.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]),
}

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)
Expand Down

0 comments on commit e1430e1

Please sign in to comment.