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

With no initial value for uncertain parameter, PyROS complains "ValueError: User must designate at least one uncertain parameter." #2437

Closed
makansij opened this issue Jun 20, 2022 · 1 comment · Fixed by #3126

Comments

@makansij
Copy link

Summary

With no initial value for uncertain parameter, PyROS complains ValueError: User must designate at least one uncertain parameter.

We should improve this error message to be more informative. Consider the example below where I have one uncertain parameter. To reproduce, consider two runs of the code below. First, run with the line below "# First try running with this line. Then comment out that line and run with the line below. One triggers the ValueError, the other does not.

Steps to reproduce the issue

# === Required import ===
import pyomo.kernel as pmo
import numpy as np
import pyomo.environ as pyo
import pyomo.contrib.pyros as pyros

pyros_solver = pyo.SolverFactory("pyros")
m = pyo.ConcreteModel()
m.L = pyo.Var(within=pyo.Reals, bounds=(0,10), initialize=0.5)

# First try running with this line
m.x1 = pyo.Param(within=pyo.Reals, mutable=True)
# Then, comment out the above line, and uncomment the following line:
# m.x1 = pyo.Param(within=pyo.Reals, initialize=0.5, mutable=True)

fn_1 = m.x1**2 + m.L
fn_2 = m.x1**2 + m.L - m.x1
m.obj = pyo.Objective(expr = fn_1, sense=pyo.minimize)
m.c1 = pyo.Constraint(expr = 0 <= fn_2)
uncertain_parameters = [m.x1] # We can pass IndexedParams this way to PyROS, or as an expanded list per index
relative_deviation = 0.9
nominal_values = {0:1} 
bounds = [(nominal_values[i] - relative_deviation*nominal_values[i],
              nominal_values[i] + relative_deviation*nominal_values[i])
              for i in range(len(uncertain_parameters))]

box_uncertainty_set = pyros.BoxSet(bounds=bounds)

solvername = 'baron'
solverpath_exe = '<path to baron>'
baron_solver = pyo.SolverFactory(solvername, executable=solverpath_exe)
local_solver = baron_solver
global_solver = baron_solver

first_stage_variables =[m.L]
second_stage_variables = []

results_1 = pyros_solver.solve(model = m,
                                 first_stage_variables = first_stage_variables,
                                 second_stage_variables = second_stage_variables,
                                 uncertain_params = uncertain_parameters,
                                 uncertainty_set = box_uncertainty_set,
                                 local_solver = local_solver,
                                 global_solver= global_solver,
                                 tee=True,
                                 options = {
                                    "objective_focus": pyros.ObjectiveType.worst_case,
                                    "solve_master_globally": True,
                                    "load_solution":False
                                  })

Error Message

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-afa9aa54a15b> in <module>
     76                                     "objective_focus": pyros.ObjectiveType.worst_case,
     77                                     "solve_master_globally": True,
---> 78                                     "load_solution":False
     79                                   })
     80 

/usr/local/lib/python3.7/site-packages/pyomo/contrib/pyros/pyros.py in solve(self, model, first_stage_variables, second_stage_variables, uncertain_params, uncertainty_set, local_solver, global_solver, **kwds)
    327         model = model
    328         # === Validate kwarg inputs
--> 329         validate_kwarg_inputs(model, config)
    330 
    331         # === Validate ability of grcs RO solver to handle this model

/usr/local/lib/python3.7/site-packages/pyomo/contrib/pyros/util.py in validate_kwarg_inputs(model, config)
    440     pdb.set_trace()
    441     # === Uncertain params provided check
--> 442     if len(config.uncertain_params) == 0:
    443         raise ValueError("User must designate at least one uncertain parameter.")
    444 

ValueError: User must designate at least one uncertain parameter.
@shermanjasonaf
Copy link
Contributor

Understood. I'll update pyros.util.validate_kwarg_inputs to make this error message more informative.

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

Successfully merging a pull request may close this issue.

3 participants