TopFarmProblem
- class topfarm.TopFarmProblem(design_vars, cost_comp=None, driver=<topfarm.easy_drivers.EasyScipyOptimizeDriver object>, constraints=[], plot_comp=<topfarm.plotting.NoPlot object>, record_id=None, expected_cost=1, ext_vars={}, approx_totals=False, recorder=None, additional_recorders=None, n_wt=0, grid_layout_comp=None, penalty_comp=None, reports=None, **kwargs)[source]
__init__
(design_vars[, cost_comp, driver, ...])Initialize TopFarmProblem
evaluate
([state, disp])Evaluate the cost model
optimize
([state, disp, recorder_as_list])Run the optimization problem
- __init__(design_vars, cost_comp=None, driver=<topfarm.easy_drivers.EasyScipyOptimizeDriver object>, constraints=[], plot_comp=<topfarm.plotting.NoPlot object>, record_id=None, expected_cost=1, ext_vars={}, approx_totals=False, recorder=None, additional_recorders=None, n_wt=0, grid_layout_comp=None, penalty_comp=None, reports=None, **kwargs)[source]
Initialize TopFarmProblem
- Parameters
design_vars (dict or list of key-initial_value-tuples) –
Design variables for the problem.
Ex: {‘x’: [1,2,3], ‘y’:([3,2,1],0,1), ‘z’:([4,5,6],[4,5,4], [6,7,6])}
Ex: [(‘x’, [1,2,3]), (‘y’,([3,2,1],0,1)), (‘z’,([4,5,6],[4,5,4], [6,7,6]))]
Ex: [(‘x’, ([1,2,3],0,3,’m’)), (‘y’,([3,2,1],’m’)), (‘z’,([4,5,6],[4,5,4], [6,7,6]))]
Ex: zip(‘xy’, pos.T)
The keys (x, y, z) are the names of the design variable.
The values are either
the initial value or
- on of the following tuples:
(initial value, unit) (initial value, lower bound, upper bound) (initial value, lower bound, upper bound, unit)
cost_comp (ExplicitComponent or TopFarmProblem or TopFarmGroup) –
Component that provides the cost function. It has to be the style of an OpenMDAO v2 ExplicitComponent. Pure python cost functions can be wrapped using
CostModelComponent
class intopfarm.cost_models.cost_model_wrappers
.ExplicitComponent are wrapped into a TopFarmGroup.
For nested problems, the cost comp_comp is typically a TopFarmProblem
driver (openmdao Driver, optinal) – Driver used to solve the optimization driver. For an example, see the
EasyScipyOptimizeDriver
class intopfarm.easy_drivers
.constraints (list of Constraint-objects or tuples) – Constraint-objects are e.g. XYBoundaryConstraint, SpacingConstraint Tuples have the form (variable to constrain, {dict with options passed to the the OpenMDAO method add_constraint})
penalty_comp (ExplicitComponent, optional) – Component that converts constraints into penalty both for drivers that do and do not support constraints. Constraints are automatically converted to penalty for drivers that do not support constraints and the default magnitude of the penalty that is added to the objective is the sum of the constraint violations + 10**10.
plot_comp (ExplicitComponent, optional) – OpenMDAO ExplicitComponent used to plot the state (during optimization). For no plotting, pass in the
topfarm.plotting.NoPlot
class.record_id (string "<record_id>:<case>", optional) –
Identifier for the optimization. Allows a user to restart an optimization where it left off.
record_id can be name (saves as recordings/<name>.pkl), abs or relative path Case can be:
””, “latest”, “-1”: Continue from latest
”best”: Continue from best case (minimum cost)
”0”: Start from scratch (initial position)
”4”: Start from case number 4
expected_cost (int, float or None, optional) –
Used to scale the cost, default is 1. This has influence on some drivers, e.g. SLSQP where it affects the step size
If None, the value is found by evaluating the cost function
ext_vars (dict or list of key-initial_value tuple) –
Used for nested problems to propagate variables from parent problem
Ex. {‘type’: [1,2,3]}
Ex. [(‘type’, [1,2,3])]
approx_totals (bool or dict) – If True, approximates the total derivative of the cost_comp group, skipping the partial ones. If it is a dictionary, it’s elements are passed to the approx_totals function of an OpenMDAO Group.
recorder (Main recorder) –
additional_recorders (list(Recorder) or None) – A list of additional recorders to be added to the problem
n_wt (int) – Number of wind turbines
grid_layout_comp (ExplicitComponent or TopFarmGroup) – Components that uses at least one of topfarm.grid_x_key or topfarm.grid_y_key as input, and provides topfarm.x_key and topfarm.y_key as output. Default values for topfarm.grid_x_key or topfarm.grid_y_key are ‘sx’ and ‘sy’ respectively. These can be overwritten in the same way as e.g. topfarm.x_key. The component is inserted before constraint components will enables the use of components relying on x and y situated before the main cost component in the workflow.
Examples
See main() in the bottom of this file
- optimize(state={}, disp=False, recorder_as_list=False)[source]
Run the optimization problem
- Parameters
state (dict, optional) –
Initial state
Ex: {‘x’: [1,2,3], ‘y’:[3,2,1]}
The current state is used to unspecified variables
disp (bool, optional) – if True, the time used for the optimization is printed
recorder_as_list (bool, optional) – if True, returns multiprocessing friendly recorder as list of class and attributes that can be pickled. Use TopFarmListRecorder().list2recorder to restore TopFarmListRecorder object
- Returns
Optimized cost (float)
state (dict)
recorder (TopFarmListRecorder or NestedTopFarmListRecorder or [TopFarmListRecorder.__class__, attributes])