Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DegeneracyHunter tests more robust wrt different solutions #1360

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading