diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..a1cb1d1 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,46 @@ +# test based on ChatGPT's suggestion +name: CI + +on: + push: + branches: [ master ] # run for every push to master + pull_request: # run for every PR + +jobs: + tests: + runs-on: ubuntu-latest # GitHub-hosted Linux runner + + steps: + # 1️⃣ Bring the source onto the runner + - name: Check out code + uses: actions/checkout@v4 + + # 2️⃣ System packages for build & tests + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + build-essential gfortran make \ + libfftw3-dev liblapack-dev \ + python3 python3-numpy + + # 3️⃣ Compile the QDyn executable (bin ends up in src/qdyn) + - name: Build qdyn + run: | + make -C src clean + make -C src \ + LIBS="-lfftw3 -lm -llapack" # override local path in Makefile + + # 4️⃣ Run the full regression-test suite + - name: Run test suite + run: | + cd tests + bash run_test_suite.sh | tee ../test_output.log + + # 5️⃣ Fail the workflow if any test reported an error + - name: Check for test failures + run: | + if grep "ERROR found" test_output.log; then + echo "Some tests failed — see log above." + exit 1 + fi diff --git a/src/Makefile b/src/Makefile index 3720cf7..1071528 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,9 +3,8 @@ # Compiler FC = gfortran FFLAGS = -# FFTW library needed -LIBS = -L/Users/janosj/Documents/Programs/fftw/fftw-3.3.10/lib -lfftw3 -lm -llapack -LDLIBS = -lfftw3 # This is necessary only on clusters, not on MacOS +LIBS = -L/Users/janosj/Documents/Programs/fftw/fftw-3.3.10/lib -lfftw3 -lm -llapack # FFTW and lapack libraries needed +LDLIBS = # Name of program OUT = qdyn @@ -16,7 +15,7 @@ OUT = qdyn OBJS = vars.o fparser.o fftw.o utils.o exactfactor.o init.o propag.o qdyn.o myprogram: $(OBJS) - $(FC) -o $(OUT) ${LIBS} ${FFLAGS} $(OBJS) ${LDLIBS} + $(FC) -o $(OUT) ${FFLAGS} $(OBJS) ${LIBS} ${LDLIBS} clean: /bin/rm -f *.o *.mod $(OUT) diff --git a/tests/EF_LaserPulse_OH_1D/check_ef.py b/tests/EF_LaserPulse_OH_1D/check_ef.py index ce0ed8b..c6bbb8b 100644 --- a/tests/EF_LaserPulse_OH_1D/check_ef.py +++ b/tests/EF_LaserPulse_OH_1D/check_ef.py @@ -26,8 +26,8 @@ # calculate maximum difference in the files (including x axis which shouldn't change) max_difference = max(abs(data - ref)) - # compare max difference to threshold - if max_difference > 1e-10: + # compare max difference to threshold (set based on difference produced by my Mac and GitHub Actions) + if max_difference > 5e-8: result = False output.write(f"Mismatch found in '{data_file}'! (max difference: {max_difference:.2e})\n") diff --git a/tests/RT_LaserPulse_CH3I_1D/check_ch3i.py b/tests/RT_LaserPulse_CH3I_1D/check_ch3i.py index b349f06..9ead1ed 100644 --- a/tests/RT_LaserPulse_CH3I_1D/check_ch3i.py +++ b/tests/RT_LaserPulse_CH3I_1D/check_ch3i.py @@ -1,13 +1,12 @@ from os.path import exists -import matplotlib.pyplot as plt from numpy import genfromtxt, linspace, interp, std, trapz, sqrt, array, reshape, shape xngrid = 256 # reading calculated data wf = genfromtxt('wf1d_ad.1.dat') -nframes_wf = int(shape(wf)[0]/xngrid) +nframes_wf = int(shape(wf)[0] / xngrid) wf = reshape(wf, (nframes_wf, xngrid, 5)).transpose((0, 2, 1)) energy = genfromtxt('energies.dat').T t = energy[0] @@ -33,12 +32,12 @@ # calculating mean and x = [[], [], []] for i in range(0, nframes_wf, 10): - x[0].append(t[i]*0.02418884254) + x[0].append(t[i] * 0.02418884254) dx = wf[i][0][1] - wf[i][0][1] norm = trapz(wf[i][3], wf[i][0], dx=dx) - aver_x = trapz(wf[i][3]*wf[i][0], wf[i][0], dx=dx)/norm + aver_x = trapz(wf[i][3] * wf[i][0], wf[i][0], dx=dx) / norm x[1].append(aver_x) - aver_dx = sqrt(trapz(wf[i][3]*wf[i][0]**2, wf[i][0], dx=dx)/norm - aver_x**2) + aver_dx = sqrt(trapz(wf[i][3] * wf[i][0] ** 2, wf[i][0], dx=dx) / norm - aver_x ** 2) x[2].append(aver_dx) x = array(x)