Skip to content

Model Observer #3695

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Model Observer #3695

wants to merge 15 commits into from

Conversation

michaelbynum
Copy link
Contributor

Summary/Motivation:

This PR extracts the code for detecting changes in models from the persistent solver interfaces to its own, independent functionality. I will have a separate PR shortly that removes the code from the solver interfaces and updates them to use this code.

Changes proposed in this PR:

  • add a module to contrib called observer that can be used to inform other classes of what changed in a pyomo model.

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.

Copy link

codecov bot commented Aug 13, 2025

Codecov Report

❌ Patch coverage is 82.19697% with 94 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.17%. Comparing base (756c2c1) to head (d718e9a).

Files with missing lines Patch % Lines
pyomo/contrib/observer/model_observer.py 81.74% 90 Missing ⚠️
pyomo/contrib/observer/component_collector.py 88.57% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3695      +/-   ##
==========================================
- Coverage   89.20%   89.17%   -0.04%     
==========================================
  Files         892      894       +2     
  Lines      103018   103546     +528     
==========================================
+ Hits        91894    92332     +438     
- Misses      11124    11214      +90     
Flag Coverage Δ
builders 26.67% <17.42%> (-0.05%) ⬇️
default 85.75% <82.19%> (?)
expensive 33.99% <17.42%> (?)
linux 86.92% <82.16%> (-2.01%) ⬇️
linux_other 86.92% <82.16%> (-0.03%) ⬇️
osx 83.26% <82.16%> (-0.01%) ⬇️
win 85.14% <82.16%> (-0.01%) ⬇️
win_other 85.14% <82.16%> (-0.01%) ⬇️

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.

"""


class AutoUpdateConfig(ConfigDict):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the intent that this lives here, not in pyomo.contrib.solver.common.config? If so, delete it there; otherwise, import it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of the deletions from pyomo.contrib.solver related to this will be in a separate PR after I refactor those interfaces to use this. For now, it will have to be in both places.

)


class Observer(abc.ABC):
Copy link
Contributor

Choose a reason for hiding this comment

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

Channeling John here - does this need to inherit from abc.ABC? What does it get us that NotImplemented doesn't deliver?

Also, this is basically the same as part of PersistentSolverBase. Again, what is the long term intent? Will PersistentSolverBase end up inheriting from this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will eventually delete PersistentSolverBase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But not quite yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ABC forces all derived classes to implement the specified methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really don't understand the dislike of ABC

obs.add_parameters(params)

def _check_for_new_vars(self, variables: List[VarData]):
new_vars = {}

Choose a reason for hiding this comment

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

Isn't enough to make new_vars a list and append non referenced variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right!

Choose a reason for hiding this comment

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

I think also this pattern is repeated multiple times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants