Closed eslickj closed 2 weeks ago
Attention: Patch coverage is 41.66667%
with 21 lines
in your changes are missing coverage. Please review.
Project coverage is 88.55%. Comparing base (
6fb0c5d
) to head (19df8be
). Report is 82 commits behind head on main.
Files | Patch % | Lines |
---|---|---|
pyomo/contrib/viewer/ui.py | 42.30% | 15 Missing :warning: |
pyomo/contrib/viewer/model_select.py | 25.00% | 6 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Summary/Motivation:
When you are working with the model viewer in Jupyter (Lab, qtconsole...) usually your Pyomo model is stored in main. This isn't necessarily the case, but it is more than likely, and if we assume that is the case we can do a few things to make the viewer easier to work with. This adds an option to specify the model by its variable name in main rather than directly specifying the model by pointer. This is just a new option and doesn't change the default behavior. In jupyter there is a callback that causes the model view to refresh every time you run a command. When you use the new option, the refresh will also check the model id to see if it has changed and load the new model if it has.
This also changes what happens if you open the UI without specifying a model. It looks in the main namespace and pulls out the first pyomo model it finds based on the order of dir(main), which I think is alphabetical. In the qtconsole-based model-viewer, it no longer creates an empty model if it can't find one, it just shows the viewer empty, and you'll have to point it at a model after you create one.
The main motivation for this is that it saves me (and hopefully anyone else that uses the viewer) a lot of time selecting the model in the UI. A lot of times I create a model by running a script. This lets me run the script and open the UI without explicitly selecting the model. Then I often find something need changed in the model which is easier done by updating the script. This lets me rerun the script overwriting the model and having the UI update without having to go back and select the model again. This also avoids confusion where the user may not realize they are looking at an older version of the model.
Changes proposed in this PR:
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: