diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 0558cab..6ce1e4c 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -9,10 +9,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python 3.12 + - name: Set up Python uses: actions/setup-python@v5 with: - python-version: '3.12' + python-version: '3.x' - name: Install dependencies if: always() @@ -27,17 +27,17 @@ jobs: if: always() run: ruff check $(git ls-files *.py) - test: + test-python: needs: code_quality runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Python 3.12 + - name: Set up Python uses: actions/setup-python@v3 with: - python-version: '3.12' + python-version: '3.x' - name: Install dependencies if: always() diff --git a/.github/workflows/test_suite_ubuntu.yml b/.github/workflows/test_suite_ubuntu.yml new file mode 100644 index 0000000..4672864 --- /dev/null +++ b/.github/workflows/test_suite_ubuntu.yml @@ -0,0 +1,65 @@ +# Workflow to run CAM-ML test suite +name: TestSuiteUbuntu + +# Controls when the workflow will run +on: + # Triggers the workflow on pushes to the "main" branch, i.e., PR merges + push: + branches: [ "main" ] + + # Triggers the workflow on pushes to open pull requests with code changes + pull_request: + paths: + - '.github/workflows/test_suite_ubuntu.yml' + - '**.f90' + - '**.F90' + - '**CMakeLists.txt' + - '**requirements.txt' + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Cancel jobs running if new commits are pushed +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +# Workflow run - one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "test-suite-ubuntu" + test-suite-ubuntu: + # The type of runner that the job will run on + runs-on: ubuntu-latest + strategy: + fail-fast: false + + # These steps represent sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - name: Checkout code + with: + persist-credentials: false + uses: actions/checkout@v4 + + # Install dependencies + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y libhdf5-dev libnetcdf-dev libnetcdff-dev + + # Build the code with cmake + - name: Build test suite + run: | + cd tests/ + mkdir build + cd build + cmake .. + cmake --build . + + # Run the test suites + - name: Test suite + run: | + cd tests/build + ./test_CAM_interface + # This YOG convection test will be addressed in a separate issue + # ./test_YOG_convection \ No newline at end of file diff --git a/YOG_convection/resources/SAM_sounding.nc b/YOG_convection/resources/SAM_sounding.nc new file mode 100644 index 0000000..bec6832 Binary files /dev/null and b/YOG_convection/resources/SAM_sounding.nc differ diff --git a/YOG_convection/resources/requirements.txt b/YOG_convection/resources/requirements.txt index 229333d..3058dff 100644 --- a/YOG_convection/resources/requirements.txt +++ b/YOG_convection/resources/requirements.txt @@ -1,4 +1,4 @@ -certifi==2023.7.22 -cftime==1.6.2 -netCDF4==1.6.4 -numpy==1.21.6 +certifi +cftime +netCDF4 +numpy diff --git a/requirements.txt b/requirements.txt index 657bcd6..031e504 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ torch netcdf4 -ruff +ruff==0.9.1 pytest diff --git a/tests/test_utils.F90 b/tests/test_utils.F90 index 926f861..ef08dd3 100644 --- a/tests/test_utils.F90 +++ b/tests/test_utils.F90 @@ -30,6 +30,7 @@ subroutine print_assert_sp(test_name, is_close, relative_error) write(*, '(A, " :: [", A, "] maximum relative error = ", E11.4)') pass, trim(test_name), relative_error else write(*, '(A, " :: [", A, "] maximum relative error = ", E11.4)') fail, trim(test_name), relative_error + stop 999 end if end subroutine print_assert_sp @@ -44,6 +45,7 @@ subroutine print_assert_dp(test_name, is_close, relative_error) write(*, '(A, " :: [", A, "] maximum relative error = ", E11.4)') pass, trim(test_name), relative_error else write(*, '(A, " :: [", A, "] maximum relative error = ", E11.4)') fail, trim(test_name), relative_error + stop 999 end if end subroutine print_assert_dp @@ -58,6 +60,7 @@ subroutine print_assert_int(test_name, match, abs_error) write(*, '(A, " :: [", A, "] maximum absolute error = ", I8)') pass, trim(test_name), abs_error else write(*, '(A, " :: [", A, "] maximum absolute error = ", I8)') fail, trim(test_name), abs_error + stop 999 end if end subroutine print_assert_int diff --git a/torch_nets/models.py b/torch_nets/models.py index 67bfaf4..2636303 100755 --- a/torch_nets/models.py +++ b/torch_nets/models.py @@ -181,8 +181,8 @@ def load_from_netcdf_params(nc_file: str, dtype: str = "float32") -> ANN: for i, layer in enumerate( lyr for lyr in model.modules() if isinstance(lyr, nn.Linear) ): - layer.weight.data = torch.tensor(data_set[f"w{i+1}"][:].astype(dtype)) - layer.bias.data = torch.tensor(data_set[f"b{i+1}"][:].astype(dtype)) + layer.weight.data = torch.tensor(data_set[f"w{i + 1}"][:].astype(dtype)) + layer.bias.data = torch.tensor(data_set[f"b{i + 1}"][:].astype(dtype)) return model