pyomo icon indicating copy to clipboard operation
pyomo copied to clipboard

Pyomo.DoE bug fixes

Open adowling2 opened this issue 1 year ago • 9 comments

Fixes No issue

Summary/Motivation:

  • Minor enhancements in Pyomo.DoE in preparation for a tutorial/workshop

Changes proposed in this PR:

  • Fixed error about ambiguous a.any() versus a.all() for logical check of a list-like object
  • Added a TypeError to prevent a downstream cryptic error message
  • Update type checking per suggested best practices from @jsiirola and @mrmundt
  • Improved initialization of the Jacobian and Cholesky factorization
  • Added optionally passing theta parameter values into create_model when generating scenarios. This is especially helpful if create_model includes initialization such was using the simulator in pyomo.dae
  • Added more comments
  • Fixed degree of freedom issue by fixing the parameters on the nominal case model. This is important if create_model creates a full model in stage1 model. Our original design anticipated stage1 mode would be really lite, but that is inconvenient when trying to use the same create_model for parmest and pyomo.doe

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.

adowling2 avatar Apr 24 '24 01:04 adowling2

@jsiirola @mrmundt Suggestions for type(lower_bounds) in [int, float]?

adowling2 avatar Apr 25 '24 01:04 adowling2

Any reasons for not replacing if type(self.L_initial) != type(None) with if self.L_initial is not None?

adowling2 avatar Apr 25 '24 01:04 adowling2

For checking for numeric types, we generally use

from pyomo.common.numeric_types import native_numeric_types

if type(lower_bound) in native_numeric_types:
   pass
# or
if lower_bound.__class__ in native_numeric_types:
   pass

and yes: if self.L_initial is not None is the recommended idiom.

jsiirola avatar Apr 25 '24 03:04 jsiirola

@adowling2 - Please run black -S -C on your changes to enforce PEP8 standards.

mrmundt avatar Apr 25 '24 15:04 mrmundt

More development plans:

  • [x] Ensure discretize_model = None works on TCLab example (separate repo, really helpful for testing)
  • [x] Use the jac_initial argument. Currently, it is stored in self and not used.
  • [x] Automatically initialize Cholesky factorization
  • [x] Confirm that the "square problem" has zero degrees of freedom. Correct if necessary.
  • [x] Run black

adowling2 avatar Apr 25 '24 23:04 adowling2

@adowling2 - Please run black -S -C on your changes to enforce PEP8 standards.

I got Error: no such option: -C

However, black -S worked fine. I have version 19.10b0 if that matters.

adowling2 avatar Apr 26 '24 01:04 adowling2

Update: I reinstalled black and it works using the command provided by @mrmundt. Now using black, 24.4.2. I'm going to keep the comment above for my future reference.

adowling2 avatar Apr 26 '24 02:04 adowling2

@dlakes94 @slilonfe5 @jialuw96 Check out these enhancements to Pyomo.DoE. We'll want to use this branch (which will hopefully be merged into main soon) when refreshing the Pyomo.DoE examples.

adowling2 avatar Apr 26 '24 02:04 adowling2

Update: I reinstalled black and it works using the command provided by @mrmundt. Now using black, 24.4.2. I'm going to keep the comment above for my future reference.

Future reference - yup, it matters! We use the newest black, unless there are bugs in it (e.g., 24.4.1 had a bug that was problematic).

mrmundt avatar Apr 29 '24 12:04 mrmundt

Anything else needed to get this reviewed and merged?

adowling2 avatar May 06 '24 20:05 adowling2