Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to regression test python scripts #1222

Merged
merged 7 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .github/workflows/automated-dev-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
- name: Setup workspace
run: cmake -E make_directory ${{runner.workspace}}/openfast/build
- name: Configure build
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
- name: Setup workspace
run: cmake -E make_directory ${{runner.workspace}}/openfast/build
- name: Configure build
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev # gcovr
- name: Setup workspace
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Build OpenFAST C-Interfaces
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Build OpenFAST glue-code
Expand Down Expand Up @@ -249,7 +249,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Build FAST.Farm
Expand Down Expand Up @@ -287,7 +287,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Run AeroDyn tests
Expand Down Expand Up @@ -332,7 +332,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Configure Tests
Expand Down Expand Up @@ -387,7 +387,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Run Interface / API tests
Expand Down Expand Up @@ -424,7 +424,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Configure Tests
Expand Down Expand Up @@ -471,7 +471,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Configure Tests
Expand Down Expand Up @@ -515,7 +515,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Configure Tests
Expand Down Expand Up @@ -559,7 +559,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Configure Tests
Expand Down Expand Up @@ -603,7 +603,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Configure Tests
Expand Down Expand Up @@ -647,7 +647,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Configure Tests
Expand Down Expand Up @@ -691,7 +691,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Configure Tests
Expand Down Expand Up @@ -735,7 +735,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install numpy Bokeh
pip install numpy "Bokeh>=2.4"
sudo apt-get update -y
sudo apt-get install -y libhdf5-dev libopenmpi-dev libyaml-cpp-dev
- name: Configure Tests
Expand Down
2 changes: 1 addition & 1 deletion reg_tests/executeAerodynRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
caseInputFile = os.path.join(testBuildDirectory, "ad_driver.dvr")
returnCode = openfastDrivers.runAerodynDriverCase(caseInputFile, executable, verbose=verbose)
if returnCode != 0:
rtl.exitWithError("")
sys.exit(returnCode*10)

### Build the filesystem navigation variables for running the regression test
# For multiple turbines, test turbine 2, for combined cases, test case 4
Expand Down
2 changes: 1 addition & 1 deletion reg_tests/executeBeamdynRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
caseInputFile = os.path.join(testBuildDirectory, "bd_driver.inp")
returnCode = openfastDrivers.runBeamdynDriverCase(caseInputFile, executable)
if returnCode != 0:
rtl.exitWithError("")
sys.exit(returnCode*10)

### Build the filesystem navigation variables for running the regression test
localOutFile = os.path.join(testBuildDirectory, "bd_driver.out")
Expand Down
2 changes: 1 addition & 1 deletion reg_tests/executeFASTFarmRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def ignoreBaselineItems(directory, contents):
caseInputFile = os.path.join(testBuildDirectory, caseName + ".fstf")
returnCode = openfastDrivers.runOpenfastCase(caseInputFile, executable)
if returnCode != 0:
rtl.exitWithError("")
sys.exit(returnCode*10)

### Build the filesystem navigation variables for running the regression test
localOutFile = os.path.join(testBuildDirectory, caseName + ".out")
Expand Down
2 changes: 1 addition & 1 deletion reg_tests/executeHydrodynPyRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
caseInputFile = os.path.join(testBuildDirectory, "hydrodyn_driver.py")
returnCode = openfastDrivers.runHydrodynDriverCase(caseInputFile, executable)
if returnCode != 0:
rtl.exitWithError("")
sys.exit(returnCode*10)

### Build the filesystem navigation variables for running the regression test
localOutFile = os.path.join(testBuildDirectory, "hd_py.out")
Expand Down
14 changes: 10 additions & 4 deletions reg_tests/executeHydrodynRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
parser.add_argument("buildDirectory", metavar="path/to/openfast_repo/build", type=str, nargs=1, help="The path to the OpenFAST repository build directory.")
parser.add_argument("rtol", metavar="Relative-Tolerance", type=float, nargs=1, help="Relative tolerance to allow the solution to deviate; expressed as order of magnitudes less than baseline.")
parser.add_argument("atol", metavar="Absolute-Tolerance", type=float, nargs=1, help="Absolute tolerance to allow small values to pass; expressed as order of magnitudes less than baseline.")
parser.add_argument("-p", "-plot", dest="plot", default=False, metavar="Plotting-Flag", type=bool, nargs="?", help="bool to include matplotlib plots in failed cases")
parser.add_argument("-n", "-no-exec", dest="noExec", default=False, metavar="No-Execution", type=bool, nargs="?", help="bool to prevent execution of the test cases")
parser.add_argument("-v", "-verbose", dest="verbose", default=False, metavar="Verbose-Flag", type=bool, nargs="?", help="bool to include verbose system output")
parser.add_argument("-p", "-plot", dest="plot", default=False, const=True, metavar="Plotting-Flag", type=bool, nargs="?", help="bool to include matplotlib plots in failed cases")
parser.add_argument("-n", "-no-exec", dest="noExec", default=False, const=True, metavar="No-Execution", type=bool, nargs="?", help="bool to prevent execution of the test cases")
parser.add_argument("-v", "-verbose", dest="verbose", default=False, const=True, metavar="Verbose-Flag", type=bool, nargs="?", help="bool to include verbose system output")

args = parser.parse_args()

Expand Down Expand Up @@ -98,13 +98,19 @@
for file in glob.glob(os.path.join(inputsDirectory,"*dat")):
filename = file.split(os.path.sep)[-1]
shutil.copy(os.path.join(inputsDirectory,filename), os.path.join(testBuildDirectory,filename))

dirToCopy = os.path.join("glue-codes","openfast","5MW_Baseline","HydroData")
buildDirectoryGlue = os.path.join(buildDirectory,os.pardir,os.pardir,dirToCopy)
if not os.path.isdir(buildDirectoryGlue):
src = os.path.join(rtest,dirToCopy)
shutil.copytree(src, buildDirectoryGlue)

### Run HydroDyn on the test case
if not noExec:
caseInputFile = os.path.join(testBuildDirectory, "hd_driver.inp")
returnCode = openfastDrivers.runHydrodynDriverCase(caseInputFile, executable)
if returnCode != 0:
rtl.exitWithError("")
sys.exit(returnCode*10)

### Build the filesystem navigation variables for running the regression test
localOutFile = os.path.join(testBuildDirectory, "driver.HD.out")
Expand Down
4 changes: 2 additions & 2 deletions reg_tests/executeInflowwindPyRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
caseInputFile = os.path.join(testBuildDirectory, "inflowWind_testDriver.py")
returnCode = openfastDrivers.runInflowwindDriverCase(caseInputFile, executable)
if returnCode != 0:
rtl.exitWithError("")

sys.exit(returnCode*10)
### Build the filesystem navigation variables for running the regression test
localOutFile = os.path.join(testBuildDirectory, "Points.Velocity.dat")
baselineOutFile = os.path.join(targetOutputDirectory, "Points.Velocity.dat")
Expand Down
2 changes: 1 addition & 1 deletion reg_tests/executeInflowwindRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
caseInputFile = os.path.join(testBuildDirectory, "ifw_driver.inp")
returnCode = openfastDrivers.runInflowwindDriverCase(caseInputFile, executable)
if returnCode != 0:
rtl.exitWithError("")
sys.exit(returnCode*10)

### Build the filesystem navigation variables for running the regression test
localOutFile = os.path.join(testBuildDirectory, "Points.Velocity.dat")
Expand Down
4 changes: 2 additions & 2 deletions reg_tests/executeOpenfastAeroAcousticRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def ignoreBaselineItems(directory, contents):
caseInputFile = os.path.join(testBuildDirectory, caseName + ".fst")
returnCode = openfastDrivers.runOpenfastCase(caseInputFile, executable)
if returnCode != 0:
rtl.exitWithError("")

sys.exit(returnCode*10)
### Build the filesystem navigation variables for running the regression test
# testing on file 2. Gives each observer and sweep of frequency ranges
localOutFile = os.path.join(testBuildDirectory, caseName + "_2.out")
Expand Down
2 changes: 1 addition & 1 deletion reg_tests/executeOpenfastCppRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def ignoreBaselineItems(directory, contents):
caseInputFile = os.path.abspath("cDriver.yaml")
returnCode = openfastDrivers.runOpenfastCase(caseInputFile, executable)
if returnCode != 0:
rtl.exitWithError("")
sys.exit(returnCode*10)
os.chdir(cwd)

### Build the filesystem navigation variables for running the regression test
Expand Down
2 changes: 1 addition & 1 deletion reg_tests/executeOpenfastLinearRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):
caseInputFile = os.path.join(testBuildDirectory, caseName + ".fst")
returnCode = openfastDrivers.runOpenfastCase(caseInputFile, executable)
if returnCode != 0:
rtl.exitWithError("")
sys.exit(returnCode*10)

### Get a all the .lin files in the baseline directory
baselineOutFiles = [f for f in os.listdir(targetOutputDirectory) if '.lin' in f]
Expand Down
2 changes: 1 addition & 1 deletion reg_tests/executeOpenfastRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def ignoreBaselineItems(directory, contents):
caseInputFile = os.path.join(testBuildDirectory, caseName + ".fst")
returnCode = openfastDrivers.runOpenfastCase(caseInputFile, executable)
if returnCode != 0:
rtl.exitWithError("")
sys.exit(returnCode*10)

### Build the filesystem navigation variables for running the regression test
localOutFile = os.path.join(testBuildDirectory, caseName + ".outb")
Expand Down
1 change: 1 addition & 0 deletions reg_tests/executePythonRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def ignoreBaselineItems(directory, contents):
output_channel_names = openfastlib.output_channel_names

### Build the filesystem navigation variables for running the regression test
localOutFile = os.path.join(testBuildDirectory, caseName + ".outb")
baselineOutFile = os.path.join(targetOutputDirectory, caseName + ".outb")
rtl.validateFileOrExit(baselineOutFile)

Expand Down
2 changes: 1 addition & 1 deletion reg_tests/executeSubdynRegressionCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
# run driver
returnCode = openfastDrivers.runSubdynDriverCase(caseInputFile, executable, verbose=verbose)
if returnCode != 0:
rtl.exitWithError("")
sys.exit(returnCode*10)

### Build the filesystem navigation variables for running the regression test
localOutFile = os.path.join(testBuildDirectory, caseName+".SD.out")
Expand Down
36 changes: 25 additions & 11 deletions reg_tests/lib/errorPlotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,30 @@ def finalizePlotDirectory(test_solution, plot_list, case):

for i, plot in enumerate(plot_list):
_path = os.path.join(plot_path, plot + '_div.txt')
with open(_path, 'r') as f:
div = f.read().strip().join((' ', '\n'))
html = ''.join((html, div))
try:
with open(_path, 'r') as f:
div = f.read().strip().join((' ', '\n'))
html = ''.join((html, div))
except FileNotFoundError:
print("The file for ", plot ," does not exist.")

html = ''.join((html, ' </div>' + '\n'))
html = ''.join((html, ' </div>' + '\n'))
html = ''.join((html, '</body>' + '\n'))
html = ''.join((html, _htmlTail()))

script = "" # initialize in case plot_list is empty
for i, plot in enumerate(plot_list):
_path = os.path.join(plot_path, f'{plot}_script.txt')
with open(_path, "r") as f:
_s = f.read()
if i == 0:
script = _s
else:
script = ''.join((script, _s))
try:
with open(_path, "r") as f:
_s = f.read()
if i == 0:
script = _s
else:
script = ''.join((script, _s))
except FileNotFoundError:
msg = "The file does not exist."

shutil.rmtree(plot_path, ignore_errors=True)

Expand All @@ -243,8 +250,8 @@ def exportResultsSummary(path, results):
html.write(' <div class="container">' + '\n')

# Test Case - Pass/Fail - Max Relative Norm
data = [('<a href="{0}/{0}.html">{0}</a>'.format(r[0]), r[1]) for i,r in enumerate(results)]
table = _tableHead(['Test Case', 'Pass/Fail'])
data = [('<a href="{0}/{0}.html">{0}</a>'.format(r[0]), r[1],r[2],'<a href="{0}/{0}.log">{0}.log</a>'.format(r[0])) for i,r in enumerate(results)]
table = _tableHead(['Test Case', 'Pass/Fail', 'Completion Code', 'Screen Output'])
body = ' <tbody>' + '\n'
for i, d in enumerate(data):
body += ' <tr>' + '\n'
Expand All @@ -256,7 +263,14 @@ def exportResultsSummary(path, results):
body += (' <td class="cell-warning">' + fmt + '</td>').format(d[1]) + '\n'
else:
body += (' <td>' + fmt + '</td>').format(d[1]) + '\n'

if d[2] != 0:
body += (' <td class="cell-warning">{}</td>').format(d[2]) + '\n'
else:
body += (' <td>{}</td>').format(d[2]) + '\n'

body += ' <td>{0:s}</td>'.format(d[3]) + '\n'

body += ' </tr>' + '\n'
body += ' </tbody>' + '\n'
table += body
Expand Down
5 changes: 3 additions & 2 deletions reg_tests/lib/openfastDrivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ def _runGenericCase(inputFile, executable, verbose=False, log=True):
rtl.validateFileOrExit(inputFile)
rtl.validateExeOrExit(executable)

casebase = os.path.sep.join(inputFile.split(os.path.sep)[-1].split('.')[:-1])
caseparent = os.path.sep.join(inputFile.split(os.path.sep)[:-1])
#bjj, why wouldn't we check if log is true instead of verbose being false to generate a log file???
if verbose:
logFile = None
else:
caseparent = os.path.sep.join(inputFile.split(os.path.sep)[:-1])
casebase = caseparent.split(os.path.sep)[-1] # assumes that the directory structure name is the name of the .log file. (for consistent driver + glue-code names)
logFile = caseparent + os.path.sep + casebase + '.log'

returnCode = _runCase(executable, inputFile, logFile, stdout)
Expand Down
14 changes: 11 additions & 3 deletions reg_tests/lib/pass_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,17 @@ def calculate_max_norm(testData, baselineData):
return maxnorm(abs(testData - baselineData))

def calculateNorms(test_data, baseline_data):
relative_norm = calculate_max_norm_over_range(test_data, baseline_data)
max_norm = calculate_max_norm(test_data, baseline_data)
relative_l2_norm = calculate_relative_norm(test_data, baseline_data)
if test_data.size != baseline_data.size:
# print("Calculate Norms size(testdata)={}".format(test_data.size))
# print("Calculate Norms size(baseline)={}".format(baseline_data.size))
relative_norm = np.nan * calculate_max_norm_over_range(test_data, test_data)
max_norm = relative_norm
relative_l2_norm = relative_norm
else:
relative_norm = calculate_max_norm_over_range(test_data, baseline_data)
max_norm = calculate_max_norm(test_data, baseline_data)
relative_l2_norm = calculate_relative_norm(test_data, baseline_data)

results = np.stack(
(
relative_norm,
Expand Down
Loading