Pyomo/pyomo

Defer processing ConfigDict's handling of default values until they are needed

emma58 opened this issue · 0 comments

Summary

We lack an elegant way to pass configured solvers as config arguments, as is pointed out in #3220.

Rationale

Many transformations rely on the user being able to pass a configured solver as an argument so that that configuration will persist wherever it is used in the transformation (or meta algorithm). Right now we often do that by passing a solver instance, but this is suboptimal since those solver instances will be created on import. (Alternatively, some parts of code take the solver name as the argument and pass an options dictionary separately, but this is rather clunky and difficult to validate.)

Description

As suggested by @jsiirola, allow this syntax:

CONFIG.declare(
    'solver',
    ConfigValue(
        domain=SolverFactory,
        default='gurobi',
        description="A solver to use to solve the continuous subproblems for "
        "calculating the M values",
    ),
)

and don't process the default value until the first time it is needed.