Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
TopFarm2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TOPFARM
TopFarm2
Commits
a392aa39
Commit
a392aa39
authored
6 years ago
by
Jennifer Rinker
Browse files
Options
Downloads
Patches
Plain Diff
updating docstrings
parent
50bc0b3b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!74
Updating docstrings
Pipeline
#5186
passed
6 years ago
Stage: test
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
docs/source/api.rst
+20
-0
20 additions, 0 deletions
docs/source/api.rst
docs/source/conf.py
+3
-1
3 additions, 1 deletion
docs/source/conf.py
docs/source/index.rst
+1
-0
1 addition, 0 deletions
docs/source/index.rst
topfarm/_topfarm.py
+87
-12
87 additions, 12 deletions
topfarm/_topfarm.py
with
111 additions
and
13 deletions
docs/source/api.rst
0 → 100644
+
20
−
0
View file @
a392aa39
.. _api:
===========================
API
===========================
Defining Problems in TOPFARM
-----------------------------
.. # pull the docstring from the module
.. automodule:: topfarm._topfarm
.. # pull the TopFarmProblem class and autopopulate methods
.. autoclass:: topfarm.TopFarmProblem
:members:
.. # pull the TurbineXYZOptimizationProblem class and autopopulate methods
.. autoclass:: topfarm.TurbineXYZOptimizationProblem
:members:
\ No newline at end of file
This diff is collapsed.
Click to expand it.
docs/source/conf.py
+
3
−
1
View file @
a392aa39
...
@@ -16,7 +16,9 @@
...
@@ -16,7 +16,9 @@
# If extensions (or modules to document with autodoc) are in another directory,
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import
os
import
sys
sys
.
path
.
insert
(
0
,
os
.
path
.
join
(
os
.
path
.
abspath
(
'
.
'
),
'
..
'
,
'
..
'
))
# -- General configuration ------------------------------------------------
# -- General configuration ------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
docs/source/index.rst
+
1
−
0
View file @
a392aa39
...
@@ -11,6 +11,7 @@ Welcome to TOPFARM, the wind-farm optimizer
...
@@ -11,6 +11,7 @@ Welcome to TOPFARM, the wind-farm optimizer
installation
installation
using_topfarm
using_topfarm
api
.. toctree::
.. toctree::
:caption: Examples
:caption: Examples
...
...
This diff is collapsed.
Click to expand it.
topfarm/_topfarm.py
+
87
−
12
View file @
a392aa39
from
topfarm.constraint_components.boundary_component
import
BoundaryComp
"""
TOPFARM OpenMDAO Problems.
from
topfarm.constraint_components.spacing_component
import
SpacingComp
from
topfarm.plotting
import
PlotComp
This module contains the different OpenMDAO problems that are defined for
from
topfarm.utils
import
smart_start
different types of optimization problems.
Notes
-----
A new OpenMDAO problem must be constructed for every optimization problem that
has different design variables. For example, if one problem optimizes a
wind-farm layout but another optimizes turbine types at fixed turbine
positions, these require OpenMDAO problems that are constructed differently.
To get around this, TOPFARM has a base optimization problem,
``TopFarmProblem`` that inherits from the ``Problem`` class in OpenMDAO. The
methods and attributes in this TOPFARM base class are inherited by the other
types of problems and then expanded to reflect the particular characteristics
of each optimization problem.
"""
import
time
import
time
import
numpy
as
np
import
numpy
as
np
from
openmdao.drivers.doe_generators
import
DOEGenerator
,
ListGenerator
from
openmdao.drivers.doe_driver
import
DOEDriver
from
openmdao.core.explicitcomponent
import
ExplicitComponent
from
topfarm.recorders
import
ListRecorder
,
NestedTopFarmListRecorder
,
\
TopFarmListRecorder
from
openmdao.api
import
Problem
,
ScipyOptimizeDriver
,
IndepVarComp
from
openmdao.api
import
Problem
,
ScipyOptimizeDriver
,
IndepVarComp
from
openmdao.core.explicitcomponent
import
ExplicitComponent
from
openmdao.drivers.doe_driver
import
DOEDriver
from
openmdao.drivers.doe_generators
import
DOEGenerator
,
ListGenerator
from
openmdao.drivers.genetic_algorithm_driver
import
SimpleGADriver
from
openmdao.drivers.genetic_algorithm_driver
import
SimpleGADriver
from
topfarm.constraint_components.boundary_component
import
BoundaryComp
from
topfarm.constraint_components.spacing_component
import
SpacingComp
from
topfarm.drivers
import
random_search_driver
from
topfarm.drivers.random_search_driver
import
RandomSearchDriver
from
topfarm.drivers.random_search_driver
import
RandomSearchDriver
from
topfarm.easy_drivers
import
EasyRandomSearchDriver
from
topfarm.easy_drivers
import
EasyRandomSearchDriver
from
topfarm.drivers
import
random_search_driver
from
topfarm.plotting
import
PlotComp
from
topfarm.recorders
import
ListRecorder
,
NestedTopFarmListRecorder
,
\
TopFarmListRecorder
from
topfarm.utils
import
smart_start
class
TopFarmProblem
(
Problem
):
class
TopFarmProblem
(
Problem
):
"""
Base OpenMDAO problem for TOPFARM optimizations.
Parameters
----------
cost_comp : OpenMDAO-style cost component.
A cost component in the style of an OpenMDAO v2 ExplicitComponent.
For an example, see the ``CostModelComponent`` class in
``topfarm.cost_models.cost_model_wrappers``.
driver : OpenMDAO-style optimization driver.
Driver used to solve the optimization driver. For an example, see the
``EasyScipyOptimizeDriver`` class in ``topfarm.easy_drivers``.
plot_comp : Plotting component.
OpenMDAO ExplicitComponent to specify which type of plotting you want.
For no plotting, pass in the ``topfarm.plotting.NoPlot`` class.
record_id : str.
Identifier for the optimization. Allows a user to restart an
optimization where it left off.
expected_cost : float
Approximate expected value of the final cost. Used for scaling the cost
to condition it for optimization.
"""
def
__init__
(
self
,
cost_comp
,
driver
,
plot_comp
,
record_id
,
expected_cost
):
def
__init__
(
self
,
cost_comp
,
driver
,
plot_comp
,
record_id
,
expected_cost
):
"""
Initialize a TopFarmProblem.
"""
Problem
.
__init__
(
self
)
Problem
.
__init__
(
self
)
if
isinstance
(
cost_comp
,
TopFarmProblem
):
if
isinstance
(
cost_comp
,
TopFarmProblem
):
cost_comp
=
cost_comp
.
as_component
()
cost_comp
=
cost_comp
.
as_component
()
...
@@ -79,6 +122,7 @@ class TopFarmProblem(Problem):
...
@@ -79,6 +122,7 @@ class TopFarmProblem(Problem):
self
.
recorder
=
TopFarmListRecorder
(
self
.
record_id
)
self
.
recorder
=
TopFarmListRecorder
(
self
.
record_id
)
def
evaluate
(
self
,
state
=
{}):
def
evaluate
(
self
,
state
=
{}):
"""
Evaluate the cost model.
"""
t
=
time
.
time
()
t
=
time
.
time
()
self
.
update_state
(
state
)
self
.
update_state
(
state
)
tmp_recorder
=
ListRecorder
()
tmp_recorder
=
ListRecorder
()
...
@@ -89,6 +133,7 @@ class TopFarmProblem(Problem):
...
@@ -89,6 +133,7 @@ class TopFarmProblem(Problem):
return
self
.
cost
,
self
.
state
return
self
.
cost
,
self
.
state
def
evaluate_gradients
(
self
):
def
evaluate_gradients
(
self
):
"""
Evaluate the gradients.
"""
t
=
time
.
time
()
t
=
time
.
time
()
rec
=
ListRecorder
()
rec
=
ListRecorder
()
self
.
driver
.
add_recorder
(
rec
)
self
.
driver
.
add_recorder
(
rec
)
...
@@ -98,6 +143,7 @@ class TopFarmProblem(Problem):
...
@@ -98,6 +143,7 @@ class TopFarmProblem(Problem):
return
res
return
res
def
optimize
(
self
,
state
=
{}):
def
optimize
(
self
,
state
=
{}):
"""
Run the optimization problem.
"""
self
.
load_recorder
()
self
.
load_recorder
()
self
.
update_state
(
state
)
self
.
update_state
(
state
)
if
self
.
recorder
.
num_cases
>
0
:
if
self
.
recorder
.
num_cases
>
0
:
...
@@ -120,8 +166,7 @@ class TopFarmProblem(Problem):
...
@@ -120,8 +166,7 @@ class TopFarmProblem(Problem):
self
.
update_state
({
k
:
best_case
.
outputs
[
k
]
for
k
in
best_case
.
outputs
})
self
.
update_state
({
k
:
best_case
.
outputs
[
k
]
for
k
in
best_case
.
outputs
})
return
self
.
cost
,
self
.
state
,
self
.
recorder
return
self
.
cost
,
self
.
state
,
self
.
recorder
def
check_gradients
(
self
,
all
=
False
,
tol
=
1e-3
):
def
check_gradients
(
self
,
all
=
False
,
tol
=
1e-3
):
# check gradient computations
"""
Check gradient computations
"""
if
all
:
if
all
:
comp_name_lst
=
[
comp
.
pathname
for
comp
in
self
.
model
.
system_iter
()
comp_name_lst
=
[
comp
.
pathname
for
comp
in
self
.
model
.
system_iter
()
if
comp
.
_has_compute_partials
]
if
comp
.
_has_compute_partials
]
...
@@ -181,6 +226,36 @@ class TurbineTypeOptimizationProblem(TopFarmProblem):
...
@@ -181,6 +226,36 @@ class TurbineTypeOptimizationProblem(TopFarmProblem):
class
TurbineXYZOptimizationProblem
(
TopFarmProblem
):
class
TurbineXYZOptimizationProblem
(
TopFarmProblem
):
"""
Optimize the turbine locations in a wind farm.
Parameters
----------
cost_comp : OpenMDAO-style cost component.
A cost component in the style of an OpenMDAO v2 ExplicitComponent.
For an example, see the ``CostModelComponent`` class in
``topfarm.cost_models.cost_model_wrappers``.
turbineXYZ : np.ndarray.
Array of the initial locations of the wind turbines, with dimensions
[n_wt x n_d].
boundary_comp : TOPFARM boundary component.
OpenMDAO for defining the boundary of the wind farm.
min_spacing : float, optional.
Minimum allowable distance between turbines in meters.
driver : OpenMDAO-style optimization driver, optional.
Driver used to solve the optimization driver. For an example, see the
``EasyScipyOptimizeDriver`` class in ``topfarm.easy_drivers``. Default
is the ScipyOptimizeDriver.
plot_comp : Plotting component, optional.
OpenMDAO ExplicitComponent to specify which type of plotting you want.
For no plotting, pass in the ``topfarm.plotting.NoPlot`` class. Default
is none.
record_id : str, optional.
Identifier for the optimization. Allows a user to restart an
optimization where it left off. Default is none.
expected_cost : float, optional.
Approximate expected value of the final cost. Used for scaling the cost
to condition it for optimization. Default is 1.
"""
def
__init__
(
self
,
cost_comp
,
turbineXYZ
,
boundary_comp
,
min_spacing
=
None
,
def
__init__
(
self
,
cost_comp
,
turbineXYZ
,
boundary_comp
,
min_spacing
=
None
,
driver
=
ScipyOptimizeDriver
(),
plot_comp
=
None
,
record_id
=
None
,
expected_cost
=
1
):
driver
=
ScipyOptimizeDriver
(),
plot_comp
=
None
,
record_id
=
None
,
expected_cost
=
1
):
if
plot_comp
:
if
plot_comp
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment