pyomo icon indicating copy to clipboard operation
pyomo copied to clipboard

Add meaningful exception when variables are not found in parmest

Open dallan-keylogic opened this issue 4 years ago • 2 comments

Summary

Presently, when theta_names are provided to parmest.Estimator incorrectly, the exception provided is cryptic and unhelpful. An error is logged that the variables were not able to be found, but it's not clear to the user that it is the reason for the exception. Explicitly raising an exception would be more helpful.

Rationale

Yesterday, I attempted to use parmest for the first time. However, I wrote theta_names = ["m.params.PR_kappa['H2','H2O']", "m.params.PR_kappa['H2O','H2']"] instead of ["params.PR_kappa['H2','H2O']", "params.PR_kappa['H2O','H2']"]. The traceback I got was not helpful for debugging:

  File "[Redacted]\IDAES\IDAES-doug\H2_H2O_VLE_validation.py", line 62, in <module>
    obj_value, parameters = pest.theta_est()

  File "[Redacted]\miniconda3\envs\idaes-fresh\lib\site-packages\pyomo\contrib\parmest\parmest.py", line 674, in theta_est
    return self._Q_opt(solver=solver, return_values=return_values,

  File "[Redacted]\miniconda3\envs\idaes-fresh\lib\site-packages\pyomo\contrib\parmest\parmest.py", line 426, in _Q_opt
    ef = local_ef.create_EF(scen_names,

  File "[Redacted]\miniconda3\envs\idaes-fresh\lib\site-packages\pyomo\contrib\parmest\create_ef.py", line 88, in create_EF
    scen_dict = {

  File "[Redacted]\miniconda3\envs\idaes-fresh\lib\site-packages\pyomo\contrib\parmest\create_ef.py", line 89, in <dictcomp>
    name: scenario_creator(name, **scenario_creator_kwargs)

  File "[Redacted]\miniconda3\envs\idaes-fresh\lib\site-packages\pyomo\contrib\parmest\parmest.py", line 163, in _experiment_instance_creation_callback
    instance._mpisppy_node_list = [scenario_tree.ScenarioNode(

  File "[Redacted]\miniconda3\envs\idaes-fresh\lib\site-packages\pyomo\contrib\parmest\scenario_tree.py", line 86, in __init__
    self.nonant_vardata_list = build_vardatalist(self,

  File "[Redacted]\miniconda3\envs\idaes-fresh\lib\site-packages\pyomo\contrib\parmest\scenario_tree.py", line 39, in build_vardatalist
    if v.is_indexed():

AttributeError: 'NoneType' object has no attribute 'is_indexed'

Above all of that, I saw the logged error:

Message: 'theta_name[%s] (%s) was not found on the model' Arguments: ((1, "m.params.PR_kappa['H2O','H2']"),)

but after quickly validating that such a variable was, in fact, created on my model I started looking for other causes. It wasn't obvious to me that such an error message might not get generated during normal operation of parmest as a result of whatever necessitated specifying a variable name instead of the actual variable object.

Description

If such an error is going to prevent further execution of the code and no rescue is possible, it should raise an exception instead of just being a logged error.

dallan-keylogic avatar Oct 19 '21 14:10 dallan-keylogic

@djlaky Is this something we have take care of with the parmest redesign? Do we have a more sensible error message now? Do you think we can close this issue?

adowling2 avatar Apr 30 '25 01:04 adowling2

@djlaky Is this something we have take care of with the parmest redesign? Do we have a more sensible error message now? Do you think we can close this issue?

This probably should be tested in Pyomo.DoE and ParmEst. I am unsure if I have tested any examples with multi-indexing (however I believe Shammah has). The mentioned issue should no longer be relevant.

djlaky avatar May 28 '25 18:05 djlaky