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

Adding floating point exception checks to GitHub Actions #280

Merged
merged 3 commits into from
Mar 29, 2024
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
32 changes: 32 additions & 0 deletions .github/workflows/floatingpoint.yml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ gcov/*
*.so
*.valgrind
*.cache
*.floatingpoint

# Documentation
docs/.build
Expand Down
2 changes: 2 additions & 0 deletions src/distrot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,8 @@ void WriteBodyDYoblDtDistRot(BODY *body, CONTROL *control, OUTPUT *output,

/* Ensure that we don't overwrite derivative */
dDeriv = 0;
dDeriv = pow(10, 300);
dDeriv *= dDeriv;
for (iPert = 0; iPert <= body[iBody].iGravPerts; iPert++) {
dDeriv += *(update[iBody].padDYoblDtDistRot[iPert]);
}
Expand Down
1 change: 1 addition & 0 deletions src/vplanet.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int main_impl(int argc, char *argv[]) {
// feenableexcept(FE_INVALID | FE_OVERFLOW);
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID);
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_OVERFLOW);
fprintf(stderr, "INFO: Floating point trapping enabled.\n");
#else
fprintf(stderr,
"WARNING: Floating point trapping only enabled for x86 "
Expand Down
2 changes: 1 addition & 1 deletion tests/AtmescEqtideStellar/Lopez12CPL/vpl.in
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
Expand Down
2 changes: 1 addition & 1 deletion tests/AtmescEqtideStellar/WaterLossCPL/vpl.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Primary input file to demonstrate coupling between AtmEsc and EqTide with
# water present
sSystemName WaterCPL
iVerbose 0
iVerbose 5
bOverwrite 1

saBodyFiles star.in b.in
Expand Down
2 changes: 1 addition & 1 deletion tests/AtmescEqtideStellar/WaterLossCTL/vpl.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Primary input file to demonstrate coupling between AtmEsc and EqTide with
# water present
sSystemName WaterCTL
iVerbose 0
iVerbose 5
bOverwrite 1

saBodyFiles star.in b.in
Expand Down
2 changes: 1 addition & 1 deletion tests/AtmescSpinbody/NBodyAtmEsc/vpl.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sUnitAngle deg # Options: deg, rad
bDoLog 1 # Write a log file?
iDigits 5 # Maximum number of digits to right of decimal
dMinValue 1e-10 # Minimum value of eccentricity/obliquity
iVerbose 0 # Verbosity level max=5
iVerbose 5 # Verbosity level max=5

#Evolution Parameters
bDoForward 1 # Perform a forward evolution?
Expand Down
2 changes: 1 addition & 1 deletion tests/AtmescStellar/DiffLimWaterEscape/vpl.in
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
Expand Down
2 changes: 1 addition & 1 deletion tests/AtmescStellar/MiniNeptuneEvapDyn/vpl.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Example from Fig. 3 from Lehmer & Catling (2017), but with evolving properties
sSystemName dynamic

iVerbose 0
iVerbose 5
bOverwrite 1
saBodyFiles star.in planet.in

Expand Down
2 changes: 1 addition & 1 deletion tests/BinaryEqtideStellar/STEEP_CBP_CPL/vpl.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Primary input file for VPLANET
sSystemName STEEP_CPL # System Name
iVerbose 0 # Verbosity level
iVerbose 5 # Verbosity level
bOverwrite 1 # Allow file overwrites?

# List of "body files" that contain body-specific parameters
Expand Down
2 changes: 1 addition & 1 deletion tests/DistorbDistrotEqtide/CTL_LL2/vpl.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Primary input file for VPLANET
sSystemName TGard # System Name
iVerbose 0 # Verbosity level
iVerbose 5 # Verbosity level
bOverwrite 1 # Allow file overwrites?

# All space after a # is ignored, as is white space
Expand Down
2 changes: 1 addition & 1 deletion tests/DistorbDistrotEqtide/CTL_RD4/vpl.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Primary input file for VPLANET
sSystemName TGard # System Name
iVerbose 0 # Verbosity level
iVerbose 5 # Verbosity level
bOverwrite 1 # Allow file overwrites?

# All space after a # is ignored, as is white space
Expand Down
102 changes: 102 additions & 0 deletions tests/floatingpoint.py
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()
Loading