Accessing solver status and termination conditions

Pyomo has been designed to provide high level scripting capabilities for users to quickly and easily write meta-algorithms using off the shelf solvers. Users writing these scripts often need to make decisions based on the status or the termination condition obtained from a solver. To this aim, Pyomo provides a standardized set of objects that can be used to query solver information regardless of the solver being used. The following code snippet provides a typical scenario where SolverStatus and TerminationCondition objects can be useful. 


from pyomo.opt import SolverStatus, TerminationCondition

…

results = opt.solve(instance) # Solving a model instance  
instance.load(results) # Loading solution into results object

if (results.solver.status == SolverStatus.ok) and (results.solver.termination_condition == TerminationCondition.optimal):
    # Do something when the solution in optimal and feasible
elif (results.solver.termination_condition == TerminationCondition.infeasible):
    # Do something when model in infeasible
else:
    # Something else is wrong
    print “Solver Status: ”,  result.solver.status


The following table provides a complete list of all available solver statuses and termination conditions.

Solver Statuses
ok Normal termination
warning Termination with unusual condition
error Terminated internally with error
aborted Terminated due to external conditions (e.g. interrupts)
unknown Unknown (an uninitialized value)
Termination Conditions
maxTimeLimit Exceeded maximum time limit allowed
maxIterations Exceeded maximum number of iterations allowed
minFunctionValue Found solution smaller than specified function value
minStepLength Step length is smaller than specified limit
globallyOptimal Found a globally optimal solution
locallyOptimal Found a locally optimal solution
optimal Found an optimal solution
maxEvaluations Exceeded maximum number of problem evaluations (e.g., branch and bound nodes)
other Other, uncategorized normal termination
unbounded Demonstrated that problem is unbounded
infeasible Demonstrated that problem is infeasible
invalidProblem The problem setup or characteristics are not valid for the solver
solverFailure Solver failed to terminate correctly
internalSolverError Internal solver error
error Other error
userInterrupt Interrupt signal generated by user
resourceInterrupt Interrupt signal in resources used by the solver
licensingProblem Problem accessing solver license