Skip to content

Use Hessian approximation in CyIpopt when grey-box without Hessian is present#3892

Open
Robbybp wants to merge 10 commits intoPyomo:mainfrom
Robbybp:cyipopt-hessian
Open

Use Hessian approximation in CyIpopt when grey-box without Hessian is present#3892
Robbybp wants to merge 10 commits intoPyomo:mainfrom
Robbybp:cyipopt-hessian

Conversation

@Robbybp
Copy link
Copy Markdown
Contributor

@Robbybp Robbybp commented Mar 26, 2026

Fixes #3891

Changes proposed in this PR:

  • Set (potentially override) hessian_approximation=limited-memory in CyIpopt solver when the model contains a grey-box that doesn't support Hessians
  • Log a warning if this happens and the user had set hessian_approximation=exact
  • Add a has_hessian_support method to PyomoNLPWithGreyBoxBlocks (previously only existed on _ExternalGreyBoxAsNLP, although the former has a private _has_hessian_support attribute)

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.

@Robbybp Robbybp changed the title Cyipopt hessian Use Hessian approximation in CyIpopt when grey-box without Hessian is present Mar 26, 2026
@michaelbynum michaelbynum self-requested a review March 26, 2026 12:34
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.93%. Comparing base (6baac63) to head (5ac3a48).
⚠️ Report is 54 commits behind head on main.

Files with missing lines Patch % Lines
...trib/pynumero/algorithms/solvers/cyipopt_solver.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3892      +/-   ##
==========================================
- Coverage   89.93%   89.93%   -0.01%     
==========================================
  Files         902      902              
  Lines      106393   106399       +6     
==========================================
+ Hits        95683    95685       +2     
- Misses      10710    10714       +4     
Flag Coverage Δ
builders 29.21% <50.00%> (+0.01%) ⬆️
default 86.23% <83.33%> (?)
expensive 35.65% <50.00%> (?)
linux 87.38% <83.33%> (-2.04%) ⬇️
linux_other 87.38% <83.33%> (-0.01%) ⬇️
oldsolvers 28.12% <16.66%> (+0.01%) ⬆️
osx 82.73% <33.33%> (+0.01%) ⬆️
win 85.80% <83.33%> (-0.01%) ⬇️
win_other 85.80% <83.33%> (-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.

Copy link
Copy Markdown
Member

@jsiirola jsiirola 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.

One design question, though: should we promote has_hessian_support up to PyomoNLP? (Maybe this should be added to a future "Let's revisit the design of Pynumero and ExternalGreyBox"?)

# Note that `config` is a copy of the instance-level self.config so
# we don't have to reset the option after the solve.
if config.options.get("hessian_approximation", None) == "exact":
logger.warning(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a test exercising / verifying this warning?

@Robbybp
Copy link
Copy Markdown
Contributor Author

Robbybp commented Apr 8, 2026

should we promote has_hessian_support up to PyomoNLP?

For now, no. PyomoNLP always has Hessian support. However, if we eventually merge grey box support into PyomoNLP (to eliminate the need for PyomoNLPWithGreyBoxBlocks), then we will need to do this.

@jsiirola
Copy link
Copy Markdown
Member

jsiirola commented Apr 9, 2026

should we promote has_hessian_support up to PyomoNLP?

For now, no. PyomoNLP always has Hessian support. However, if we eventually merge grey box support into PyomoNLP (to eliminate the need for PyomoNLPWithGreyBoxBlocks), then we will need to do this.

I was mostly thinking about an implementation like

def has_hessian_support(self):
    return True

and including it so that we had a "standard" interface API.

@Robbybp
Copy link
Copy Markdown
Contributor Author

Robbybp commented Apr 9, 2026

I see. I still would rather not add this before we need it.

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.

[CyIpopt] Automatically use Hessian approximation when grey-box exact Hessian isn't available

4 participants