Beispiel #1
0
def get_configuration(key):
    config = ConfigDict()
    config.declare('print_callback_message', 
                   ConfigValue(domain=bool,
                               description='Print a message when callback is called',
                               default=False)).declare_as_argument(f'--{key}.print-callback-message')
    return config
Beispiel #2
0
def get_configuration(config):
    ans = ConfigDict()
    ans.declare('key1', ConfigValue(default=0, domain=int))
    ans.declare('key2', ConfigValue(default=5, domain=str))
    return ans(config)
Beispiel #3
0
def _trf_config():
    """
    Generate the configuration dictionary.
    The user may change the configuration options during the instantiation
    of the trustregion solver:
        >>> optTRF = SolverFactory('trustregion',
        ...                        solver='ipopt',
        ...                        maximum_iterations=50,
        ...                        minimum_radius=1e-5,
        ...                        verbose=True)

    The user may also update the configuration after instantiation:
        >>> optTRF = SolverFactory('trustregion')
        >>> optTRF._CONFIG.trust_radius = 0.5

    The user may also update the configuration as part of the solve call:
        >>> optTRF = SolverFactory('trustregion')
        >>> optTRF.solve(model, decision_variables, trust_radius=0.5)
    Returns
    -------
    CONFIG : ConfigDict
        This holds all configuration options to be passed to the TRF solver.

    """
    CONFIG = ConfigDict('TrustRegion')

    ### Solver options
    CONFIG.declare(
        'solver',
        ConfigValue(default='ipopt',
                    description='Solver to use. Default = ``ipopt``.'))
    CONFIG.declare(
        'keepfiles',
        ConfigValue(default=False,
                    domain=Bool,
                    description="Optional. Whether or not to "
                    "write files of sub-problems for use in debugging. "
                    "Default = False."))
    CONFIG.declare(
        'tee',
        ConfigValue(default=False,
                    domain=Bool,
                    description="Optional. Sets the ``tee`` "
                    "for sub-solver(s) utilized. "
                    "Default = False."))

    ### Trust Region specific options
    CONFIG.declare(
        'verbose',
        ConfigValue(default=False,
                    domain=Bool,
                    description="Optional. When True, print each "
                    "iteration's relevant information to the console "
                    "as well as to the log. "
                    "Default = False."))
    CONFIG.declare(
        'trust_radius',
        ConfigValue(default=1.0,
                    domain=PositiveFloat,
                    description="Initial trust region radius ``delta_0``. "
                    "Default = 1.0."))
    CONFIG.declare(
        'minimum_radius',
        ConfigValue(
            default=1e-6,
            domain=PositiveFloat,
            description="Minimum allowed trust region radius ``delta_min``. "
            "Default = 1e-6."))
    CONFIG.declare(
        'maximum_radius',
        ConfigValue(
            default=CONFIG.trust_radius * 100,
            domain=PositiveFloat,
            description="Maximum allowed trust region radius. If trust region "
            "radius reaches maximum allowed, solver will exit. "
            "Default = 100 * trust_radius."))
    CONFIG.declare(
        'maximum_iterations',
        ConfigValue(default=50,
                    domain=PositiveInt,
                    description="Maximum allowed number of iterations. "
                    "Default = 50."))
    ### Termination options
    CONFIG.declare(
        'feasibility_termination',
        ConfigValue(
            default=1e-5,
            domain=PositiveFloat,
            description=
            "Feasibility measure termination tolerance ``epsilon_theta``. "
            "Default = 1e-5."))
    CONFIG.declare(
        'step_size_termination',
        ConfigValue(
            default=CONFIG.feasibility_termination,
            domain=PositiveFloat,
            description="Step size termination tolerance ``epsilon_s``. "
            "Matches the feasibility termination tolerance by default."))
    ### Switching Condition options
    CONFIG.declare(
        'minimum_feasibility',
        ConfigValue(default=1e-4,
                    domain=PositiveFloat,
                    description="Minimum feasibility measure ``theta_min``. "
                    "Default = 1e-4."))
    CONFIG.declare(
        'switch_condition_kappa_theta',
        ConfigValue(
            default=0.1,
            domain=In(NumericRange(0, 1, 0, (False, False))),
            description="Switching condition parameter ``kappa_theta``. "
            "Contained in open set (0, 1). "
            "Default = 0.1."))
    CONFIG.declare(
        'switch_condition_gamma_s',
        ConfigValue(default=2.0,
                    domain=PositiveFloat,
                    description="Switching condition parameter ``gamma_s``. "
                    "Must satisfy: ``gamma_s > 1/(1+mu)`` where ``mu`` "
                    "is contained in set (0, 1]. "
                    "Default = 2.0."))
    ### Trust region update/ratio test parameters
    CONFIG.declare(
        'radius_update_param_gamma_c',
        ConfigValue(
            default=0.5,
            domain=In(NumericRange(0, 1, 0, (False, False))),
            description="Lower trust region update parameter ``gamma_c``. "
            "Default = 0.5."))
    CONFIG.declare(
        'radius_update_param_gamma_e',
        ConfigValue(
            default=2.5,
            domain=In(NumericRange(1, None, 0)),
            description="Upper trust region update parameter ``gamma_e``. "
            "Default = 2.5."))
    CONFIG.declare(
        'ratio_test_param_eta_1',
        ConfigValue(default=0.05,
                    domain=In(NumericRange(0, 1, 0, (False, False))),
                    description="Lower ratio test parameter ``eta_1``. "
                    "Must satisfy: ``0 < eta_1 <= eta_2 < 1``. "
                    "Default = 0.05."))
    CONFIG.declare(
        'ratio_test_param_eta_2',
        ConfigValue(default=0.2,
                    domain=In(NumericRange(0, 1, 0, (False, False))),
                    description="Lower ratio test parameter ``eta_2``. "
                    "Must satisfy: ``0 < eta_1 <= eta_2 < 1``. "
                    "Default = 0.2."))
    ### Filter
    CONFIG.declare(
        'maximum_feasibility',
        ConfigValue(
            default=50.0,
            domain=PositiveFloat,
            description="Maximum allowable feasibility measure ``theta_max``. "
            "Parameter for use in filter method."
            "Default = 50.0."))
    CONFIG.declare(
        'param_filter_gamma_theta',
        ConfigValue(
            default=0.01,
            domain=In(NumericRange(0, 1, 0, (False, False))),
            description="Fixed filter parameter ``gamma_theta`` within (0, 1). "
            "Default = 0.01"))
    CONFIG.declare(
        'param_filter_gamma_f',
        ConfigValue(
            default=0.01,
            domain=In(NumericRange(0, 1, 0, (False, False))),
            description="Fixed filter parameter ``gamma_f`` within (0, 1). "
            "Default = 0.01"))

    return CONFIG
Beispiel #4
0
def pyros_config():
    CONFIG = ConfigDict('PyROS')

    # ================================================
    # === Options common to all solvers
    # ================================================
    CONFIG.declare(
        'time_limit',
        ConfigValue(
            default=None,
            domain=NonNegativeFloat,
            description="Optional. Default = None. "
            "Total allotted time for the execution of the PyROS solver in seconds "
            "(includes time spent in sub-solvers). 'None' is no time limit."))
    CONFIG.declare(
        'keepfiles',
        ConfigValue(
            default=False,
            domain=bool,
            description=
            "Optional. Default = False. Whether or not to write files of sub-problems for use in debugging. "
            "Must be paired with a writable directory supplied via ``subproblem_file_directory``."
        ))
    CONFIG.declare(
        'tee',
        ConfigValue(
            default=False,
            domain=bool,
            description=
            "Optional. Default = False. Sets the ``tee`` for all sub-solvers utilized."
        ))
    CONFIG.declare(
        'load_solution',
        ConfigValue(
            default=True,
            domain=bool,
            description="Optional. Default = True. "
            "Whether or not to load the final solution of PyROS into the model object."
        ))

    # ================================================
    # === Required User Inputs
    # ================================================
    CONFIG.declare(
        "first_stage_variables",
        ConfigValue(
            default=[],
            domain=InputDataStandardizer(Var, _VarData),
            description=
            "Required. List of ``Var`` objects referenced in ``model`` representing the design variables."
        ))
    CONFIG.declare(
        "second_stage_variables",
        ConfigValue(
            default=[],
            domain=InputDataStandardizer(Var, _VarData),
            description=
            "Required. List of ``Var`` referenced in ``model`` representing the control variables."
        ))
    CONFIG.declare(
        "uncertain_params",
        ConfigValue(
            default=[],
            domain=InputDataStandardizer(Param, _ParamData),
            description=
            "Required. List of ``Param`` referenced in ``model`` representing the uncertain parameters. MUST be ``mutable``. "
            "Assumes entries are provided in consistent order with the entries of 'nominal_uncertain_param_vals' input."
        ))
    CONFIG.declare(
        "uncertainty_set",
        ConfigValue(
            default=None,
            domain=uncertainty_sets,
            description=
            "Required. ``UncertaintySet`` object representing the uncertainty space "
            "that the final solutions will be robust against."))
    CONFIG.declare(
        "local_solver",
        ConfigValue(
            default=None,
            domain=SolverResolvable(),
            description=
            "Required. ``Solver`` object to utilize as the primary local NLP solver."
        ))
    CONFIG.declare(
        "global_solver",
        ConfigValue(
            default=None,
            domain=SolverResolvable(),
            description=
            "Required. ``Solver`` object to utilize as the primary global NLP solver."
        ))
    # ================================================
    # === Optional User Inputs
    # ================================================
    CONFIG.declare(
        "objective_focus",
        ConfigValue(
            default=ObjectiveType.nominal,
            domain=ValidEnum(ObjectiveType),
            description=
            "Optional. Default = ``ObjectiveType.nominal``. Choice of objective function to optimize in the master problems. "
            "Choices are: ``ObjectiveType.worst_case``, ``ObjectiveType.nominal``. See Note for details."
        ))
    CONFIG.declare(
        "nominal_uncertain_param_vals",
        ConfigValue(
            default=[],
            domain=list,
            description=
            "Optional. Default = deterministic model ``Param`` values. List of nominal values for all uncertain parameters. "
            "Assumes entries are provided in consistent order with the entries of ``uncertain_params`` input."
        ))
    CONFIG.declare(
        "decision_rule_order",
        ConfigValue(
            default=0,
            domain=In([0, 1, 2]),
            description=
            "Optional. Default = 0. Order of decision rule functions for handling second-stage variable recourse. "
            "Choices are: '0' for constant recourse (a.k.a. static approximation), '1' for affine recourse "
            "(a.k.a. affine decision rules), '2' for quadratic recourse."))
    CONFIG.declare(
        "solve_master_globally",
        ConfigValue(
            default=False,
            domain=bool,
            description=
            "Optional. Default = False. 'True' for the master problems to be solved with the user-supplied global solver(s); "
            "or 'False' for the master problems to be solved with the user-supplied local solver(s). "
        ))
    CONFIG.declare(
        "max_iter",
        ConfigValue(
            default=-1,
            domain=PositiveIntOrMinusOne,
            description=
            "Optional. Default = -1. Iteration limit for the GRCS algorithm. '-1' is no iteration limit."
        ))
    CONFIG.declare(
        "robust_feasibility_tolerance",
        ConfigValue(
            default=1e-4,
            domain=NonNegativeFloat,
            description=
            "Optional. Default = 1e-4. Relative tolerance for assessing robust feasibility violation during separation phase."
        ))
    CONFIG.declare(
        "separation_priority_order",
        ConfigValue(
            default={},
            domain=dict,
            description=
            "Optional. Default = {}. Dictionary mapping inequality constraint names to positive integer priorities for separation. "
            "Constraints not referenced in the dictionary assume a priority of 0 (lowest priority)."
        ))
    CONFIG.declare(
        "progress_logger",
        ConfigValue(
            default="pyomo.contrib.pyros",
            domain=a_logger,
            description=
            "Optional. Default = \"pyomo.contrib.pyros\". The logger object to use for reporting."
        ))
    CONFIG.declare(
        "backup_local_solvers",
        ConfigValue(
            default=[],
            domain=SolverResolvable(),
            description=
            "Optional. Default = []. List of additional ``Solver`` objects to utilize as backup "
            "whenever primary local NLP solver fails to identify solution to a sub-problem."
        ))
    CONFIG.declare(
        "backup_global_solvers",
        ConfigValue(
            default=[],
            domain=SolverResolvable(),
            description=
            "Optional. Default = []. List of additional ``Solver`` objects to utilize as backup "
            "whenever primary global NLP solver fails to identify solution to a sub-problem."
        ))
    CONFIG.declare(
        "subproblem_file_directory",
        ConfigValue(
            default=None,
            domain=str,
            description=
            "Optional. Path to a directory where subproblem files and "
            "logs will be written in the case that a subproblem fails to solve."
        ))
    # ================================================
    # === Advanced Options
    # ================================================
    CONFIG.declare(
        "bypass_local_separation",
        ConfigValue(
            default=False,
            domain=bool,
            description=
            "This is an advanced option. Default = False. 'True' to only use global solver(s) during separation; "
            "'False' to use local solver(s) at intermediate separations, "
            "using global solver(s) only before termination to certify robust feasibility. "
        ))
    CONFIG.declare(
        "bypass_global_separation",
        ConfigValue(
            default=False,
            domain=bool,
            description=
            "This is an advanced option. Default = False. 'True' to only use local solver(s) during separation; "
            "however, robustness of the final result will not be guaranteed. Use to expedite PyROS run when "
            "global solver(s) cannot (efficiently) solve separation problems.")
    )
    CONFIG.declare(
        "p_robustness",
        ConfigValue(
            default={},
            domain=dict,
            description=
            "This is an advanced option. Default = {}. Whether or not to add p-robustness constraints to the master problems. "
            "If the dictionary is empty (default), then p-robustness constraints are not added. "
            "See Note for how to specify arguments."))

    return CONFIG