Skip to content

ParmEst: Support solver object inputs - #4107

Draft
sscini wants to merge 9 commits into
Pyomo:mainfrom
sscini:parmest-solver-object-arg
Draft

sscini wants to merge 9 commits into
Pyomo:mainfrom
sscini:parmest-solver-object-arg

Conversation

@sscini

@sscini sscini commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Fixes # .

Summary/Motivation:

Add ability to support solver objects in ParmEst instead of a solver string for opt SolverFactory.

Changes proposed in this PR:

  • Change ipopt default to ipopt_v2
  • Add support for Ipopt solver objects with old or new interface
  • Translate TerminationConditions with legacywrapper to maintain backwards compatibility

AI-Use Disclosure

  • AI tools were NOT used during the preparation of this PR

or

  • AI tools contributed to the development of this PR

    • AI tools generated documentation (including the PR description/comments, code comments, and/or Sphinx documentation)
    • AI tools generated tests (baselines, examples, and/or code)
    • AI tools generated code (apart from tests)

    Review process (select ONE):

    • Rewritten: All AI-generated content was rewritten by me before being committed.
    • Reviewed/verified: I retained AI-generated content and verified it before committing. Verification included (as applicable):
      • Ran the code and fixed issues
      • Added and ran tests
      • Checked correctness/logic of code and tests
      • Checked for alignment with the contribution guide
      • Considered security implications
    • As-is: AI-generated content was commited directly to the repository

Notes for reviewers (optional):

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.

@sscini

sscini commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@blnicho @adowling2 @slilonfe5 @smondal13
This is as far as I was able to get for tonight on a basic implementation of using solver objects in ParmEst. There are a lot of design decisions that I think need consideration before implementing due to the large amount of changes present if you switch to the new SolverFactory and Results object. I would support switch to ipopt_v2 like in mentioned branch for output index fix for the upcoming release, but believe more time is needed for Solver object support.

The following choices need to be made for a robust implementation:

  1. Should solver objects be provided to the Estimator class, the public functions (theta_est, cov_est, objective_at_theta, etc.), or both?
  2. Should we use the legacy termination conditions and solver status originally for backwards compatibility or switch to the newer interface?
  3. For cov_est reduced hessian method, pynumero has its own ipopt solver, so I believe that would need to be updated as well.
  4. Do we store the full results object from the solver as part of the estimator class?
  5. Which solvers should be supported by default? Any nonlinear solver in pyomo, old interface, or new interface? Is it better to support ipopt specific termination conditions or settings?

Will continue working on this tomorrow, but wanted to share starting progress. Thank you and please let me know if you have any strong opinions on these design choices.

@sscini

sscini commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Thank you @smondal13 for reminding me this is done in DoE for reference.

From previous message:

  1. Following DoE, the solver is set at the Experiment class as a string or object. It can be set at theta_est and cov_est for backwards compatibility, but other functions use from the Estimator.
  2. The opt version (current, also pyo.SolverFactory is used to keep termination conditions an checks consistent. Ipopt new interface can be used through ipopt_v2.
  3. Ipopt v2 is now the default. Pynumero still uses ipopt, but solver options from the solver are sent to pynumero. Ipopt_v2 can be used for finite_difference and k_aug methods.
  4. Not using new interface, so did not store results object
  5. Current nonlinear solvers accessible from legacy SolverFactory are supported.

@adowling2 Please let me know if you disagree with any of these decisions.

Comment thread pyomo/contrib/parmest/parmest.py Resolved
Comment thread pyomo/contrib/parmest/parmest.py Resolved
Comment thread pyomo/contrib/parmest/parmest.py Resolved
Comment thread pyomo/contrib/parmest/parmest.py Resolved
Comment thread pyomo/contrib/parmest/parmest.py Resolved
Comment thread pyomo/contrib/parmest/parmest.py Resolved
Comment thread pyomo/contrib/parmest/parmest.py Resolved
Comment thread pyomo/contrib/parmest/parmest.py Resolved
Comment thread pyomo/contrib/parmest/parmest.py Resolved
@adowling2

Copy link
Copy Markdown
Member

@sscini I agree with these design decisions.

One wringle. For debugging, it could be desirable to set a solver option, such as iter=0, for one of the steps. I am okay if we defer that. But this has come up in the past when I have wanted to debug one of the solvers in Pyomo.DoE or ParmEst.

"""
if isinstance(solver, str):
solver_name = solver
solver = SolverFactory(solver_name)

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.

Do you know the type or error raised when the solver name is unknown? If yes, it’s safer to put this in a try-except block.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

An error is not raised until you try to solve it. It instead creates an UnknownSolver, which is why I check for that after this step.

Comment thread pyomo/contrib/parmest/parmest.py Outdated
e.g., step=0.02 is a 2% perturbation
solver : str
Solver name specified by the user, e.g., 'ipopt'
solver : str or ``solver`` object

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.

Use the appropriate data type for the solver object. str is a data type, solver object is not

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Each solver returns its own object type. I am looking into how to better represent this. This is what is currently in the docstring for DoE.

Comment thread pyomo/contrib/parmest/parmest.py Outdated
e.g., step=0.02 is a 2% perturbation
solver : str
Solver name specified by the user, e.g., 'ipopt'
solver : str or ``solver`` object

@slilonfe5 slilonfe5 Nov 19, 2026 •

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.

Same comment about solver object data type. Also, you gave an explicit example of the solver name, but did not give an explicit example of the solver object

Comment thread pyomo/contrib/parmest/parmest.py Outdated
e.g., step=0.02 is a 2% perturbation
solver : str
Solver name specified by the user, e.g., 'ipopt'
solver : str or ``solver`` object

@slilonfe5 slilonfe5 Nov 19, 2026 •

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.

Same comment about solver object data type. You gave an explicit example of the solver name, but did not give an explicit example of the solver object

Comment thread pyomo/contrib/parmest/parmest.py Outdated
Dictionary containing the estimates of the unknown parameters
solver : str
Solver name specified by the user, e.g., 'ipopt'
solver : str or ``solver`` object

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.

Same comment about solver object data type. You gave an explicit example of the solver name, but did not give an explicit example of the solver object

Comment thread pyomo/contrib/parmest/parmest.py Resolved
Comment thread pyomo/contrib/parmest/parmest.py Outdated
regularization_weight: float, optional
Weighting factor for the regularization term. Used with
``regularization="L2"``. Default is 1.0.
solver: str or ``solver`` object, optional

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.

Same comment about solver object data type. You gave an explicit example of the solver name, but did not give an explicit example of the solver object

Comment thread pyomo/contrib/parmest/parmest.py Outdated
Default is None.
solver : str, optional
Solver to use for optimization. Default is "ef_ipopt".
solver : str or ``solver`` object, optional

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.

Same comment about solver object data type. You gave an explicit example of the solver name, but did not give an explicit example of the solver object

raise RuntimeError("k_aug no longer supported.")
if solver == "ef_ipopt":
sol = SolverFactory('ipopt')
sol = self.solver

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.

self.solver is constructed from whatever argument the user supplies in the Estimator class. The solver from “ef_ipopt” may not be the same as that from self.solver. Unless we want sol to be whatever self.solver is

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I missed this part thanks. In the current implementation (on main) using ef_ipopt just pointed to the default, so I was keeping the same option as the default in case people explicitly put it for backwards compatibility. Will rethink a smarter way to do this. In reality it would get the value from theta_est like with cov_est and _cov_at_theta

Comment thread pyomo/contrib/parmest/parmest.py Outdated
e.g., 'finite_difference'
solver : str
Solver name specified by the user, e.g., 'ipopt'
solver : ``solver`` object

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.

Why only solver object here? Why removing the option to supply a string?

@sscini sscini Nov 20, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

My reasoning was that since it is the private function for cov_est, the input for cov_est will be converted into a solver object with _get_solver() from a string, so it would never reach _cov_at_theta as a string.

Comment thread pyomo/contrib/parmest/parmest.py Outdated
----------
solver: str, optional
Currently only "ef_ipopt" is supported. Default is "ef_ipopt".
solver: str or ``solver`` object, optional

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.

Same comment about solver object data type. You gave an explicit example of the solver name, but did not give an explicit example of the solver object

Comment thread pyomo/contrib/parmest/parmest.py Outdated
Default is 'finite_difference'
solver : str, optional
Solver name, e.g., 'ipopt'. Default is 'ipopt'
solver : str or ``solver`` object, optional

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.

Same comment about solver object data type. You gave an explicit example of the solver name, but did not give an explicit example of the solver object

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.

4 participants