optimize

Package Contents

Classes

Functions

class InterfaceCharacterization[source]

Interface for the evaluation of a device

__str__()[source]

Return str(self).

class Characterization[source]

Bases: optimeed.optimize.characterization.interfaceCharacterization.InterfaceCharacterization

Interface for the evaluation of a device

compute(theDevice)[source]

Action to perform to characterize (= compute the objective function) of the device.

Parameters:theDevice – the device to characterize
class InterfaceMathsToPhysics[source]

Interface to transform output from the optimizer to meaningful variables of the device

class MathsToPhysics[source]

Bases: optimeed.optimize.mathsToPhysics.interfaceMathsToPhysics.InterfaceMathsToPhysics

Dummy yet powerful example of maths to physics. The optimization variables are directly injected to the device

fromMathsToPhys(xVector, theDevice, theOptimizationVariables)[source]

Transforms an input vector coming from the optimization (e.g. [0.23, 4, False]) to “meaningful” variable (ex: length, number of poles, flag).

Parameters:
  • xVector – List of optimization variables from the optimizer
  • theDeviceInterfaceDevice
  • opti_variables – list of OptimizationVariable
fromPhysToMaths(theDevice, theOptimizationVariables)[source]

Extracts a mathematical vector from meaningful variable of the Device

Parameters:
  • theDeviceInterfaceDevice
  • opti_variables – list of OptimizationVariable
Returns:

List of optimization variables

__str__()[source]

Return str(self).

class ArrayMathsToPhysics[source]

Bases: optimeed.optimize.mathsToPhysics.interfaceMathsToPhysics.InterfaceMathsToPhysics

Evaluate array M2P. Only use it if specifically needed

fromMathsToPhys(list_of_xvector, theDevice, theOptimizationVariables)[source]

Transforms an input vector coming from the optimization (e.g. [0.23, 4, False]) to “meaningful” variable (ex: length, number of poles, flag).

Parameters:
  • xVector – List of optimization variables from the optimizer
  • theDeviceInterfaceDevice
  • opti_variables – list of OptimizationVariable
fromPhysToMaths(theDevice, theOptimizationVariables)[source]

Extracts a mathematical vector from meaningful variable of the Device

Parameters:
  • theDeviceInterfaceDevice
  • opti_variables – list of OptimizationVariable
Returns:

List of optimization variables

__str__()[source]

Return str(self).

class FastObjCons(constraintEquation, name=None)[source]

Bases: optimeed.optimize.objAndCons.interfaceObjCons.InterfaceObjCons

Convenience class to create an objective or a constraint very fast.

compute(theDevice)[source]

Get the value of the objective or the constraint. The objective is to MINIMIZE and the constraint has to respect VALUE <= 0

Parameters:theDevice – Input device that has already been evaluated
Returns:float.
get_name()[source]
class InterfaceObjCons[source]

Interface class for objectives and constraints. The objective is to MINIMIZE and the constraint has to respect VALUE <= 0

get_name()[source]
__str__()[source]

Return str(self).

class MultiObjective_GA(theGenerator=MyGenerator)[source]

Bases: optimeed.optimize.optiAlgorithms.algorithmInterface.AlgorithmInterface, optimeed.core.Option_class

Based on Platypus Library. Workflow: Define what to optimize and which function to call with a Problem Define the initial population with a Generator Define the algorithm. As options, define how to evaluate the elements with a Evaluator, i.e., for multiprocessing. Define what is the termination condition of the algorithm with TerminationCondition. Here, termination condition is a maximum time.

initialize(initialVectorGuess, listOfOptimizationVariables)[source]

This function is called just before running optimization algorithm.

compute()[source]

Launch the optimization

Returns:vector of optimal variables
set_evaluationFunction(evaluationFunction, callback_on_evaluation, numberOfObjectives, numberOfConstraints, array_evaluator)[source]

Set the evaluation function and all the necessary callbacks

Parameters:
  • evaluationFunction – check evaluateObjectiveAndConstraints()
  • callback_on_evaluation – check callback_on_evaluation(). Call this function after performing the evaluation of the individuals
  • numberOfObjectives – int, number of objectives
  • numberOfConstraints – int, number of constraints
  • array_evaluator – If True, evaluate each generation at once using numpy array. Use it only with care, as it dismisses some features (expert mode)
set_maxtime(maxTime)[source]

Set maximum optimization time (in seconds)

__str__()[source]

Return str(self).

get_convergence()[source]

This function is called just before compute. Because the convergence is contained in opti algorithm, it must be created now.

add_terminationCondition(theTerminationCondition)[source]
reset()[source]
class Monobjective_PSO[source]

Bases: optimeed.optimize.optiAlgorithms.algorithmInterface.AlgorithmInterface, optimeed.core.Option_class

Interface for the optimization algorithm

initialize(initialVectorGuess, listOfOptimizationVariables)[source]

This function is called once parameters can’t be changed anymore, before “get_convergence”.

Parameters:
Returns:

compute()[source]

Launch the optimization

Returns:vector of optimal variables
set_evaluationFunction(evaluationFunction, callback_on_evaluate, numberOfObjectives, _numberOfConstraints, array_evaluator)[source]

Set the evaluation function and all the necessary callbacks

Parameters:
  • evaluationFunction – check evaluateObjectiveAndConstraints()
  • callback_on_evaluation – check callback_on_evaluation(). Call this function after performing the evaluation of the individuals
  • numberOfObjectives – int, number of objectives
  • numberOfConstraints – int, number of constraints
  • array_evaluator – If True, evaluate each generation at once using numpy array. Use it only with care, as it dismisses some features (expert mode)
set_terminationCondition(theTerminationCondition)[source]
set_maxtime(maxTime)[source]

Set maximum optimization time (in seconds)

__str__()[source]

Return str(self).

get_convergence()[source]

Get the convergence of the optimization

Returns:InterfaceConvergence
class Real_OptimizationVariable(attributeName, val_min, val_max)[source]

Bases: OptimizationVariable

Real (continuous) optimization variable. Most used type

get_min_value()[source]
get_max_value()[source]
get_PhysToMaths(deviceIn)[source]

Convert the initial value of the variable contained in the device to optimization variable value

Parameters:deviceInInterfaceDevice
Returns:value of the corresponding optimization variable
do_MathsToPhys(value, deviceIn)[source]

Apply the value to the device

__str__()[source]

Return str(self).

class Binary_OptimizationVariable(attributeName)[source]

Bases: OptimizationVariable

Boolean (True/False) optimization variable.

get_PhysToMaths(deviceIn)[source]

Convert the initial value of the variable contained in the device to optimization variable value

Parameters:deviceInInterfaceDevice
Returns:value of the corresponding optimization variable
do_MathsToPhys(value, deviceIn)[source]

Apply the value to the device

__str__()[source]

Return str(self).

class Integer_OptimizationVariable(attributeName, val_min, val_max)[source]

Bases: OptimizationVariable

Integer variable, in [min_value, max_value]

get_min_value()[source]
get_max_value()[source]
get_PhysToMaths(deviceIn)[source]

Convert the initial value of the variable contained in the device to optimization variable value

Parameters:deviceInInterfaceDevice
Returns:value of the corresponding optimization variable
do_MathsToPhys(value, deviceIn)[source]

Apply the value to the device

__str__()[source]

Return str(self).

run_optimization(optimizer_settings: OptimizerSettings, opti_historic, max_opti_time_sec=10, return_x_solutions=False, array_evaluator=False, initialVectorGuess=None)[source]

Perform the optimization.

Parameters:
  • optimizer_settingsOptimizerSettings containing all information in models, objectives and optimization variable
  • opti_historic – OptiHistoric to log evaluations and results
  • max_opti_time_sec – Maximum optimization time (default stopping criterion, unless modified in algorithm)
  • return_x_solutions – If True, returns raw parameters in reults
  • array_evaluator – If True, evaluate each generation at once using numpy array. Use it only with care, as it dismisses some features (expert mode)
Returns:

list of the best optimized devices, convergence information and [if return_x_solutions=True] best solutions

class OptimizerSettings(theDevice, theObjectives, theConstraints, theOptimizationVariables, theOptimizationAlgorithm=None, theMathsToPhysics=None, theCharacterization=None)[source]

Bases: 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.

get_additional_attributes_to_save()[source]

Return list of attributes corresponding to object, whose type cannot be determined statically (e.g. topology change)

get_additional_attributes_to_save_list()[source]

Same behavior as get_additional_attributes_to_save, but where the attributes contains list of unknown items

get_device()[source]
get_M2P()[source]
get_charac()[source]
get_optivariables()[source]
get_objectives()[source]
get_constraints()[source]
get_optialgorithm()[source]
class OptiHistoric(optiname='opti', autosave_timer=60 * 5, autosave=True, create_new_directory=True, performance_datastruct=True, folder=getPath_workspace())[source]

Contains all the points that have been evaluated

class _pointData(currTime, objectives, constraints)[source]
class _LogParams[source]
add_parameters(params)[source]
get_rows_indices(list_of_params)[source]
log_after_evaluation(returned_values: dict)[source]

Save the output of evaluate to optiHistoric. This function should be called by the optimizer IN a process safe context.

set_results(devicesList)[source]
get_best_devices_without_reevaluating(list_of_best_params)[source]
set_convergence(theConvergence)[source]
save()[source]
get_convergence()[source]
Returns:convergence InterfaceConvergence
get_devices()[source]
Returns:List of devices (ordered by evaluation number)
get_logopti()[source]
Returns:Log optimization (to check the convergence)
start(optimization_parameters)[source]

Function called upon starting the optimization. Create folders.

class OptiHistoric_Fast(optiname='opti')[source]

Almost empty struct, just enough to display the graphs. Used to speed up optimization

log_after_evaluation(returned_values: dict)[source]
set_results(theResults)[source]
get_best_devices_without_reevaluating(_)[source]
set_convergence(theConvergence)[source]
save()[source]
get_convergence()[source]
get_devices()[source]
get_logopti()[source]
start(optimization_parameters)[source]
class OptiHistoric_Empty[source]

Totally empty struct, cannot be used within visualization

log_after_evaluation(returned_values: dict)[source]
set_results(theResults)[source]
get_best_devices_without_reevaluating(_)[source]
set_convergence(_)[source]
save()[source]
get_convergence()[source]
get_devices()[source]
get_logopti()[source]
start(_)[source]