def __init__(self, *args, **kwargs): name = "ParOpt" category = "Local Optimizer" if _ParOpt is None: raise Error("There was an error importing ParOpt") # Create and fill-in the dictionary of default option values defOpts = {} options = _ParOpt.getOptionsInfo() for option_name in options: # Get the type and default value of the named argument _type = None if options[option_name].option_type == "bool": _type = bool elif options[option_name].option_type == "int": _type = int elif options[option_name].option_type == "float": _type = float else: _type = str default_value = options[option_name].default # Set the entry into the dictionary defOpts[option_name] = [_type, default_value] self.set_options = {} informs = {} Optimizer.__init__(self, name, category, defOpts, informs, *args, **kwargs) # ParOpt requires a dense Jacobian format self.jacType = "dense2d" return
def _setup_driver(self, problem): """ Prepare the driver for execution. This is the final thing to run during setup. Parameters ---------- paropt_problem : <Problem> Pointer """ # TODO: # - logic for different opt algorithms # - treat equality constraints super(ParOptDriver, self)._setup_driver(problem) # Raise error if multiple objectives are provided if len(self._objs) > 1: msg = 'ParOpt currently does not support multiple objectives.' raise RuntimeError(msg.format(self.__class__.__name__)) # Create the ParOptProblem from the OpenMDAO problem self.paropt_problem = ParOptProblem(problem) # Take only the options declared from ParOpt info = ParOpt.getOptionsInfo() paropt_options = {} for key in self.options: if key in info.keys(): paropt_options[key] = self.options[key] self.opt = ParOpt.Optimizer(self.paropt_problem, paropt_options) return
def _declare_options(self): """ Declare options before kwargs are processed in the init method. """ info = ParOpt.getOptionsInfo() for name in info: default = info[name].default descript = info[name].descript values = info[name].values if info[name].option_type == 'bool': self.options.declare(name, default, types=bool, desc=descript) elif info[name].option_type == 'int': self.options.declare(name, default, types=int, lower=values[0], upper=values[1], desc=descript) elif info[name].option_type == 'float': self.options.declare(name, default, types=float, lower=values[0], upper=values[1], desc=descript) elif info[name].option_type == 'str': if default is None: self.options.declare(name, default, types=str, allow_none=True, desc=descript) else: self.options.declare(name, default, types=str, desc=descript) elif info[name].option_type == 'enum': self.options.declare(name, default, values=values, desc=descript) return
def __init__(self, raiseError=True, options={}): name = "ParOpt" category = "Local Optimizer" if _ParOpt is None: if raiseError: raise Error("There was an error importing ParOpt") # Create and fill-in the dictionary of default option values self.defOpts = {} paropt_default_options = _ParOpt.getOptionsInfo() # Manually override the options with missing default values paropt_default_options["ip_checkpoint_file"].default = "default.out" paropt_default_options["problem_name"].default = "problem" for option_name in paropt_default_options: # Get the type and default value of the named argument _type = None if paropt_default_options[option_name].option_type == "bool": _type = bool elif paropt_default_options[option_name].option_type == "int": _type = int elif paropt_default_options[option_name].option_type == "float": _type = float else: _type = str default_value = paropt_default_options[option_name].default # Set the entry into the dictionary self.defOpts[option_name] = [_type, default_value] self.set_options = {} self.informs = {} super().__init__(name, category, defaultOptions=self.defOpts, informs=self.informs, options=options) # ParOpt requires a dense Jacobian format self.jacType = "dense2d" return