forked from NREL/wind-hybrid-open-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Establish tests and clarify naming (NREL#24)
* Testing interface_base. * Remove repeated class definition. * renaming send_setpoints and compute_setpoints to send_controls and compute_controls, respectively, for generality. * Move controller_base into controllers/ directory. * Beginning to build out interface library tests. * Updating to check_controls. * setpoints -> controls for dicts. * Test imports, methods implemented. * Tests for HerculesADYawInterface. * Explicit dictionary input. * Simplified tests for HerculesWindBatteryInterface * Ruff. * Inheritance tests. * Beginnings of controller library test. * Improved developer installation instructions. * Add note for future test for HerculesWindBatteryController. * Ruff. * Add zmq to requirements. * Reverting some changes from setpoints to controls in the wind battery controlller/interface for current compatibility with Hercules.
- Loading branch information
Showing
25 changed files
with
459 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ | |
# "dash-daq==0.5.0", | ||
# "scikit-image", | ||
# ZMQ stuff | ||
# "zmq", | ||
"zmq", | ||
# NETCDF | ||
# "netCDF4", | ||
# YAML | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Copyright 2021 NREL | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
|
||
# See https://nrel.github.io/wind-hybrid-open-controller for documentation | ||
|
||
from whoc.controllers import ( | ||
HerculesWindBatteryController, | ||
WakeSteeringADStandin, | ||
) | ||
from whoc.interfaces import HerculesADYawInterface | ||
from whoc.interfaces.interface_base import InterfaceBase | ||
|
||
|
||
class StandinInterface(InterfaceBase): | ||
""" | ||
Empty class to test controllers. | ||
""" | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def get_measurements(self): | ||
pass | ||
|
||
def check_controls(self): | ||
pass | ||
|
||
def send_controls(self): | ||
pass | ||
|
||
|
||
test_hercules_dict = { | ||
"dt": 1, | ||
"time": 0, | ||
"controller": {"num_turbines": 2, "initial_conditions": {"yaw": [270.0, 270.0]}}, | ||
"hercules_comms": { | ||
"amr_wind": { | ||
"test_farm": { | ||
"turbine_wind_directions": [271.0, 272.5], | ||
"turbine_powers": [4000.0, 4001.0], | ||
} | ||
} | ||
}, | ||
"py_sims": {"test_battery": {"outputs": 10.0}}, | ||
} | ||
|
||
|
||
def test_controller_instantiation(): | ||
""" | ||
Tests whether all controllers can be imported correctly and that they | ||
each implement the required methods specified by ControllerBase. | ||
""" | ||
test_interface = StandinInterface() | ||
|
||
_ = WakeSteeringADStandin(interface=test_interface, input_dict=test_hercules_dict) | ||
_ = HerculesWindBatteryController(interface=test_interface, input_dict=test_hercules_dict) | ||
|
||
|
||
def test_WakeSteeringADStandin(): | ||
test_interface = HerculesADYawInterface(test_hercules_dict) | ||
test_controller = WakeSteeringADStandin(interface=test_interface, input_dict=test_hercules_dict) | ||
|
||
# Check that the controller can be stepped | ||
test_hercules_dict_out = test_controller.step(hercules_dict=test_hercules_dict) | ||
assert test_hercules_dict_out["hercules_comms"]["amr_wind"]["test_farm"][ | ||
"turbine_yaw_angles" | ||
] == [270.0, 270.0] | ||
|
||
test_hercules_dict["time"] = 20 | ||
test_hercules_dict_out = test_controller.step(hercules_dict=test_hercules_dict) | ||
assert ( | ||
test_hercules_dict_out["hercules_comms"]["amr_wind"]["test_farm"]["turbine_yaw_angles"] | ||
== test_hercules_dict["hercules_comms"]["amr_wind"]["test_farm"]["turbine_wind_directions"] | ||
) | ||
|
||
|
||
def test_HerculesWindBatteryController(): | ||
# TODO: write this test, possibly clean up HerculesWindBatteryController class | ||
pass |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copyright 2021 NREL | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
|
||
# See https://nrel.github.io/wind-hybrid-open-controller for documentation | ||
|
||
# import inspect | ||
import pytest | ||
from whoc.interfaces.interface_base import InterfaceBase | ||
|
||
# import whoc.interfaces | ||
|
||
|
||
class InheritanceTestClassBad(InterfaceBase): | ||
""" | ||
Class that is missing necessary methods. | ||
""" | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
|
||
class InheritanceTestClassGood(InterfaceBase): | ||
""" | ||
Class that is missing necessary methods. | ||
""" | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def get_measurements(self): | ||
pass | ||
|
||
def check_controls(self): | ||
pass | ||
|
||
def send_controls(self): | ||
pass | ||
|
||
|
||
def test_InterfaceBase_methods(): | ||
""" | ||
Check that the base interface class establishes the correct methods. | ||
""" | ||
interface_base = InheritanceTestClassGood() | ||
assert hasattr(interface_base, "get_measurements") | ||
assert hasattr(interface_base, "check_controls") | ||
assert hasattr(interface_base, "send_controls") | ||
|
||
|
||
def test_inherited_methods(): | ||
""" | ||
Check that a subclass of InterfaceBase inherits methods correctly. | ||
""" | ||
|
||
with pytest.raises(TypeError): | ||
_ = InheritanceTestClassBad() | ||
|
||
_ = InheritanceTestClassGood() | ||
|
||
|
||
def test_all_interfaces_implement_methods(): | ||
# In future, I'd like to dynamically instantiate classes, but the different | ||
# inputs that they require on __init__ is currently a roadblock, so I'll just | ||
# explicitly instantiate each interface class for the time being. | ||
|
||
# class_dict = dict(inspect.getmembers(whoc.interfaces, inspect.isclass)) | ||
|
||
pass |
Oops, something went wrong.