Skip to content

Rework SolutionLoader#3701

Open
michaelbynum wants to merge 27 commits intoPyomo:mainfrom
michaelbynum:solver_api
Open

Rework SolutionLoader#3701
michaelbynum wants to merge 27 commits intoPyomo:mainfrom
michaelbynum:solver_api

Conversation

@michaelbynum
Copy link
Contributor

Summary/Motivation:

This PR updates the solution loader in pyomo/contrib/solver based on recent design discussions.

Changes proposed in this PR:

  • add get_number_of_solutions method
  • add get_solution_ids method
  • add load_solution_method
  • add load_import_suffixes method
  • add solution_id as an argument to methods

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.

@michaelbynum michaelbynum changed the title Rework SolutionLoader [Depends on #3698] Rework SolutionLoader Aug 13, 2025
@codecov
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

❌ Patch coverage is 77.40113% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.12%. Comparing base (749e3ac) to head (0338bcc).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
pyomo/contrib/solver/solvers/asl_sol_reader.py 81.63% 9 Missing ⚠️
pyomo/contrib/solver/solvers/gms_sol_reader.py 62.50% 9 Missing ⚠️
pyomo/contrib/solver/common/solution_loader.py 86.66% 6 Missing ⚠️
...ontrib/solver/solvers/gurobi/gurobi_direct_base.py 64.70% 6 Missing ⚠️
pyomo/contrib/solver/solvers/highs.py 64.28% 5 Missing ⚠️
...contrib/solver/solvers/gurobi/gurobi_persistent.py 71.42% 4 Missing ⚠️
pyomo/contrib/solver/solvers/ipopt.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3701      +/-   ##
==========================================
- Coverage   89.47%   88.12%   -1.36%     
==========================================
  Files         908      908              
  Lines      106738   106951     +213     
==========================================
- Hits        95509    94253    -1256     
- Misses      11229    12698    +1469     
Flag Coverage Δ
builders 29.08% <29.37%> (-0.01%) ⬇️
default 85.94% <77.40%> (?)
expensive 35.50% <29.37%> (?)
linux 34.57% <29.37%> (-54.61%) ⬇️
linux_other 34.57% <29.37%> (-52.58%) ⬇️
oldsolvers 27.99% <29.37%> (+0.47%) ⬆️
osx ?
win ?
win_other ?

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blnicho blnicho removed this from Pyomo 6.10 Feb 4, 2026
@michaelbynum michaelbynum changed the title [Depends on #3698] Rework SolutionLoader Rework SolutionLoader Feb 11, 2026
Copy link
Member

@jsiirola jsiirola left a comment

Choose a reason for hiding this comment

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

A couple minor questions that don't need to hold up the PR and one significant one that probably does (it look like the ASL solution loader is not loading all import suffixes).

Comment on lines +35 to +36
for k, v in solution_loader.get_duals(solution_id=solution_id).items():
dual_suffix[k] = v
Copy link
Member

Choose a reason for hiding this comment

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

Some questions:

  • Should the Suffix be cleared before loading?
  • Could this just be:
Suggested change
for k, v in solution_loader.get_duals(solution_id=solution_id).items():
dual_suffix[k] = v
dual_suffix.update(solution_loader.get_duals(solution_id=solution_id))

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.

vars_to_load: list
A list of the variables whose solution value should be retrieved. If vars_to_load
is None, then the values for all variables will be retrieved.
solution_id: Optional[Any]
Copy link
Member

Choose a reason for hiding this comment

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

Instead of Optional[Type], I believe the current "preferred Python" annotation is Type | None. In this case, since Any includes None, I think you could just do Any (although Any | None is a little more explicit).

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.

Comment on lines +76 to +77
def load_import_suffixes(self, solution_id=None):
load_import_suffixes(self._pyomo_model, self, solution_id=solution_id)
Copy link
Member

Choose a reason for hiding this comment

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

This only loads duals and rc ... the ASL supports arbitrary inpirt suffixes, which I think need to be supported here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you give me an example of what ASLSolFileData would look like if it had other suffixes. I see that it has attributes like var_suffixes. I assume the keys are the names of the suffixes, and the values map the variable indices to the suffix values? Any suggestions on how to test this?

Copy link
Member

Choose a reason for hiding this comment

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

Yes: Suffix data comes back from the ASL flagged for "variables", "constraints", "objectives", and the "problem". We blindly parse that into the corresponding attributes (var_suffixes, etc).

  • For var, con, and obj, the dict maps suffix name to a dict that maps the 0-based integer index of the relevant variable / constraint / objective in the corresponding list in the NLWriterInfo returned by the writer tot he suffix value.
  • For the problem, since there is only one problem, the problem_suffixes dict just maps suffix name to value.

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 - kind of. I just raise an error if any variables are eliminated or any scaling is done.

@blnicho blnicho requested a review from jsiirola March 17, 2026 19:27
@michaelbynum
Copy link
Contributor Author

michaelbynum commented Mar 17, 2026

@AnhTran01 , @boxblox - could you please take a look at the changes to the gams solution loader?

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