Exemple #1
0
def use_idaes_solver_configuration_defaults(b=True):
    """
    This function enables (or disables if given False as the argument) solvers
    getting default settings from the IDAES configuration.  When enabled this
    allows global configuration of solvers.

    Args:
        b: True to use default solver configurations from the IDAES configuration
           False to use standard Pyomo solver factories. Default is True.

    Returns:
        None
    """
    idaes.cfg.use_idaes_solver_config = b
    if b:  # This will let you explicitly state you don't want any part of this
        # so if you only do "use_idaes_solver_configuration_defaults(False)" up-
        # front you are saying I know this stuff exists and I must insist you
        # don't use it, of course you can still implicitly not use it.  You can
        # also turn it off and on, if that makes sense for you, but once you turn
        # it on, you've still registerd the wrapper classes, and if you turn
        # it off they just pass-through.
        for c in list(SolverFactory):
            if isinstance(SolverFactory.get_class(c), SolverWrapper):
                continue
            SolverWrapper(c)
        if 'default' not in SolverFactory:
            SolverWrapper('default')
Exemple #2
0
 def __init__(self, name, register=True):
     self.name = name
     if name == 'default':
         self.solver = None
         doc = "IDAES Configured Default Solver"
     else:
         self.solver = SolverFactory.get_class(name)
         doc = SolverFactory.doc(name)
     if register:
         SolverFactory.unregister(name)
         # Re-register the solver (register is a decorator)
         SolverFactory.register(name, doc)(self)
Exemple #3
0
 def __call__(self, *args, **kwargs):
     if self.name == "default":
         name = idaes.cfg.default_solver
         solver = SolverFactory.get_class(name)
     else:
         name = self.name
         solver = self.solver
     if name in idaes.cfg and (self._use_idaes_config or name == "default"):
         for k, v in idaes.cfg[name].items():
             if k not in kwargs:
                 kwargs[k] = v
             elif k == "options":
                 # options is in ConfigBlock and in kwargs, treat "options"
                 # special so individual options can have defaults not just
                 # the whole options block
                 for opk, opv in v.items():
                     if opk not in kwargs["options"]:
                         kwargs["options"][opk] = opv
     return solver(*args, **kwargs)