pyomo
pyomo copied to clipboard
Unknown attribute `time' when using APPSI IPOPT
Summary
When solving using IPOPT, it solves successfully, but when loading the results, it checks for timing data in pyros_algorithm_methods.py, and then doesn't find them so it barfs. We should handle this more gracefully.
Steps to reproduce the issue
Run the code below:
# === 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)
n=3
m.add_component('x1', pyo.Param(range(n), initialize=x_0_init, mutable=True))
def expression_1(m, i):
return 0 <= m.x1[i]
fn_1 = m.x1[0]**2 + m.L
fn_2 = m.x1[0]**2 + m.L - m.x1[1]
m.obj = pyo.Objective(expr = fn_1, sense = pyo.minimize)
m.c1 = pyo.Constraint(expr = 0 <= fn_2)
m.c_rule = pyo.Constraint(range(n), rule = expression_1)
new = m.clone()
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, 1:1, 2:0.5}
bounds = [(nominal_values[i] - relative_deviation*nominal_values[i],
nominal_values[i] + relative_deviation*nominal_values[i])
for i in range(len(nominal_values))]
box_uncertainty_set = pyros.BoxSet(bounds=bounds)
solvername = 'appsi_ipopt'
ipopt_solver = pyo.SolverFactory(solvername)
local_solver = ipopt_solver
global_solver = ipopt_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
Here's the stack trace:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-c7c5873063e3> in <module>
58 "objective_focus": pyros.ObjectiveType.worst_case,
59 "solve_master_globally": True,
---> 60 "load_solution":False
61 })
62 else:
/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)
431
432 # === Solve and load solution into model
--> 433 pyros_soln, final_iter_separation_solns = ROSolver_iterative_solve(model_data, config)
434
435
/usr/local/lib/python3.7/site-packages/pyomo/contrib/pyros/pyros_algorithm_methods.py in ROSolver_iterative_solve(model_data, config)
170 #timing_data.total_master_solve_time += get_time_from_solver(master_soln.results)
171
--> 172 if k > 0: # master feas problem not solved for iteration 0
173 #timing_data.total_master_solve_time += get_time_from_solver(master_soln.feasibility_problem_results)
174 pass
/usr/local/lib/python3.7/site-packages/pyomo/contrib/pyros/separation_problem_methods.py in solve_separation_problem(model_data, config)
325 local_solve_time += get_time_from_solver(s.results)
326 else:
--> 327 local_solve_time += get_time_from_solver(solve_data.results)
328
329 # === Terminate for timing
/usr/local/lib/python3.7/site-packages/pyomo/contrib/pyros/util.py in get_time_from_solver(results)
181 raise ValueError("Accessing the time for this type of solver is not supported by get_time_from_solver.")
182 else:
--> 183 return results.solver.time
184 else:
185 return results.solver.time
/usr/local/lib/python3.7/site-packages/pyomo/opt/results/container.py in __getattr__(self, name)
173 if len(self) == 0:
174 self.add()
--> 175 return getattr(self._list[0], name)
176
177 def __setattr__(self,name,val):
/usr/local/lib/python3.7/site-packages/pyomo/opt/results/container.py in __getattr__(self, name)
282 except Exception:
283 pass
--> 284 raise AttributeError("Unknown attribute `"+str(name)+"' for object with type "+str(type(self)))
285
286 def __setattr__(self,name,val):
AttributeError: Unknown attribute `time' for object with type <class 'pyomo.opt.results.solver.SolverInformation'>