Skip to content

Solver Refactor Pt. 2: Restructure for Future Redesign #3476

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

Merged
merged 73 commits into from
Mar 19, 2025

Conversation

mrmundt
Copy link
Contributor

@mrmundt mrmundt commented Feb 18, 2025

Fixes #1030 (doesn't actually fix it; just the next step)

Summary/Motivation:

This is meant to be a "mid-point" for the ongoing solver refactor. It is currently working in this form, so this PR is intended to merge changes up to now so we can start making more fine-tuned changes that are easier to track.

Changes proposed in this PR:

  • Introduce highs
  • Restructure the directory tree
  • Rework some tests for clarity
  • Reduce duplicate code
  • Apply static analysis suggestions (pylint)

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.

from pyomo.core.expr.numvalue import NumericConstant
from pyomo.contrib.solver.util import collect_vars_and_named_exprs, get_objective
from pyomo.contrib.solver.common.results import Results
from pyomo.contrib.solver.common.util import collect_vars_and_named_exprs, get_objective


class PersistentSolverUtils(abc.ABC):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOT TODO for this PR:

  • What is the intent of this class?
    • To manage automatic checking of state / checking differences in the model and updating them; implements the "Auto" part of APPSI
    • What is a better name? PersistentSolverStateTracker? This is the classic "is-a" vs. "has-a". Other ideas: PersistentSolverChangeDetector, PersistentModelStateManager, PersistentSolverUpdater

Summary: We don't want the persistent solver interfaces to inherit from this; we want the classes to be able to contain one of these classes and use it. ModelChangeObserver

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also probably won't need the _func_name and func_name standard here when re-worked.

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 90.43210% with 93 lines in your changes missing coverage. Please review.

Project coverage is 88.62%. Comparing base (ab59eb2) to head (2f0f8be).

Files with missing lines Patch % Lines
pyomo/contrib/solver/solvers/highs.py 93.48% 32 Missing ⚠️
pyomo/contrib/solver/solvers/gurobi_persistent.py 80.89% 17 Missing ⚠️
pyomo/contrib/solver/solvers/sol_reader.py 83.69% 15 Missing ⚠️
pyomo/contrib/solver/common/base.py 86.44% 8 Missing ⚠️
pyomo/contrib/solver/solvers/gurobi_direct.py 86.53% 7 Missing ⚠️
pyomo/contrib/solver/common/persistent.py 88.63% 5 Missing ⚠️
pyomo/contrib/solver/common/results.py 72.22% 5 Missing ⚠️
pyomo/contrib/solver/common/util.py 96.61% 2 Missing ⚠️
pyomo/contrib/solver/solvers/ipopt.py 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3476      +/-   ##
==========================================
- Coverage   88.64%   88.62%   -0.02%     
==========================================
  Files         881      882       +1     
  Lines      100873   101370     +497     
==========================================
+ Hits        89421    89843     +422     
- Misses      11452    11527      +75     
Flag Coverage Δ
linux 86.11% <90.12%> (+0.03%) ⬆️
osx 76.18% <83.64%> (+0.08%) ⬆️
other 86.59% <90.12%> (-0.01%) ⬇️
win 81.03% <89.09%> (-3.53%) ⬇️

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.

Copy link
Contributor

@michaelbynum michaelbynum left a comment

Choose a reason for hiding this comment

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

After this PR is merged, we need to port some of the recent changes in appsi to here.

@michaelbynum
Copy link
Contributor

I have now gone through all of the changed files.

return default_config_block(self, init)[0]

def set_options(self, options):
"""
Method to manually set options; can be called outside of the solve method
"""
opts = {k: v for k, v in options.value().items() if v is not None}
Copy link
Member

Choose a reason for hiding this comment

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

This implementation implicitly assumes options is a ConfigDict. We should update the documentation to include argument type specification, and then update the implementation to accept dict or ConfigDict (by dropping the call to value():

        opts = {k: v for k, v in options.items() if v is not None}

return objective


class _VarAndNamedExprCollector(ExpressionValueVisitor):
Copy link
Member

Choose a reason for hiding this comment

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

TODO (later): this should be ported to the StreamBasedExpressionVisitor

Copy link
Contributor

Choose a reason for hiding this comment

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

I have lots of these conversions to do...

@mrmundt mrmundt merged commit 2d05305 into Pyomo:main Mar 19, 2025
91 of 93 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.

[PEP] Redesign of Pyomo Solvers
4 participants