**optimize** =========================== .. py:module:: optimeed.optimize Subpackages ----------- .. toctree:: :titlesonly: :maxdepth: 8 characterization/index.rst mathsToPhysics/index.rst objAndCons/index.rst optiAlgorithms/index.rst .. toctree:: :titlesonly: :maxdepth: 1 optiHistoric/index.rst optiVariable/index.rst optimizer/index.rst Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: optimeed.optimize.InterfaceCharacterization optimeed.optimize.Characterization optimeed.optimize.InterfaceMathsToPhysics optimeed.optimize.MathsToPhysics optimeed.optimize.ArrayMathsToPhysics optimeed.optimize.FastObjCons optimeed.optimize.InterfaceObjCons optimeed.optimize.MultiObjective_GA optimeed.optimize.Monobjective_PSO optimeed.optimize.Real_OptimizationVariable optimeed.optimize.Binary_OptimizationVariable optimeed.optimize.Integer_OptimizationVariable optimeed.optimize.OptimizerSettings optimeed.optimize.OptiHistoric optimeed.optimize.OptiHistoric_Fast optimeed.optimize.OptiHistoric_Empty Functions ~~~~~~~~~ .. autoapisummary:: optimeed.optimize.run_optimization .. py:class:: InterfaceCharacterization Interface for the evaluation of a device .. py:method:: compute(theDevice) :abstractmethod: Action to perform to characterize (= compute the objective function) of the device. :param theDevice: the device to characterize .. py:method:: __str__() Return str(self). .. py:class:: Characterization Bases: :py:obj:`optimeed.optimize.characterization.interfaceCharacterization.InterfaceCharacterization` Interface for the evaluation of a device .. py:method:: compute(theDevice) Action to perform to characterize (= compute the objective function) of the device. :param theDevice: the device to characterize .. py:class:: InterfaceMathsToPhysics Interface to transform output from the optimizer to meaningful variables of the device .. py:method:: fromMathsToPhys(xVector, theDevice, opti_variables) :abstractmethod: Transforms an input vector coming from the optimization (e.g. [0.23, 4, False]) to "meaningful" variable (ex: length, number of poles, flag). :param xVector: List of optimization variables from the optimizer :param theDevice: :class:`~optimeed.InterfaceDevice.InterfaceDevice` :param opti_variables: list of :class:`~optimeed.optimize.OptimizationVariable.OptimizationVariable` .. py:method:: fromPhysToMaths(theDevice, opti_variables) :abstractmethod: Extracts a mathematical vector from meaningful variable of the Device :param theDevice: :class:`~optimeed.InterfaceDevice.InterfaceDevice` :param opti_variables: list of :class:`~optimeed.optimize.OptimizationVariable.OptimizationVariable` :return: List of optimization variables .. py:class:: MathsToPhysics Bases: :py:obj:`optimeed.optimize.mathsToPhysics.interfaceMathsToPhysics.InterfaceMathsToPhysics` Dummy yet powerful example of maths to physics. The optimization variables are directly injected to the device .. py:method:: fromMathsToPhys(xVector, theDevice, theOptimizationVariables) Transforms an input vector coming from the optimization (e.g. [0.23, 4, False]) to "meaningful" variable (ex: length, number of poles, flag). :param xVector: List of optimization variables from the optimizer :param theDevice: :class:`~optimeed.InterfaceDevice.InterfaceDevice` :param opti_variables: list of :class:`~optimeed.optimize.OptimizationVariable.OptimizationVariable` .. py:method:: fromPhysToMaths(theDevice, theOptimizationVariables) Extracts a mathematical vector from meaningful variable of the Device :param theDevice: :class:`~optimeed.InterfaceDevice.InterfaceDevice` :param opti_variables: list of :class:`~optimeed.optimize.OptimizationVariable.OptimizationVariable` :return: List of optimization variables .. py:method:: __str__() Return str(self). .. py:class:: ArrayMathsToPhysics Bases: :py:obj:`optimeed.optimize.mathsToPhysics.interfaceMathsToPhysics.InterfaceMathsToPhysics` Evaluate array M2P. Only use it if specifically needed .. py:method:: fromMathsToPhys(list_of_xvector, theDevice, theOptimizationVariables) Transforms an input vector coming from the optimization (e.g. [0.23, 4, False]) to "meaningful" variable (ex: length, number of poles, flag). :param xVector: List of optimization variables from the optimizer :param theDevice: :class:`~optimeed.InterfaceDevice.InterfaceDevice` :param opti_variables: list of :class:`~optimeed.optimize.OptimizationVariable.OptimizationVariable` .. py:method:: fromPhysToMaths(theDevice, theOptimizationVariables) Extracts a mathematical vector from meaningful variable of the Device :param theDevice: :class:`~optimeed.InterfaceDevice.InterfaceDevice` :param opti_variables: list of :class:`~optimeed.optimize.OptimizationVariable.OptimizationVariable` :return: List of optimization variables .. py:method:: __str__() Return str(self). .. py:class:: FastObjCons(constraintEquation, name=None) Bases: :py:obj:`optimeed.optimize.objAndCons.interfaceObjCons.InterfaceObjCons` Convenience class to create an objective or a constraint very fast. .. py:method:: compute(theDevice) Get the value of the objective or the constraint. The objective is to MINIMIZE and the constraint has to respect VALUE <= 0 :param theDevice: Input device that has already been evaluated :return: float. .. py:method:: get_name() .. py:class:: InterfaceObjCons Interface class for objectives and constraints. The objective is to MINIMIZE and the constraint has to respect VALUE <= 0 .. py:method:: compute(theDevice) :abstractmethod: Get the value of the objective or the constraint. The objective is to MINIMIZE and the constraint has to respect VALUE <= 0 :param theDevice: Input device that has already been evaluated :return: float. .. py:method:: get_name() .. py:method:: __str__() Return str(self). .. py:class:: MultiObjective_GA(theGenerator=MyGenerator) Bases: :py:obj:`optimeed.optimize.optiAlgorithms.algorithmInterface.AlgorithmInterface`, :py:obj:`optimeed.core.Option_class` Based on `Platypus Library `_. Workflow: Define what to optimize and which function to call with a :class:`Problem` Define the initial population with a :class:`Generator` Define the algorithm. As options, define how to evaluate the elements with a :class:`Evaluator`, i.e., for multiprocessing. Define what is the termination condition of the algorithm with :class:`TerminationCondition`. Here, termination condition is a maximum time. .. py:attribute:: DIVISION_OUTER :value: 0 .. py:attribute:: OPTI_ALGORITHM :value: 1 .. py:attribute:: NUMBER_OF_CORES :value: 2 .. py:attribute:: KWARGS_ALGO :value: 3 .. py:method:: initialize(initialVectorGuess, listOfOptimizationVariables) This function is called just before running optimization algorithm. .. py:method:: compute() Launch the optimization :return: vector of optimal variables .. py:method:: set_evaluationFunction(evaluationFunction, callback_on_evaluation, numberOfObjectives, numberOfConstraints, array_evaluator) Set the evaluation function and all the necessary callbacks :param evaluationFunction: check :meth:`~optimeed.optimize.optimizer.evaluateObjectiveAndConstraints` :param callback_on_evaluation: check :meth:`~optimeed.optimize.optimizer.callback_on_evaluation`. Call this function after performing the evaluation of the individuals :param numberOfObjectives: int, number of objectives :param numberOfConstraints: int, number of constraints :param array_evaluator: If True, evaluate each generation at once using numpy array. Use it only with care, as it dismisses some features (expert mode) .. py:method:: set_maxtime(maxTime) Set maximum optimization time (in seconds) .. py:method:: __str__() Return str(self). .. py:method:: get_convergence() This function is called just before compute. Because the convergence is contained in opti algorithm, it must be created now. .. py:method:: add_terminationCondition(theTerminationCondition) .. py:method:: reset() .. py:class:: Monobjective_PSO Bases: :py:obj:`optimeed.optimize.optiAlgorithms.algorithmInterface.AlgorithmInterface`, :py:obj:`optimeed.core.Option_class` Interface for the optimization algorithm .. py:attribute:: NUMBER_OF_CORES :value: 1 .. py:attribute:: KWARGS_ALGO :value: 2 .. py:method:: initialize(initialVectorGuess, listOfOptimizationVariables) This function is called once parameters can't be changed anymore, before "get_convergence". :param initialVectorGuess: list of variables that describe the initial individual :param listOfOptimizationVariables: list of :class:`optimeed.optimize.optiVariable.OptimizationVariable` :return: .. py:method:: compute() Launch the optimization :return: vector of optimal variables .. py:method:: set_evaluationFunction(evaluationFunction, callback_on_evaluate, numberOfObjectives, _numberOfConstraints, array_evaluator) Set the evaluation function and all the necessary callbacks :param evaluationFunction: check :meth:`~optimeed.optimize.optimizer.evaluateObjectiveAndConstraints` :param callback_on_evaluation: check :meth:`~optimeed.optimize.optimizer.callback_on_evaluation`. Call this function after performing the evaluation of the individuals :param numberOfObjectives: int, number of objectives :param numberOfConstraints: int, number of constraints :param array_evaluator: If True, evaluate each generation at once using numpy array. Use it only with care, as it dismisses some features (expert mode) .. py:method:: set_terminationCondition(theTerminationCondition) .. py:method:: set_maxtime(maxTime) Set maximum optimization time (in seconds) .. py:method:: __str__() Return str(self). .. py:method:: get_convergence() Get the convergence of the optimization :return: :class:`~optimeed.optimize.optiAlgorithms.convergence.interfaceConvergence.InterfaceConvergence` .. py:class:: Real_OptimizationVariable(attributeName, val_min, val_max) Bases: :py:obj:`OptimizationVariable` Real (continuous) optimization variable. Most used type .. py:attribute:: val_min :type: float .. py:attribute:: val_max :type: float .. py:method:: get_min_value() .. py:method:: get_max_value() .. py:method:: get_PhysToMaths(deviceIn) Convert the initial value of the variable contained in the device to optimization variable value :param deviceIn: :class:`~optimeed.InterfaceDevice.InterfaceDevice` :return: value of the corresponding optimization variable .. py:method:: do_MathsToPhys(value, deviceIn) Apply the value to the device .. py:method:: __str__() Return str(self). .. py:class:: Binary_OptimizationVariable(attributeName) Bases: :py:obj:`OptimizationVariable` Boolean (True/False) optimization variable. .. py:method:: get_PhysToMaths(deviceIn) Convert the initial value of the variable contained in the device to optimization variable value :param deviceIn: :class:`~optimeed.InterfaceDevice.InterfaceDevice` :return: value of the corresponding optimization variable .. py:method:: do_MathsToPhys(value, deviceIn) Apply the value to the device .. py:method:: __str__() Return str(self). .. py:class:: Integer_OptimizationVariable(attributeName, val_min, val_max) Bases: :py:obj:`OptimizationVariable` Integer variable, in [min_value, max_value] .. py:attribute:: val_min :type: int .. py:attribute:: val_max :type: int .. py:method:: get_min_value() .. py:method:: get_max_value() .. py:method:: get_PhysToMaths(deviceIn) Convert the initial value of the variable contained in the device to optimization variable value :param deviceIn: :class:`~optimeed.InterfaceDevice.InterfaceDevice` :return: value of the corresponding optimization variable .. py:method:: do_MathsToPhys(value, deviceIn) Apply the value to the device .. py:method:: __str__() Return str(self). .. py:function:: run_optimization(optimizer_settings: OptimizerSettings, opti_historic, max_opti_time_sec=10, return_x_solutions=False, array_evaluator=False, initialVectorGuess=None) Perform the optimization. :param optimizer_settings: :class:`OptimizerSettings` containing all information in models, objectives and optimization variable :param opti_historic: OptiHistoric to log evaluations and results :param max_opti_time_sec: Maximum optimization time (default stopping criterion, unless modified in algorithm) :param return_x_solutions: If True, returns raw parameters in reults :param array_evaluator: If True, evaluate each generation at once using numpy array. Use it only with care, as it dismisses some features (expert mode) :return: list of the best optimized devices, convergence information and [if return_x_solutions=True] best solutions .. py:class:: OptimizerSettings(theDevice, theObjectives, theConstraints, theOptimizationVariables, theOptimizationAlgorithm=None, theMathsToPhysics=None, theCharacterization=None) Bases: :py:obj:`optimeed.core.SaveableObject` Abstract class for dynamically type-hinted objects. This class is to solve the special case where the exact type of an attribute is not known before runtime, yet has to be saved. .. py:method:: get_additional_attributes_to_save() Return list of attributes corresponding to object, whose type cannot be determined statically (e.g. topology change) .. py:method:: get_additional_attributes_to_save_list() Same behavior as get_additional_attributes_to_save, but where the attributes contains list of unknown items .. py:method:: get_device() .. py:method:: get_M2P() .. py:method:: get_charac() .. py:method:: get_optivariables() .. py:method:: get_objectives() .. py:method:: get_constraints() .. py:method:: get_optialgorithm() .. py:class:: OptiHistoric(optiname='opti', autosave_timer=60 * 5, autosave=True, create_new_directory=True, performance_datastruct=True, folder=getPath_workspace()) Contains all the points that have been evaluated .. py:class:: _pointData(currTime, objectives, constraints) .. py:attribute:: time :type: float .. py:attribute:: objectives :type: List[float] .. py:attribute:: constraints :type: List[float] .. py:class:: _LogParams .. py:method:: add_parameters(params) .. py:method:: get_rows_indices(list_of_params) .. py:method:: log_after_evaluation(returned_values: dict) Save the output of evaluate to optiHistoric. This function should be called by the optimizer IN a process safe context. .. py:method:: set_results(devicesList) .. py:method:: get_best_devices_without_reevaluating(list_of_best_params) .. py:method:: set_convergence(theConvergence) .. py:method:: save() .. py:method:: get_convergence() :return: convergence :class:`~optimeed.optimize.optiAlgorithms.convergence.interfaceConvergence.InterfaceConvergence` .. py:method:: get_devices() :return: List of devices (ordered by evaluation number) .. py:method:: get_logopti() :return: Log optimization (to check the convergence) .. py:method:: start(optimization_parameters) Function called upon starting the optimization. Create folders. .. py:class:: OptiHistoric_Fast(optiname='opti') Almost empty struct, just enough to display the graphs. Used to speed up optimization .. py:method:: log_after_evaluation(returned_values: dict) .. py:method:: set_results(theResults) .. py:method:: get_best_devices_without_reevaluating(_) .. py:method:: set_convergence(theConvergence) .. py:method:: save() .. py:method:: get_convergence() .. py:method:: get_devices() .. py:method:: get_logopti() .. py:method:: start(optimization_parameters) .. py:class:: OptiHistoric_Empty Totally empty struct, cannot be used within visualization .. py:method:: log_after_evaluation(returned_values: dict) .. py:method:: set_results(theResults) .. py:method:: get_best_devices_without_reevaluating(_) .. py:method:: set_convergence(_) .. py:method:: save() .. py:method:: get_convergence() .. py:method:: get_devices() .. py:method:: get_logopti() .. py:method:: start(_)