Skip to content
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
83 changes: 83 additions & 0 deletions .github/scripts/set_test_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bash

# Configure CI test environment variables for Clawpack workflows.
# Usage:
# source .github/scripts/set_test_env.sh regression <compiler> <build>

set -euo pipefail

test_group="${1:-}"
compiler="${2:-}"
build="${3:-}"

if [[ -z "${test_group}" || -z "${compiler}" || -z "${build}" ]]; then
echo "Usage: source .github/scripts/set_test_env.sh <test_group> <compiler> <build>"
return 1 2>/dev/null || exit 1
fi

case "${test_group}" in
regression|slow)
case "${compiler}" in
gcc)
case "${build}" in
debug)
export FFLAGS="-O0 -g -fcheck=all -fbacktrace -fbounds-check -ffpe-trap=invalid,zero,overflow -finit-real=nan -finit-integer=nan -Wall -Wunderflow -Wextra -Wconversion -Wuninitialized -Warray-bounds -Wshadow -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-unused-label -Wno-unused-but-set-variable"
export OMP_NUM_THREADS=1
;;
opt)
export FFLAGS="-O1 -fopenmp -funroll-loops -finline-functions -ftree-vectorize -fstack-protector-strong -flto -march=native"
export OMP_NUM_THREADS=2
;;
*)
echo "Unknown build type: ${build}"
return 1 2>/dev/null || exit 1
;;
esac
;;
intel|intel-classic)
case "${build}" in
debug)
export FFLAGS="-O0 -debug all -check all -warn all,nodec,interfaces -gen_interfaces -traceback -fpe0 -ftrapuv -init=snan,arrays -check bounds"
export OMP_NUM_THREADS=1
;;
opt)
export FFLAGS="-O -qopenmp -unroll -finline-functions -inline-forceinline -ipo -ip"
export OMP_NUM_THREADS=2
;;
*)
echo "Unknown build type: ${build}"
return 1 2>/dev/null || exit 1
;;
esac
;;
lfortran)
case "${build}" in
debug)
export FFLAGS=""
export OMP_NUM_THREADS=1
;;
opt)
export FFLAGS="--fast --openmp"
export OMP_NUM_THREADS=2
;;
*)
echo "Unknown build type: ${build}"
return 1 2>/dev/null || exit 1
;;
esac
;;
nvidia-hpc|flang)
echo "${compiler} compiler not yet supported"
return 1 2>/dev/null || exit 1
;;
*)
echo "Unknown compiler: ${compiler}"
return 1 2>/dev/null || exit 1
;;
esac
;;
*)
echo "Unknown test group: ${test_group}"
return 1 2>/dev/null || exit 1
;;
esac
115 changes: 87 additions & 28 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Test Classic
name: Test Classic Clawpack

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]
workflow_dispatch:

permissions:
contents: read
Expand All @@ -13,43 +14,101 @@ env:
CLAW: ${{ github.workspace }}

jobs:
build:
python-lint:
name: >
python-lint - ubuntu-latest - py ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.12', '3.13']

steps:
- name: Set up Python 3.10
uses: actions/setup-python@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6.2.0
with:
python-version: "3.10"
- name: Install dependencies
python-version: ${{ matrix.python-version }}

- name: Install python dependencies
run: |
sudo apt-get update
sudo apt-get install gfortran
python -m pip install --upgrade pip
pip install flake8 meson-python ninja pytest numpy
pip install flake8

- name: Checkout clawpack
uses: actions/checkout@v4.1.5
with:
repository: clawpack/clawpack
submodules: true
- name: Checkout classic branch
uses: actions/checkout@v4.1.5
with:
repository: clawpack/classic
path: classic
- name: Install clawpack
run: |
pip install --no-build-isolation --editable $CLAW
# pip install --user -e $CLAW
- name: Checkout Classic branch
uses: actions/checkout@v6.0.2

- name: Lint with flake8
run: |
cd ${CLAW}/classic
cd ${CLAW}
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest

regression-tests:
name: >
regression - ${{ matrix.os }} - ${{ matrix.toolchain.compiler }} ${{ matrix.build }} - py ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
build: [debug, opt]
python-version: ['3.12']
toolchain:
- {compiler: gcc, version: 14}
- {compiler: gcc, version: 15}
exclude:
- os: ubuntu-latest
toolchain: {compiler: gcc, version: 15}
- os: macos-latest
toolchain: {compiler: gcc, version: 14}

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6.2.0
with:
python-version: ${{ matrix.python-version }}

- name: Set up compilers
uses: fortran-lang/setup-fortran@v1.9.0
id: setup-fortran
with:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}

- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 meson-python ninja pytest numpy

- name: Checkout Clawpack
uses: actions/checkout@v6.0.2
with:
repository: clawpack/clawpack
submodules: true

- name: Checkout Classic branch
uses: actions/checkout@v6.0.2
with:
path: classic

- name: Install clawpack python
run: |
pip install --no-build-isolation --editable .

- name: Run regression tests
run: |
cd ${CLAW}/classic
pytest
source .github/scripts/set_test_env.sh regression "${{ matrix.toolchain.compiler }}" "${{ matrix.build }}"
echo "FFLAGS: $FFLAGS"
echo "OMP_NUM_THREADS: $OMP_NUM_THREADS"
pytest --basetemp=${CLAW}/classic/pytest_tmp -vv -s -o addopts="" -m "regression"

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v7
with:
name: test_results_${{ matrix.os }}_${{ matrix.toolchain.compiler }}_${{ matrix.build }}
path: ${{ env.CLAW }}/classic/pytest_tmp
if-no-files-found: ignore
2 changes: 2 additions & 0 deletions examples/acoustics_1d_example1/regression_data/frame0001.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1.253314136595804307e+01
-6.266570676735773837e+00
2 changes: 2 additions & 0 deletions examples/acoustics_1d_example1/regression_data/frame0002.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1.018560194718946428e-33
-5.092800973594732139e-34
29 changes: 29 additions & 0 deletions examples/acoustics_1d_example1/test_acoustics_1d_example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python

from pathlib import Path
import pytest

import clawpack.classic.test as test


def test_acoustics_1d_example1(tmp_path: Path, save: bool):
runner = test.ClassicTestRunner(tmp_path,
test_path=Path(__file__).parent)

runner.set_data()

runner.rundata.clawdata.num_output_times = 2
runner.rundata.clawdata.tfinal = 1.0
runner.rundata.clawdata.output_t0 = False

runner.write_data()

runner.executable_name = "xclaw"
runner.build_executable()
runner.run_code()

runner.check_frame(1, indices=(0, 1), save=save)
runner.check_frame(2, indices=(0, 1), save=save)

if __name__=="__main__":
raise SystemExit(pytest.main([__file__]))
1 change: 0 additions & 1 deletion examples/acoustics_1d_heterogeneous/setrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

"""

from __future__ import absolute_import
import os
import numpy as np

Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,37 @@
#!/usr/bin/env python
"""
Regression tests for a 1D heterogeneous acoustics test
"""

from __future__ import absolute_import
import sys
import unittest

from pathlib import Path
import pytest
import clawpack.classic.test as test

@pytest.mark.regression
def test_acoustics_1d_heterogeneous(tmp_path: Path, save: bool):
# Create an example-local runner. tmp_path keeps all generated files and
# solver output out of the source tree.
runner = test.ClassicTestRunner(tmp_path, test_path=Path(__file__).parent)

class Acoustics1DHeterogeneousTest(test.ClassicRegressionTest):
r"""Basic test for an 1D heterogeneous acoustics test case"""

def runTest(self, save=False):

# Write out data files
self.load_rundata()

# Modify data for test run
self.rundata.clawdata.num_output_times = 2
self.rundata.clawdata.tfinal = 5.0
self.rundata.clawdata.output_t0 = False
self.write_rundata_objects()

# Run code
self.run_code()

# Perform tests
self.check_frame(indices=[0, 1], save=save, frame_num=1,
file_name='regression_data_test2.txt')
self.check_frame(indices=[0, 1], save=save, frame_num=2,
file_name='regression_data_test3.txt')
# Load the default example configuration from setrun.py and make the run
# smaller/faster for regression testing.
runner.set_data()
runner.rundata.clawdata.num_output_times = 2
runner.rundata.clawdata.tfinal = 5.0
runner.rundata.clawdata.output_t0 = False

# Write the input data files into the temporary run directory.
runner.write_data()

self.success = True
# Build using the example Makefile, then move the executable into tmp_path.
runner.build_executable()

# Run the code with both input files and output files in tmp_path.
runner.run_code()

# Compare selected output frames against saved regression baselines.
runner.check_frame(1, indices=(0, 1), save=save)
runner.check_frame(2, indices=(0, 1), save=save)

if __name__=="__main__":
if len(sys.argv) > 1:
if bool(sys.argv[1]):
# Fake the setup and save out output
test = Acoustics1DHeterogeneousTest()
try:
test.setUp()
test.runTest(save=True)
finally:
test.tearDown()
sys.exit(0)
unittest.main()
raise SystemExit(pytest.main([__file__]))
Loading
Loading