Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add meaningful exception when variables are not found in parmest #2156

Open
dallan-keylogic opened this issue Oct 19, 2021 · 0 comments
Open

Comments

@dallan-keylogic
Copy link

dallan-keylogic commented Oct 19, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant