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

fix scip results processing #3023

Merged
merged 3 commits into from
Oct 31, 2023
Merged

fix scip results processing #3023

merged 3 commits into from
Oct 31, 2023

Conversation

michaelbynum
Copy link
Contributor

@michaelbynum michaelbynum commented Oct 26, 2023

Summary

With SCIP 8.0.3, the results processing is currently broken:

import ampl_module_scip
import os
os.environ['PATH'] = os.pathsep.join([ampl_module_scip.bin_dir, os.environ['PATH']])
import pyomo.environ as pyo


m = pyo.ConcreteModel()
m.x = pyo.Var(domain=pyo.Integers)
m.objective = pyo.Objective( expr= m.x)
m.con = pyo.Constraint(expr= m.x >= 1)

opt = pyo.SolverFactory('scip')
results = opt.solve(m, tee=True)

Outputs:

WARNING: No dual information available when presolving was performed.
WARNING: Unexpected SCIP solver message: SCIP 8.0.3\x3a optimal solution;
objective 1; 0 simplex iterations; 0 branching nodes
Traceback (most recent call last):
  File "/Users/.../pyomo_with_scip.py", line 13, in <module>
    results = opt.solve(m, tee=True)
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../pyomo/pyomo/opt/base/solvers.py", line 661, in solve
    _model.solutions.load_from(
  File "/Users/.../pyomo/pyomo/core/base/PyomoModel.py", line 230, in load_from
    raise ValueError(
ValueError: Cannot load a SolverResults object with bad status: unknown

To correct this, I changed the bit of code that parses the solver message to be more flexible by checking if specific strings are in the message instead of checking if they are equal. In this case, Pyomo is looking for "optimal solution found", but the message is just "optimal solution".

The other problem is the SCIP log is parsed to get the primal bound. However, the log parsing does not work properly if SCIP solves the problem in the preprocessing phase. To fix this, I added a try/except and simply leave the primal bound empty if the log is not parsed correctly.

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.

@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (96c4c0b) 85.31% compared to head (f400b5e) 87.87%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3023      +/-   ##
==========================================
+ Coverage   85.31%   87.87%   +2.56%     
==========================================
  Files         763      769       +6     
  Lines       89308    89520     +212     
==========================================
+ Hits        76191    78670    +2479     
+ Misses      13117    10850    -2267     
Flag Coverage Δ
linux 85.20% <80.00%> (-0.01%) ⬇️
osx 75.00% <0.00%> (-0.01%) ⬇️
other 85.38% <80.00%> (-0.01%) ⬇️
win 82.42% <80.00%> (-0.01%) ⬇️

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

Files Coverage Δ
pyomo/solvers/plugins/solvers/SCIPAMPL.py 71.84% <80.00%> (-0.50%) ⬇️

... and 106 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

results.problem.lower_bound = results.solver.primal_bound
else:
results.problem.upper_bound = results.solver.primal_bound
except AttributeError:
Copy link
Member

Choose a reason for hiding this comment

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

@michaelbynum would you mind adding a short comment here explaining why this is needed or when you would end up here? Is this from a difference in solver versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Sorry - I was in a hurry yesterday.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I only added comments to the PR. Now, I've added comments to the code.

@mrmundt
Copy link
Contributor

mrmundt commented Oct 30, 2023

@michaelbynum - Jenkins failures are not related. Our build environment was the problem. I have fixed it and flagged this for re-test.

@blnicho blnicho merged commit 00e9324 into Pyomo:main Oct 31, 2023
30 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants