Skip to content

Greybox Objectives#3364

Merged
michaelbynum merged 20 commits intoPyomo:mainfrom
michaelbynum:greybox
Mar 12, 2025
Merged

Greybox Objectives#3364
michaelbynum merged 20 commits intoPyomo:mainfrom
michaelbynum:greybox

Conversation

@michaelbynum
Copy link
Copy Markdown
Contributor

Summary/Motivation:

This PR adds support for objectives in PyNumero grey box models.

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
Copy Markdown
Contributor

@Robbybp Robbybp left a comment

Choose a reason for hiding this comment

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

I haven't reviewed changes in _evaluate_hessian_if_necessary_and_cache yet, but this looks fine.

Just curious, what is the motivation for doing this instead of just using outputs and putting them in the objective? Is there some motivating use case where this works better?

@codykarcher
Copy link
Copy Markdown
Contributor

I haven't reviewed changes in _evaluate_hessian_if_necessary_and_cache yet, but this looks fine.

Just curious, what is the motivation for doing this instead of just using outputs and putting them in the objective? Is there some motivating use case where this works better?

This is me. For applications I work with, it's common for people to just come with a black box and say "minimize". Clearly that approach is not ideal, but allowing this capability will enable us to reach out to people who are used to doing optimization that way and help us convert them to the light side of the force...

@Robbybp
Copy link
Copy Markdown
Contributor

Robbybp commented Sep 18, 2024

For applications I work with, it's common for people to just come with a black box and say "minimize"

Okay, so this is basically just for convenience.

Clearly that approach is not ideal

I don't think it's clear at all. I'm usually a fan of eliminating auxiliary variables where possible, so this approach appeals to me. I was just curious if there was an example where it actually mattered for performance or reliability.

Copy link
Copy Markdown
Contributor

@codykarcher codykarcher left a comment

Choose a reason for hiding this comment

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

Looks good, will test functionality over the next few weeks

@codykarcher
Copy link
Copy Markdown
Contributor

codykarcher commented Sep 27, 2024

For applications I work with, it's common for people to just come with a black box and say "minimize"

Okay, so this is basically just for convenience.

Clearly that approach is not ideal

I don't think it's clear at all. I'm usually a fan of eliminating auxiliary variables where possible, so this approach appeals to me. I was just curious if there was an example where it actually mattered for performance or reliability.

It is not ideal in the context of it hides structure I could potentially implement in my optimization problem. IE, what if my black box is hiding a convex optimization problem? But yea, it is a matter of convenience not performance.

@mrmundt
Copy link
Copy Markdown
Contributor

mrmundt commented Oct 8, 2024

@michaelbynum , @Robbybp - We are hoping to cut a patch release on Monday (the 14th). Any chance this is going to make it into that?

@mrmundt
Copy link
Copy Markdown
Contributor

mrmundt commented Nov 26, 2024

@michaelbynum , @Robbybp - Pinging on this PR again! Any update?

@blnicho blnicho requested review from Robbybp and mrmundt February 25, 2025 20:10
Copy link
Copy Markdown
Contributor

@Robbybp Robbybp left a comment

Choose a reason for hiding this comment

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

Some minor comments. Otherwise, this looks good to me.

Comment on lines +326 to +348
# Support for objectives
def has_objective(self):
return False

def evaluate_objective(self) -> float:
"""
Compute the objective from the values set in
input_values
"""
raise NotImplementedError(
'evaluate_objective called but not implemented in the derived class.'
)

def evaluate_grad_objective(self, out=None):
"""
Compute the gradient of the objective from the
values set in input_values
"""
raise NotImplementedError(
'evaluate_grad_objective called but not '
'implemented in the derived class.'
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remind me: Why don't we include default methods for evaluate_hessian* that raise NotImplementedError? Is the presence of such a method used to determine Hessian support at some point?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like it:

self._has_hessian_support = True
. If we want to change that, I can create an issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I prefer try/except NotImplementedError to using hasattr, but I'm not sure it's important enough to change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree. I'll at least create an issue.

Copy link
Copy Markdown
Contributor

@Robbybp Robbybp left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@michaelbynum michaelbynum merged commit 4da59c6 into Pyomo:main Mar 12, 2025
35 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.

6 participants