-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from VirtualPlanetaryLaboratory/FloatingPoint
Adding floating point exception checks to GitHub Actions
- Loading branch information
Showing
14 changed files
with
147 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: floating-point | ||
|
||
on: | ||
pull_request: | ||
branches: [main] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
floatingpoint: | ||
name: Check for floating point exceptions | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
id: setup_python | ||
uses: conda-incubator/setup-miniconda@v3 | ||
with: | ||
activate-environment: vplanet | ||
environment-file: environment.yml | ||
python-version: 3.9 | ||
|
||
- name: Run | ||
shell: bash -l {0} | ||
run: | | ||
cd tests/ | ||
python floatingpoint.py |
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 |
---|---|---|
|
@@ -68,6 +68,7 @@ gcov/* | |
*.so | ||
*.valgrind | ||
*.cache | ||
*.floatingpoint | ||
|
||
# Documentation | ||
docs/.build | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
sSystemName Lopez12CPL | ||
|
||
iVerbose 0 | ||
iVerbose 5 | ||
bOverwrite 1 | ||
|
||
saBodyFiles star.in $ # The star | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
sSystemName trappist1 | ||
iVerbose 0 | ||
iVerbose 5 | ||
bOverwrite 1 | ||
saBodyFiles star.in b.in e.in | ||
sUnitMass solar | ||
|
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
|
||
# XXX Near duplicates in maketest.py, 02/06/24 | ||
def Main(): | ||
BuildVPLanet() | ||
dir_list = CollectAllTests() | ||
RemoveOldOutputFiles(dir_list) | ||
|
||
print(" ", flush=True) | ||
tot_fail = 0 | ||
tot_test = 0 | ||
tot_error = 0 | ||
for dir in dir_list: | ||
tot_test += 1 | ||
sys.stdout.write(dir) | ||
sys.stdout.write(": ") | ||
sys.stdout.flush() | ||
os.chdir(dir) | ||
subdirs = dir.split("/") | ||
test = subdirs[1] | ||
outfile = test + ".floatingpoint" | ||
cmd = "../../../bin/vplanet vpl.in" | ||
|
||
with open(outfile, "w+") as f: | ||
subprocess.run(cmd, shell=True, stdout=f, stderr=f) | ||
f = open(outfile, "r") | ||
try: | ||
last_line = f.readlines()[-1] | ||
except: | ||
print("Error") | ||
os.chdir("../../") | ||
tot_error += 1 | ||
continue | ||
# print(last_line) | ||
f.close() | ||
if last_line != "Simulation completed.\n": | ||
tot_fail += 1 | ||
print("Fail", flush=True) | ||
else: | ||
print("Pass", flush=True) | ||
os.chdir("../../") | ||
|
||
print("") | ||
|
||
if tot_fail == 0 and tot_error == 0: | ||
print("No floating point errors found!") | ||
assert True | ||
else: | ||
print( | ||
repr(tot_fail) | ||
+ "/" | ||
+ repr(tot_test) | ||
+ " test(s) failed; " | ||
+ repr(tot_error) | ||
+ "/" | ||
+ repr(tot_test) | ||
+ " test(s) errored." | ||
) | ||
assert False | ||
exit(0) | ||
|
||
|
||
def BuildVPLanet(): | ||
sys.stdout.write("Building VPLanet...") | ||
sys.stdout.flush() | ||
os.chdir("../") | ||
subprocess.check_output(["make", "debug"]) | ||
print("done.", flush=True) | ||
os.chdir("tests") | ||
|
||
|
||
def CollectAllTests(): | ||
top_list = sorted(next(os.walk("."))[1]) | ||
dir_list = [] | ||
for top in top_list: | ||
subdirs = [ | ||
os.path.join(top, subdir) for subdir in sorted(next(os.walk(top))[1]) | ||
] | ||
for subdir in subdirs: | ||
if "pycache" not in subdir: | ||
dir_list.append(subdir) | ||
|
||
return dir_list | ||
|
||
|
||
def RemoveOldOutputFiles(dir_list): | ||
for dir in dir_list: | ||
os.chdir(dir) | ||
subdirs = dir.split("/") | ||
test = subdirs[1] | ||
outfile = test + ".floatingpoint" | ||
# print (test,outfile) | ||
if os.path.exists(outfile): | ||
os.remove(outfile) | ||
os.chdir("../../") | ||
|
||
|
||
if __name__ == "__main__": | ||
Main() |