From 6ea1206299410a0f2640b9d662aa717c1ca8b71e Mon Sep 17 00:00:00 2001 From: Jack Atkinson Date: Wed, 18 Sep 2024 10:51:49 +0100 Subject: [PATCH 01/10] Restructure to place tests for NN_module in a separate test/ subdirectory and move to a CMake build process to generate them. --- NN_module/README.md | 19 +++++-- NN_module/test/CMakeLists.txt | 39 ++++++++++++++ NN_module/test/cmake/FindNetCDF.cmake | 78 +++++++++++++++++++++++++++ NN_module/{ => test}/nn_ones.txt | 0 NN_module/{ => test}/param_test.txt | 0 NN_module/{ => test}/test.f90 | 11 ++-- NN_module/{ => test}/test_utils.f90 | 0 7 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 NN_module/test/CMakeLists.txt create mode 100644 NN_module/test/cmake/FindNetCDF.cmake rename NN_module/{ => test}/nn_ones.txt (100%) rename NN_module/{ => test}/param_test.txt (100%) rename NN_module/{ => test}/test.f90 (94%) rename NN_module/{ => test}/test_utils.f90 (100%) diff --git a/NN_module/README.md b/NN_module/README.md index 1c5791f..95acca0 100644 --- a/NN_module/README.md +++ b/NN_module/README.md @@ -28,9 +28,20 @@ deactivate ## Running tests -To run the tests (requires `ifort` or `gfortran` compiler and and `netcdf` and -`netcdf-fortran` libraries) edit `Makefile` to select the appropriate compiler -(`ifort` or `gfortran`), set flags, and select files, and then build with: +There are some tests for the NN_module code in the test/ subdirectory. +These require `ifort` or `gfortran` Fortran compiler, `netcdf` and +`netcdf-fortran` libraries, and CMake. + +They can be built and run with CMake using the following commands: +``` +cd test +mkdir build +cd build +cmake .. +cmake --build . +``` +This will create an executable `yogtest` in the test subdirectory which can be run to execute the tests using: ``` -make +./yogtest ``` +with output printed to the console. diff --git a/NN_module/test/CMakeLists.txt b/NN_module/test/CMakeLists.txt new file mode 100644 index 0000000..c8d13b9 --- /dev/null +++ b/NN_module/test/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) +#policy CMP0076 - target_sources source files are relative to file where target_sources is run +cmake_policy (SET CMP0076 NEW) + +set(PROJECT_NAME YOGTest) + +project(${PROJECT_NAME} LANGUAGES Fortran) + +if(NOT CMAKE_Fortran_FLAGS) + set(CMAKE_Fortran_FLAGS "-g -ffree-line-length-none") +endif() + +# Find the NetCDF installations and set the relevant variables for compilation +# Then link to executables +# Requires more legwork as NetCDF not provided by default +find_package(PkgConfig) +pkg_search_module(NETCDF_FORTRAN netcdf-fortran) +if (NETCDF_FORTRAN_FOUND) + set(NETCDF_LIBRARIES "${NETCDF_FORTRAN_LDFLAGS}") + set(NETCDF_INCLUDES "${NETCDF_FORTRAN_INCLUDE_DIRS}") +else() + set(NETCDF_F90 "YES") + find_package(NetCDF REQUIRED) +endif() +pkg_search_module(NETCDF_C netcdf) +if (NETCDF_C_FOUND) + list(APPEND NETCDF_LIBRARIES "${NETCDF_C_LDFLAGS}") + list(APPEND NETCDF_INCLUDES "${NETCDF_C_INCLUDE_DIRS}") +endif() + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../) + +# Generate the main executable +add_executable ( yogtest + test.f90 ../precision.f90 test_utils.f90 ../SAM_consts.f90 ../nn_cf_net.f90 ../nn_convection_flux.f90 +) + +target_link_libraries( yogtest PRIVATE ${NETCDF_LIBRARIES} ) +target_include_directories( yogtest PRIVATE ${NETCDF_INCLUDES} ) diff --git a/NN_module/test/cmake/FindNetCDF.cmake b/NN_module/test/cmake/FindNetCDF.cmake new file mode 100644 index 0000000..d1082d6 --- /dev/null +++ b/NN_module/test/cmake/FindNetCDF.cmake @@ -0,0 +1,78 @@ +# - Find NetCDF +# Find the native NetCDF includes and library +# +# NETCDF_INCLUDES - where to find netcdf.h, etc +# NETCDF_LIBRARIES - Link these libraries when using NetCDF +# NETCDF_FOUND - True if NetCDF found including required interfaces (see below) +# +# Your package can require certain interfaces to be FOUND by setting these +# +# NETCDF_CXX - require the C++ interface and link the C++ library +# NETCDF_F77 - require the F77 interface and link the fortran library +# NETCDF_F90 - require the F90 interface and link the fortran library +# +# The following are not for general use and are included in +# NETCDF_LIBRARIES if the corresponding option above is set. +# +# NETCDF_LIBRARIES_C - Just the C interface +# NETCDF_LIBRARIES_CXX - C++ interface, if available +# NETCDF_LIBRARIES_F77 - Fortran 77 interface, if available +# NETCDF_LIBRARIES_F90 - Fortran 90 interface, if available +# +# Normal usage would be: +# set (NETCDF_F90 "YES") +# find_package (NetCDF REQUIRED) +# target_link_libraries (uses_f90_interface ${NETCDF_LIBRARIES}) +# target_link_libraries (only_uses_c_interface ${NETCDF_LIBRARIES_C}) + +if (NETCDF_INCLUDES AND NETCDF_LIBRARIES) + # Already in cache, be silent + set (NETCDF_FIND_QUIETLY TRUE) +endif (NETCDF_INCLUDES AND NETCDF_LIBRARIES) + +#set(CMAKE_FIND_DEBUG_MODE TRUE) +find_path (NETCDF_INCLUDES netcdf.h netcdf.mod netcdf.inc + HINTS NETCDF_DIR ENV NETCDF_DIR ENV CPATH ENV FPATH) +#set(CMAKE_FIND_DEBUG_MODE FALSE) +message (STATUS "so far NETCDF_INCLUDES: ${NETCDF_INCLUDES}") + + +find_library (NETCDF_LIBRARIES_C NAMES netcdf netcdff + HINTS ENV LD_LIBRARY_PATH LIBRARY_PATH) +mark_as_advanced(NETCDF_LIBRARIES_C) +message (STATUS "so far NETCDF_LIBRARIES_C: ${NETCDF_LIBRARIES_C}") + + +set (NetCDF_has_interfaces "YES") # will be set to NO if we're missing any interfaces +set (NetCDF_libs "${NETCDF_LIBRARIES_C}") + +get_filename_component (NetCDF_lib_dirs "${NETCDF_LIBRARIES_C}" PATH) + +macro (NetCDF_check_interface lang header libs) + if (NETCDF_${lang}) + find_path (NETCDF_INCLUDES_${lang} NAMES ${header} + HINTS "${NETCDF_INCLUDES}" NO_DEFAULT_PATH) + find_library (NETCDF_LIBRARIES_${lang} NAMES ${libs} + HINTS "${NetCDF_lib_dirs}" NO_DEFAULT_PATH) + mark_as_advanced (NETCDF_INCLUDES_${lang} NETCDF_LIBRARIES_${lang}) + if (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang}) + list (INSERT NetCDF_libs 0 ${NETCDF_LIBRARIES_${lang}}) # prepend so that -lnetcdf is last + else (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang}) + set (NetCDF_has_interfaces "NO") + message (STATUS "Failed to find NetCDF interface for ${lang}") + endif (NETCDF_INCLUDES_${lang} AND NETCDF_LIBRARIES_${lang}) + endif (NETCDF_${lang}) +endmacro (NetCDF_check_interface) + +NetCDF_check_interface (CXX netcdfcpp.h netcdf_c++) +NetCDF_check_interface (F77 netcdf.inc netcdff) +NetCDF_check_interface (F90 netcdf.mod netcdff) + +set (NETCDF_LIBRARIES "${NetCDF_libs}" CACHE STRING "All NetCDF libraries required for interface level") + +# handle the QUIETLY and REQUIRED arguments and set NETCDF_FOUND to TRUE if +# all listed variables are TRUE +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args (NetCDF DEFAULT_MSG NETCDF_LIBRARIES NETCDF_INCLUDES NetCDF_has_interfaces) + +mark_as_advanced (NETCDF_LIBRARIES NETCDF_INCLUDES) diff --git a/NN_module/nn_ones.txt b/NN_module/test/nn_ones.txt similarity index 100% rename from NN_module/nn_ones.txt rename to NN_module/test/nn_ones.txt diff --git a/NN_module/param_test.txt b/NN_module/test/param_test.txt similarity index 100% rename from NN_module/param_test.txt rename to NN_module/test/param_test.txt diff --git a/NN_module/test.f90 b/NN_module/test/test.f90 similarity index 94% rename from NN_module/test.f90 rename to NN_module/test/test.f90 index 67780fb..19c9480 100644 --- a/NN_module/test.f90 +++ b/NN_module/test/test.f90 @@ -41,7 +41,7 @@ subroutine test_nn_cf_init(test_name) character(len=1024) :: nn_filename integer :: nin, nout - nn_filename = "./NN_weights_YOG_convection.nc" + nn_filename = "../NN_weights_YOG_convection.nc" call nn_cf_net_init(nn_filename, nin, nout, nrf) @@ -71,7 +71,7 @@ subroutine test_nn(test_name) nn_in = 1.0 - nn_filename = "./NN_weights_YOG_convection.nc" + nn_filename = "../NN_weights_YOG_convection.nc" call nn_cf_net_init(nn_filename, nin, nout, nrf) call net_forward(nn_in, nn_out) @@ -113,17 +113,14 @@ subroutine test_param(test_name) real(dp) :: t_rad_rest_tend_dat(1,nrf) real(dp) :: prec_sed_dat(1) - nn_filename = "./NN_weights_YOG_convection.nc" + nn_filename = "../NN_weights_YOG_convection.nc" call nn_convection_flux_init(nn_filename) call nn_convection_flux(tabs_i, q_i, y_in, & tabs, & t_0, q_0, & rho, adz, dz, dtn, & - t_rad_rest_tend, & - t_delta_adv, q_delta_adv, & - t_delta_auto, q_delta_auto, & - t_delta_sed, q_delta_sed, prec_sed) + prec_sed) call nn_convection_flux_finalize() diff --git a/NN_module/test_utils.f90 b/NN_module/test/test_utils.f90 similarity index 100% rename from NN_module/test_utils.f90 rename to NN_module/test/test_utils.f90 From 2b3adf3a668ed67ded0773bc27a04d98230235e9 Mon Sep 17 00:00:00 2001 From: Jack Atkinson Date: Wed, 18 Sep 2024 11:00:55 +0100 Subject: [PATCH 02/10] Remove SAM interface as deprecated and no longer pursued. If we ever return to this we can recover it from git history. --- NN_module/Makefile | 2 +- NN_module/README.md | 1 - NN_module/nn_interface_SAM.f90 | 202 --------------------------------- 3 files changed, 1 insertion(+), 204 deletions(-) delete mode 100644 NN_module/nn_interface_SAM.f90 diff --git a/NN_module/Makefile b/NN_module/Makefile index 2c20b42..5a29d80 100644 --- a/NN_module/Makefile +++ b/NN_module/Makefile @@ -25,7 +25,7 @@ LDFLAGS = $(shell nf-config --flibs) $(shell nc-config --libs) # BASE TESTS #PROGRAM = test -#SRC = precision.f90 test_utils.f90 SAM_consts.f90 nn_cf_net.f90 nn_convection_flux.f90 nn_interface_SAM.f90 test.f90 +#SRC = precision.f90 test_utils.f90 SAM_consts.f90 nn_cf_net.f90 nn_convection_flux.f90 test.f90 # CAM INTERFACE TESTS PROGRAM = test_cam diff --git a/NN_module/README.md b/NN_module/README.md index 95acca0..56169dc 100644 --- a/NN_module/README.md +++ b/NN_module/README.md @@ -10,7 +10,6 @@ Files: - `nn_cf_net.f90` - The core neural net routines - `nn_convection_flux.f90` - wrapper around the neural net routines to perform physics-based operations -- `nn_interface_SAM.f90` - wrapper around the parameterisation routines to interface with the SAM model - `test.f90` - simple smoke tests for parameterisation routines - `NN_weights_YOG_convection.nc` - NetCDF file with weights for the neural net - Makefile - Makefile to compile these files diff --git a/NN_module/nn_interface_SAM.f90 b/NN_module/nn_interface_SAM.f90 deleted file mode 100644 index 329e90b..0000000 --- a/NN_module/nn_interface_SAM.f90 +++ /dev/null @@ -1,202 +0,0 @@ -module nn_interface_SAM - !! Interface to convection parameterisation for the SAM model - !! Reference: https://doi.org/10.1029/2020GL091363 - !! Also see YOG20: https://doi.org/10.1038/s41467-020-17142-3 - -!--------------------------------------------------------------------- -! Libraries to use -use nn_convection_flux_mod, only: nn_convection_flux, & - nn_convection_flux_init, nn_convection_flux_finalize -implicit none -private - - -!--------------------------------------------------------------------- -! public interfaces -public nn_convection_flux_SAM, & - nn_convection_flux_SAM_init, nn_convection_flux_SAM_finalize - - -!--------------------------------------------------------------------- -! local/private data - -integer :: it, jt - !! indices corresponding to the start of the grid domain for - !! current MPI rank - -! Copied from nn_convection_flux.f90 -! Outputs from NN are supplied at lowest 30 half-model levels -integer, parameter :: nrf = 30 - !! number of vertical levels the NN parameterisation uses - -!--------------------------------------------------------------------- -! Functions and Subroutines - -contains - - !----------------------------------------------------------------- - ! Public Subroutines - - subroutine nn_convection_flux_SAM_init(nn_filename, rank, nx, ny, nsubdomains_x) - !! Initialise the NN module - - character(len=1024), intent(in) :: nn_filename - !! NetCDF filename from which to read model weights - - integer, intent(in) :: rank - !! rank of the current subdomain task (default 0) - - integer, intent(in) :: nx, ny, nsubdomains_x - !! information about the grid and subdomains - - ! Get indices for grid section on this MPI rank - call task_rank_to_index(rank,it,jt,nx,ny,nsubdomains_x) - - ! Initialise the Neural Net from file and get info - call nn_convection_flux_init(nn_filename) - - end subroutine nn_convection_flux_SAM_init - - - subroutine nn_convection_flux_SAM(tabs_i, q_i, & - tabs, & - rho, adz, & - dz, dtn, dy, & - nx, ny, ny_gl, & - nstep, nstatis, icycle, YES3D, & - t, q, precsfc, prec_xy) - !! Interface to the nn_convection parameterisation for the SAM model - - integer :: j, k - - real, dimension(:,:,:) :: tabs_i, q_i, tabs, t, q - real, dimension(:, :) :: precsfc, prec_xy - real, dimension(:) :: rho, adz - != unit m :: dz - real, intent(in) :: dz - !! grid spacing in z direction for the lowest grid layer - real, intent(in) :: dtn - real, intent(in) :: dy - integer, intent(in) :: nx, ny, ny_gl, nstep, nstatis, icycle, YES3D - - real :: y_in(nx, ny) - !! Distance of column from equator (proxy for insolation and sfc albedo) - - real, dimension(nx, nrf) :: t_rad_rest_tend, t_delta_adv, q_delta_adv, & - t_delta_auto, t_delta_sed, & - q_delta_auto, q_delta_sed - !! deltas/tendencies returned by the parameterisation: - !! radiation rest tendency, advective, autoconversion, sedimentation - - real, dimension(nx) :: prec_sed - !! Sedimenting precipitation at surface - - ! Initialise precipitation to 0 if required and at start of cycle - if(mod(nstep-1,nstatis).eq.0 .and. icycle.eq.1) then - precsfc(:,:)=0. - end if - - ! temperature - Note that this variable is called t_i in the main SAM code!!! - ! tabs_i(i,j,1:input_ver_dim) - - ! non-precipitating water mixing ratio - ! if (rf_uses_rh) then - ! ! If using generalised relative humidity convert non-precip. water content to rel. hum - ! do k=1,nzm - ! omn = omegan(tabs(i,j,k)) - ! qsat(k) = omn * qsatw(tabs(i,j,k),pres(k)) + (1.-omn) * qsati(tabs(i,j,k),pres(k)) - ! end do - ! ! non-precipitating water from mixing ratio - ! real(q_i(i,j,1:input_ver_dim)/qsat(1:input_ver_dim),4) - ! else - ! - ! ! non-precipitating water - ! q_i(i,j,1:input_ver_dim) - ! end if - - ! distance to the equator - ! y is a proxy for insolation and surface albedo as both are only a function of |y| in SAM - do j=1, ny - y_in(:,j) = real(abs(dy*(j+jt-(ny_gl+YES3D-1)/2-0.5))) - enddo - - !----------------------------------------------------- - ! Run the neural net parameterisation - call nn_convection_flux(reshape(tabs_i(:,:,1:nrf), [nx*ny, nrf]), & - reshape(q_i(:,:,1:nrf), [nx*ny, nrf]), & - reshape(y_in, [nx*ny]), & - reshape(tabs(:,:,1:nrf), [nx*ny, nrf]), & - reshape(t(:,:,1:nrf), [nx*ny, nrf]), reshape(q(:,:,1:nrf), [nx*ny, nrf]), & - rho, adz, dz, dtn, & - t_rad_rest_tend, & - t_delta_adv, q_delta_adv, & - t_delta_auto, q_delta_auto, & - t_delta_sed, q_delta_sed, & - prec_sed) - - !----------------------------------------------------- - ! Update q and t with delta values - ! advective, autoconversion (dt = -dq*(latent_heat/cp)), - ! sedimentation (dt = -dq*(latent_heat/cp)), - ! radiation rest tendency (multiply by dtn to get dt) - q(:,:,1:nrf) = q(:,:,1:nrf) + reshape(q_delta_adv(:,:), [nx, ny, nrf]) & - + reshape(q_delta_auto(:,:), [nx, ny, nrf]) & - + reshape(q_delta_sed(:,:), [nx, ny, nrf]) - t(:,:,1:nrf) = t(:,:,1:nrf) + reshape(t_delta_adv(:,:), [nx, ny, nrf]) & - + reshape(t_delta_auto(:,:), [nx, ny, nrf]) & - + reshape(t_delta_sed(:,:), [nx, ny, nrf]) & - + reshape(t_rad_rest_tend(:,:), [nx, ny, nrf])*dtn - - !----------------------------------------------------- - ! Calculate surface precipitation - - ! Apply sedimentation at surface - precsfc(:,:) = precsfc(:,:) + reshape(prec_sed(:), [nx, ny]) ! For statistics - prec_xy(:,:) = prec_xy(:,:) + reshape(prec_sed(:), [nx, ny]) ! For 2D output - - ! Apply all autoconversion in the column and multiply by rho*adz for - ! precip (rho*dq*adz) i.e. all precip. falls out on large model timescale - do k=1, nrf - precsfc(:,:) = precsfc(:,:) - reshape(q_delta_auto(:,k), [nx, ny])*adz(k)*rho(k) - prec_xy(:,:) = prec_xy(:,:) - reshape(q_delta_auto(:,k), [nx, ny])*adz(k)*rho(k) - end do - - ! As a final check enforce q must be >= 0.0 (should be redundant) - where (q(:,:,1:nrf) .lt. 0) - q = 0.0 - end where - - end subroutine nn_convection_flux_SAM - - - subroutine nn_convection_flux_SAM_finalize() - !! Finalize the module deallocating arrays - - call nn_convection_flux_finalize() - - end subroutine nn_convection_flux_SAM_finalize - - - !----------------------------------------------------------------- - ! Private Subroutines - - subroutine task_rank_to_index (rank, i, j, nx, ny, nsubdomains_x) - !! returns the pair of beginning indices for the subdomain on the - !! global grid given the subdomain's rank. - - integer, intent(in) :: rank - !! rank of MPI process - integer, intent(in) :: nx, ny, nsubdomains_x - !! information about the grid and subdomains - integer :: i, j - !! indices at which subdomain starts - - j = rank/nsubdomains_x - i = rank - j*nsubdomains_x - - i = i * (nx) - j = j * (ny) - - end subroutine task_rank_to_index - -end module nn_interface_SAM From 2e9fe1a98eddb8f1a652e000285fa6b07eed274c Mon Sep 17 00:00:00 2001 From: Jack Atkinson Date: Wed, 18 Sep 2024 11:10:04 +0100 Subject: [PATCH 03/10] Move CAM interface code OUT of NN_odule and IN to the CAM interface directorygit status --- {NN_module => CAM_interface}/nn_interface_CAM.f90 | 0 {NN_module => CAM_interface}/test_cam_interface.f90 | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {NN_module => CAM_interface}/nn_interface_CAM.f90 (100%) rename {NN_module => CAM_interface}/test_cam_interface.f90 (100%) diff --git a/NN_module/nn_interface_CAM.f90 b/CAM_interface/nn_interface_CAM.f90 similarity index 100% rename from NN_module/nn_interface_CAM.f90 rename to CAM_interface/nn_interface_CAM.f90 diff --git a/NN_module/test_cam_interface.f90 b/CAM_interface/test_cam_interface.f90 similarity index 100% rename from NN_module/test_cam_interface.f90 rename to CAM_interface/test_cam_interface.f90 From 44bcd1ff7d2f564edc6905d6556e57ecea2b7837 Mon Sep 17 00:00:00 2001 From: Jack Atkinson Date: Wed, 18 Sep 2024 11:59:28 +0100 Subject: [PATCH 04/10] Move tests from local to a global test directory, and modify to have shared test utils and CMakeLists to build all. --- {NN_module/test => tests}/CMakeLists.txt | 23 +++++++++++++++---- .../test => tests}/cmake/FindNetCDF.cmake | 0 .../test => tests/test_NN_module}/nn_ones.txt | 0 .../test_NN_module}/param_test.txt | 0 .../test => tests/test_NN_module}/test.f90 | 10 ++++---- {NN_module/test => tests}/test_utils.f90 | 0 6 files changed, 23 insertions(+), 10 deletions(-) rename {NN_module/test => tests}/CMakeLists.txt (63%) rename {NN_module/test => tests}/cmake/FindNetCDF.cmake (100%) rename {NN_module/test => tests/test_NN_module}/nn_ones.txt (100%) rename {NN_module/test => tests/test_NN_module}/param_test.txt (100%) rename {NN_module/test => tests/test_NN_module}/test.f90 (95%) rename {NN_module/test => tests}/test_utils.f90 (100%) diff --git a/NN_module/test/CMakeLists.txt b/tests/CMakeLists.txt similarity index 63% rename from NN_module/test/CMakeLists.txt rename to tests/CMakeLists.txt index c8d13b9..65158c6 100644 --- a/NN_module/test/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,6 +10,14 @@ if(NOT CMAKE_Fortran_FLAGS) set(CMAKE_Fortran_FLAGS "-g -ffree-line-length-none") endif() + +set(NN_Module_DIR "../NN_module/") + + + +#Add cmake directory to the environment module variable +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + # Find the NetCDF installations and set the relevant variables for compilation # Then link to executables # Requires more legwork as NetCDF not provided by default @@ -28,12 +36,17 @@ if (NETCDF_C_FOUND) list(APPEND NETCDF_INCLUDES "${NETCDF_C_INCLUDE_DIRS}") endif() -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../) +# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../) # Generate the main executable -add_executable ( yogtest - test.f90 ../precision.f90 test_utils.f90 ../SAM_consts.f90 ../nn_cf_net.f90 ../nn_convection_flux.f90 +add_executable ( test_NN_module + test_NN_module/test.f90 + test_utils.f90 + ${NN_Module_DIR}/precision.f90 + ${NN_Module_DIR}/SAM_consts.f90 + ${NN_Module_DIR}/nn_cf_net.f90 + ${NN_Module_DIR}/nn_convection_flux.f90 ) -target_link_libraries( yogtest PRIVATE ${NETCDF_LIBRARIES} ) -target_include_directories( yogtest PRIVATE ${NETCDF_INCLUDES} ) +target_link_libraries( test_NN_module PRIVATE ${NETCDF_LIBRARIES} ) +target_include_directories( test_NN_module PRIVATE ${NETCDF_INCLUDES} ) diff --git a/NN_module/test/cmake/FindNetCDF.cmake b/tests/cmake/FindNetCDF.cmake similarity index 100% rename from NN_module/test/cmake/FindNetCDF.cmake rename to tests/cmake/FindNetCDF.cmake diff --git a/NN_module/test/nn_ones.txt b/tests/test_NN_module/nn_ones.txt similarity index 100% rename from NN_module/test/nn_ones.txt rename to tests/test_NN_module/nn_ones.txt diff --git a/NN_module/test/param_test.txt b/tests/test_NN_module/param_test.txt similarity index 100% rename from NN_module/test/param_test.txt rename to tests/test_NN_module/param_test.txt diff --git a/NN_module/test/test.f90 b/tests/test_NN_module/test.f90 similarity index 95% rename from NN_module/test/test.f90 rename to tests/test_NN_module/test.f90 index 19c9480..82b27d7 100644 --- a/NN_module/test/test.f90 +++ b/tests/test_NN_module/test.f90 @@ -41,7 +41,7 @@ subroutine test_nn_cf_init(test_name) character(len=1024) :: nn_filename integer :: nin, nout - nn_filename = "../NN_weights_YOG_convection.nc" + nn_filename = "../../NN_module/NN_weights_YOG_convection.nc" call nn_cf_net_init(nn_filename, nin, nout, nrf) @@ -71,7 +71,7 @@ subroutine test_nn(test_name) nn_in = 1.0 - nn_filename = "../NN_weights_YOG_convection.nc" + nn_filename = "../../NN_module/NN_weights_YOG_convection.nc" call nn_cf_net_init(nn_filename, nin, nout, nrf) call net_forward(nn_in, nn_out) @@ -113,7 +113,7 @@ subroutine test_param(test_name) real(dp) :: t_rad_rest_tend_dat(1,nrf) real(dp) :: prec_sed_dat(1) - nn_filename = "../NN_weights_YOG_convection.nc" + nn_filename = "../../NN_module/NN_weights_YOG_convection.nc" call nn_convection_flux_init(nn_filename) call nn_convection_flux(tabs_i, q_i, y_in, & @@ -124,7 +124,7 @@ subroutine test_param(test_name) call nn_convection_flux_finalize() - nn_filename = "param_test.txt" + nn_filename = "../test_NN_module/param_test.txt" ! Writing data out to file from original code runniing ! open(newunit=io, file=trim(nn_filename), status="replace", action="write", & @@ -204,7 +204,7 @@ program run_tests call test_relu("test_relu") call test_nn_cf_init("test_nn_cf_init") - call load_nn_out_ones("nn_ones.txt") + call load_nn_out_ones("../test_NN_module/nn_ones.txt") call test_nn("Test NN ones") call test_param("Test param simple") diff --git a/NN_module/test/test_utils.f90 b/tests/test_utils.f90 similarity index 100% rename from NN_module/test/test_utils.f90 rename to tests/test_utils.f90 From 27d0a7d0f1e2ba51c3fa5806a8bda40048a9c87e Mon Sep 17 00:00:00 2001 From: Jack Atkinson Date: Wed, 18 Sep 2024 12:11:54 +0100 Subject: [PATCH 05/10] Move CAM interface tests to the testing directory and incorporate into the CMake tests build process. --- tests/CMakeLists.txt | 15 +++++++++++++++ .../test_CAM_interface}/test_cam_interface.f90 | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) rename {CAM_interface => tests/test_CAM_interface}/test_cam_interface.f90 (98%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 65158c6..f005f02 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,6 +12,7 @@ endif() set(NN_Module_DIR "../NN_module/") +set(CAM_Interface_DIR "../CAM_interface/") @@ -50,3 +51,17 @@ add_executable ( test_NN_module target_link_libraries( test_NN_module PRIVATE ${NETCDF_LIBRARIES} ) target_include_directories( test_NN_module PRIVATE ${NETCDF_INCLUDES} ) + +# Generate the main executable +add_executable ( test_CAM_interface + test_CAM_interface/test_cam_interface.f90 + test_utils.f90 + ${NN_Module_DIR}/precision.f90 + ${NN_Module_DIR}/SAM_consts.f90 + ${NN_Module_DIR}/nn_cf_net.f90 + ${NN_Module_DIR}/nn_convection_flux.f90 + ${CAM_Interface_DIR}/nn_interface_CAM.f90 +) + +target_link_libraries( test_CAM_interface PRIVATE ${NETCDF_LIBRARIES} ) +target_include_directories( test_CAM_interface PRIVATE ${NETCDF_INCLUDES} ) diff --git a/CAM_interface/test_cam_interface.f90 b/tests/test_CAM_interface/test_cam_interface.f90 similarity index 98% rename from CAM_interface/test_cam_interface.f90 rename to tests/test_CAM_interface/test_cam_interface.f90 index c3beb43..ac10627 100644 --- a/CAM_interface/test_cam_interface.f90 +++ b/tests/test_CAM_interface/test_cam_interface.f90 @@ -415,8 +415,8 @@ program run_cam_tests integer, dimension(4) :: aa = [1, 2, 3, 4] integer, dimension(4) :: bb = [1, 2, 3, 4] - character(len=1024) :: nn_file = "NN_weights_YOG_convection.nc" - character(len=1024) :: sounding_file = "resources/SAM_sounding.nc" + character(len=1024) :: nn_file = "../../NN_module/NN_weights_YOG_convection.nc" + character(len=1024) :: sounding_file = "../../NN_module/resources/SAM_sounding.nc" ! Initialise the NN module call nn_convection_flux_CAM_init(nn_file, sounding_file) From fb7b576be245ed8ba57f79e76e7d4fda77aef73b Mon Sep 17 00:00:00 2001 From: Jack Atkinson Date: Wed, 18 Sep 2024 12:23:21 +0100 Subject: [PATCH 06/10] Update README files with details of new tests and restructured repository. --- CAM_interface/README.md | 7 +++++++ NN_module/README.md | 21 +++------------------ README.md | 32 ++++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/CAM_interface/README.md b/CAM_interface/README.md index 2e3acf0..339d721 100644 --- a/CAM_interface/README.md +++ b/CAM_interface/README.md @@ -17,6 +17,7 @@ require revisions to these files in future. In addition to the files in `[/NN_Module](/NN_Module)` containing the parameterisation, the additional files here are required: +- `nn_interface_CAM.F90` - The interface for performing conversion from CAM variables and grid into the variables/grid expected by the YOG parameterisation. - `yog_intr.F90` - The interface between the CAM model and the YOG parameterisation. Changes also have to be made to: @@ -27,3 +28,9 @@ Changes also have to be made to: - `/src/physics/cam/physpkg.F90` - To call the new parameteristion routines detailed in `yog_intr.F90`. Full details of these can be seen in the specific implementation in CAM linked above. + + +## Tests + +There are test routines associated with this code in `/tests/test_CAM_interface/`. +Guidance on running these can be found in the main README. diff --git a/NN_module/README.md b/NN_module/README.md index 56169dc..2c9326e 100644 --- a/NN_module/README.md +++ b/NN_module/README.md @@ -25,22 +25,7 @@ python sounding_to_netcdf.py deactivate ``` -## Running tests +## Tests -There are some tests for the NN_module code in the test/ subdirectory. -These require `ifort` or `gfortran` Fortran compiler, `netcdf` and -`netcdf-fortran` libraries, and CMake. - -They can be built and run with CMake using the following commands: -``` -cd test -mkdir build -cd build -cmake .. -cmake --build . -``` -This will create an executable `yogtest` in the test subdirectory which can be run to execute the tests using: -``` -./yogtest -``` -with output printed to the console. +There are test routines associated with this code in `/tests/test_NN_module/`. +Guidance on running these can be found in the main README. diff --git a/README.md b/README.md index 16eb783..e7c9674 100644 --- a/README.md +++ b/README.md @@ -31,20 +31,18 @@ Long term developments of this project will seek to re-deploy more complex ML pa │   └── ... ├── torch_nets │ └── ... -└── CAM_interface +├── CAM_interface +│ └── ... +└── tests └── ... -``` - +``` ### Contents ### `NN_module/` This folder contains the fortran neural net extracted from the [code referenced above](https://github.com/yaniyuval/Neural_nework_parameterization/tree/v.1.0.3), along with any dependencies, that may be compiled as a standalone fortran module. -Currently there is code that can be built on CSD3 using the included shell script. -This now needs cleaning up, testing, and a proper makefile creating (see open issues #9 and #10). - ### ``torch_nets/`` The directory contains the PyTorch versions of the neural networks we are interested in. @@ -52,6 +50,28 @@ The directory contains the PyTorch versions of the neural networks we are intere The directory contains the additional files or details to interface the code with the CAM atmospheric model as part of the CESM model suite. It also includes a link to an implementation in a fork of CAM. +### ``tests/`` + +There are some tests for the NN_module and interface code in the test/ +subdirectory. +These require a Fortran compiler, `netcdf` and +`netcdf-fortran` libraries, and CMake to build. + +They can be built and run with CMake using the following commands: +``` +cd tests +mkdir build +cd build +cmake .. +cmake --build . +``` +This will create executables in the `build/` subdirectory which can be +run to execute the tests using: +``` +./test_NN_module +./test_CAM_interface +``` +with output printed to the console. ## Contributing From 664b5dc311274f02c3f013f30f7d7b014d1bb18e Mon Sep 17 00:00:00 2001 From: Jack Atkinson Date: Wed, 18 Sep 2024 12:32:14 +0100 Subject: [PATCH 07/10] Add advice for building only specific tests. --- README.md | 6 ++++++ tests/CMakeLists.txt | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e7c9674..97c84f5 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,12 @@ run to execute the tests using: ``` with output printed to the console. +Note: To build only a specific subset of tests instead of all of them use: +``` +cmake --build . --target +``` + + ## Contributing Contributions to the repository are welcome, particularly from anyone seeking to implement the diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f005f02..c854fa6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,7 +39,7 @@ endif() # set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../) -# Generate the main executable +# Generate the test_NN_module executable add_executable ( test_NN_module test_NN_module/test.f90 test_utils.f90 @@ -52,7 +52,7 @@ add_executable ( test_NN_module target_link_libraries( test_NN_module PRIVATE ${NETCDF_LIBRARIES} ) target_include_directories( test_NN_module PRIVATE ${NETCDF_INCLUDES} ) -# Generate the main executable +# Generate the test_CAM_interface executable add_executable ( test_CAM_interface test_CAM_interface/test_cam_interface.f90 test_utils.f90 From 430751bacf62d903121d97e5655b89681a2673be Mon Sep 17 00:00:00 2001 From: Jack Atkinson Date: Wed, 18 Sep 2024 14:35:59 +0100 Subject: [PATCH 08/10] Remove Makefile as now superseded by CMake. --- NN_module/Makefile | 47 ---------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 NN_module/Makefile diff --git a/NN_module/Makefile b/NN_module/Makefile deleted file mode 100644 index 5a29d80..0000000 --- a/NN_module/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# Set compiler and flags - uncomment for ifort or gfortran as appropriate -# Set free length and include netcdf-fortran -# Try using nc/nf-config tool if available, otherwise need to manually add path as per examples below - -# gfortran configuration -FC = gfortran -FCFLAGS = -g -ffree-line-length-none $(shell nf-config --fflags) $(shell nc-config --cflags) - -# ifort configuration -# FC = ifort -# FCFLAGS = $(shell nf-config --fflags) $(shell nc-config --cflags) - -# link flags -# Link to netcdf and netcdf-fortran -# Try using nc/nf-config tool if available, otherwise manually add path as per examples below -LDFLAGS = $(shell nf-config --flibs) $(shell nc-config --libs) - -# If flags need adding manually this can be done here -# CSD3: -# FCFLAGS = -g -ffree-line-length-none -I/usr/local/software/spack/spack-views/rocky8-icelake-20220710/netcdf-fortran-4.5.4/gcc-11.3.0/intel-oneapi-mpi-2021.6.0/mscqvjsc7bwypshmhnqfc2u3zxnims3r/include -# LDFLAGS = -L/usr/local/software/spack/spack-views/rhel8-icelake-20211027_2/netcdf-fortran-4.5.3/gcc-11.2.0/intel-oneapi-mpi-2021.4.0/g4qjb23rucofcg5uitt4jwrkgyf7gba7/lib -lnetcdff -lnetcdf -lm -# Homebrew local: -# FCFLAGS = -g -ffree-line-length-none -I/opt/homebrew/Cellar/netcdf-fortran/4.6.1/include -I/opt/homebrew/Cellar/netcdf/4.9.2_1/include -# LDFLAGS = -L/opt/homebrew/Cellar/netcdf-fortran/4.6.1/lib -L/opt/homebrew/Cellar/netcdf/4.9.2_1/lib -lnetcdff -lnetcdf - -# BASE TESTS -#PROGRAM = test -#SRC = precision.f90 test_utils.f90 SAM_consts.f90 nn_cf_net.f90 nn_convection_flux.f90 test.f90 - -# CAM INTERFACE TESTS -PROGRAM = test_cam -SRC = precision.f90 test_utils.f90 SAM_consts.f90 nn_cf_net.f90 nn_convection_flux.f90 nn_interface_CAM.f90 test_cam_interface.f90 - -OBJECTS = $(SRC:.f90=.o) - - -all: $(PROGRAM) - -$(PROGRAM): $(OBJECTS) - $(FC) -o $@ $^ $(LDFLAGS) - -%.o: %.f90 - $(FC) $(FCFLAGS) -c $< - -clean: - rm -f *.o *.mod - From d8e8caf51bd3fe7032ccd690665f9970eb4c6ebd Mon Sep 17 00:00:00 2001 From: Jack Atkinson Date: Wed, 18 Sep 2024 17:26:17 +0100 Subject: [PATCH 09/10] Move NN_module to YOG_convection as discussed - a more logical name. --- README.md | 13 +++--- .../NN_weights_YOG_convection.nc | Bin {NN_module => YOG_convection}/README.md | 0 {NN_module => YOG_convection}/SAM_consts.f90 | 0 {NN_module => YOG_convection}/nn_cf_net.f90 | 0 .../nn_convection_flux.f90 | 0 {NN_module => YOG_convection}/precision.f90 | 0 {NN_module => YOG_convection}/resources/grd | 0 .../resources/requirements.txt | 0 .../resources/sounding_to_netcdf.py | 0 .../sounding_z_pres0_presi0_tabs0.txt | 0 .../resources/sounding_z_rho_rhow.txt | 0 tests/CMakeLists.txt | 38 ++++++++---------- .../test_CAM_interface/test_cam_interface.f90 | 4 +- .../nn_ones.txt | 0 .../param_test.txt | 0 .../test.f90 | 10 ++--- 17 files changed, 30 insertions(+), 35 deletions(-) rename {NN_module => YOG_convection}/NN_weights_YOG_convection.nc (100%) rename {NN_module => YOG_convection}/README.md (100%) rename {NN_module => YOG_convection}/SAM_consts.f90 (100%) rename {NN_module => YOG_convection}/nn_cf_net.f90 (100%) rename {NN_module => YOG_convection}/nn_convection_flux.f90 (100%) rename {NN_module => YOG_convection}/precision.f90 (100%) rename {NN_module => YOG_convection}/resources/grd (100%) rename {NN_module => YOG_convection}/resources/requirements.txt (100%) rename {NN_module => YOG_convection}/resources/sounding_to_netcdf.py (100%) rename {NN_module => YOG_convection}/resources/sounding_z_pres0_presi0_tabs0.txt (100%) rename {NN_module => YOG_convection}/resources/sounding_z_rho_rhow.txt (100%) rename tests/{test_NN_module => test_YOG_convection}/nn_ones.txt (100%) rename tests/{test_NN_module => test_YOG_convection}/param_test.txt (100%) rename tests/{test_NN_module => test_YOG_convection}/test.f90 (95%) diff --git a/README.md b/README.md index 97c84f5..3f12950 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Long term developments of this project will seek to re-deploy more complex ML pa ## Repository structure ``` -├── NN_module +├── YOG_convection │   └── ... ├── torch_nets │ └── ... @@ -40,14 +40,15 @@ Long term developments of this project will seek to re-deploy more complex ML pa ### Contents -### `NN_module/` -This folder contains the fortran neural net extracted from the [code referenced above](https://github.com/yaniyuval/Neural_nework_parameterization/tree/v.1.0.3), along with any dependencies, that may be compiled as a standalone fortran module. +### `YOG_convection/` +This directory contains the fortran code for the YOG convection parameterisation, along with any dependencies. +It can be included as a standalone fortran module in a larger model. ### ``torch_nets/`` -The directory contains the PyTorch versions of the neural networks we are interested in. +This directory contains the PyTorch versions of the neural networks used in the YOG convection parameterisation. ### ``CAM_interface/`` -The directory contains the additional files or details to interface the code with the CAM atmospheric model +The directory contains the additional files or details to interface the YOG code with the CAM atmospheric model as part of the CESM model suite. It also includes a link to an implementation in a fork of CAM. ### ``tests/`` @@ -68,7 +69,7 @@ cmake --build . This will create executables in the `build/` subdirectory which can be run to execute the tests using: ``` -./test_NN_module +./test_YOG_convection ./test_CAM_interface ``` with output printed to the console. diff --git a/NN_module/NN_weights_YOG_convection.nc b/YOG_convection/NN_weights_YOG_convection.nc similarity index 100% rename from NN_module/NN_weights_YOG_convection.nc rename to YOG_convection/NN_weights_YOG_convection.nc diff --git a/NN_module/README.md b/YOG_convection/README.md similarity index 100% rename from NN_module/README.md rename to YOG_convection/README.md diff --git a/NN_module/SAM_consts.f90 b/YOG_convection/SAM_consts.f90 similarity index 100% rename from NN_module/SAM_consts.f90 rename to YOG_convection/SAM_consts.f90 diff --git a/NN_module/nn_cf_net.f90 b/YOG_convection/nn_cf_net.f90 similarity index 100% rename from NN_module/nn_cf_net.f90 rename to YOG_convection/nn_cf_net.f90 diff --git a/NN_module/nn_convection_flux.f90 b/YOG_convection/nn_convection_flux.f90 similarity index 100% rename from NN_module/nn_convection_flux.f90 rename to YOG_convection/nn_convection_flux.f90 diff --git a/NN_module/precision.f90 b/YOG_convection/precision.f90 similarity index 100% rename from NN_module/precision.f90 rename to YOG_convection/precision.f90 diff --git a/NN_module/resources/grd b/YOG_convection/resources/grd similarity index 100% rename from NN_module/resources/grd rename to YOG_convection/resources/grd diff --git a/NN_module/resources/requirements.txt b/YOG_convection/resources/requirements.txt similarity index 100% rename from NN_module/resources/requirements.txt rename to YOG_convection/resources/requirements.txt diff --git a/NN_module/resources/sounding_to_netcdf.py b/YOG_convection/resources/sounding_to_netcdf.py similarity index 100% rename from NN_module/resources/sounding_to_netcdf.py rename to YOG_convection/resources/sounding_to_netcdf.py diff --git a/NN_module/resources/sounding_z_pres0_presi0_tabs0.txt b/YOG_convection/resources/sounding_z_pres0_presi0_tabs0.txt similarity index 100% rename from NN_module/resources/sounding_z_pres0_presi0_tabs0.txt rename to YOG_convection/resources/sounding_z_pres0_presi0_tabs0.txt diff --git a/NN_module/resources/sounding_z_rho_rhow.txt b/YOG_convection/resources/sounding_z_rho_rhow.txt similarity index 100% rename from NN_module/resources/sounding_z_rho_rhow.txt rename to YOG_convection/resources/sounding_z_rho_rhow.txt diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c854fa6..6117ff9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,18 +10,16 @@ if(NOT CMAKE_Fortran_FLAGS) set(CMAKE_Fortran_FLAGS "-g -ffree-line-length-none") endif() - -set(NN_Module_DIR "../NN_module/") +# Add variables for commonly used source directories +set(YOG_DIR "../YOG_convection/") set(CAM_Interface_DIR "../CAM_interface/") - - #Add cmake directory to the environment module variable list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") # Find the NetCDF installations and set the relevant variables for compilation # Then link to executables -# Requires more legwork as NetCDF not provided by default +# Requires more legwork as NetCDF not provided by default (see cmake/FindNetCDF.cmake). find_package(PkgConfig) pkg_search_module(NETCDF_FORTRAN netcdf-fortran) if (NETCDF_FORTRAN_FOUND) @@ -37,31 +35,27 @@ if (NETCDF_C_FOUND) list(APPEND NETCDF_INCLUDES "${NETCDF_C_INCLUDE_DIRS}") endif() -# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../) - -# Generate the test_NN_module executable -add_executable ( test_NN_module - test_NN_module/test.f90 +# Generate the test_YOG_convection executable +add_executable ( test_YOG_convection + test_YOG_convection/test.f90 test_utils.f90 - ${NN_Module_DIR}/precision.f90 - ${NN_Module_DIR}/SAM_consts.f90 - ${NN_Module_DIR}/nn_cf_net.f90 - ${NN_Module_DIR}/nn_convection_flux.f90 + ${YOG_DIR}/precision.f90 + ${YOG_DIR}/SAM_consts.f90 + ${YOG_DIR}/nn_cf_net.f90 + ${YOG_DIR}/nn_convection_flux.f90 ) - -target_link_libraries( test_NN_module PRIVATE ${NETCDF_LIBRARIES} ) -target_include_directories( test_NN_module PRIVATE ${NETCDF_INCLUDES} ) +target_link_libraries( test_YOG_convection PRIVATE ${NETCDF_LIBRARIES} ) +target_include_directories( test_YOG_convection PRIVATE ${NETCDF_INCLUDES} ) # Generate the test_CAM_interface executable add_executable ( test_CAM_interface test_CAM_interface/test_cam_interface.f90 test_utils.f90 - ${NN_Module_DIR}/precision.f90 - ${NN_Module_DIR}/SAM_consts.f90 - ${NN_Module_DIR}/nn_cf_net.f90 - ${NN_Module_DIR}/nn_convection_flux.f90 + ${YOG_DIR}/precision.f90 + ${YOG_DIR}/SAM_consts.f90 + ${YOG_DIR}/nn_cf_net.f90 + ${YOG_DIR}/nn_convection_flux.f90 ${CAM_Interface_DIR}/nn_interface_CAM.f90 ) - target_link_libraries( test_CAM_interface PRIVATE ${NETCDF_LIBRARIES} ) target_include_directories( test_CAM_interface PRIVATE ${NETCDF_INCLUDES} ) diff --git a/tests/test_CAM_interface/test_cam_interface.f90 b/tests/test_CAM_interface/test_cam_interface.f90 index ac10627..37986d6 100644 --- a/tests/test_CAM_interface/test_cam_interface.f90 +++ b/tests/test_CAM_interface/test_cam_interface.f90 @@ -415,8 +415,8 @@ program run_cam_tests integer, dimension(4) :: aa = [1, 2, 3, 4] integer, dimension(4) :: bb = [1, 2, 3, 4] - character(len=1024) :: nn_file = "../../NN_module/NN_weights_YOG_convection.nc" - character(len=1024) :: sounding_file = "../../NN_module/resources/SAM_sounding.nc" + character(len=1024) :: nn_file = "../../YOG_convection/NN_weights_YOG_convection.nc" + character(len=1024) :: sounding_file = "../../YOG_convection/resources/SAM_sounding.nc" ! Initialise the NN module call nn_convection_flux_CAM_init(nn_file, sounding_file) diff --git a/tests/test_NN_module/nn_ones.txt b/tests/test_YOG_convection/nn_ones.txt similarity index 100% rename from tests/test_NN_module/nn_ones.txt rename to tests/test_YOG_convection/nn_ones.txt diff --git a/tests/test_NN_module/param_test.txt b/tests/test_YOG_convection/param_test.txt similarity index 100% rename from tests/test_NN_module/param_test.txt rename to tests/test_YOG_convection/param_test.txt diff --git a/tests/test_NN_module/test.f90 b/tests/test_YOG_convection/test.f90 similarity index 95% rename from tests/test_NN_module/test.f90 rename to tests/test_YOG_convection/test.f90 index 82b27d7..2b1de69 100644 --- a/tests/test_NN_module/test.f90 +++ b/tests/test_YOG_convection/test.f90 @@ -41,7 +41,7 @@ subroutine test_nn_cf_init(test_name) character(len=1024) :: nn_filename integer :: nin, nout - nn_filename = "../../NN_module/NN_weights_YOG_convection.nc" + nn_filename = "../../YOG_convection/NN_weights_YOG_convection.nc" call nn_cf_net_init(nn_filename, nin, nout, nrf) @@ -71,7 +71,7 @@ subroutine test_nn(test_name) nn_in = 1.0 - nn_filename = "../../NN_module/NN_weights_YOG_convection.nc" + nn_filename = "../../YOG_convection/NN_weights_YOG_convection.nc" call nn_cf_net_init(nn_filename, nin, nout, nrf) call net_forward(nn_in, nn_out) @@ -113,7 +113,7 @@ subroutine test_param(test_name) real(dp) :: t_rad_rest_tend_dat(1,nrf) real(dp) :: prec_sed_dat(1) - nn_filename = "../../NN_module/NN_weights_YOG_convection.nc" + nn_filename = "../../YOG_convection/NN_weights_YOG_convection.nc" call nn_convection_flux_init(nn_filename) call nn_convection_flux(tabs_i, q_i, y_in, & @@ -124,7 +124,7 @@ subroutine test_param(test_name) call nn_convection_flux_finalize() - nn_filename = "../test_NN_module/param_test.txt" + nn_filename = "../test_YOG_convection/param_test.txt" ! Writing data out to file from original code runniing ! open(newunit=io, file=trim(nn_filename), status="replace", action="write", & @@ -204,7 +204,7 @@ program run_tests call test_relu("test_relu") call test_nn_cf_init("test_nn_cf_init") - call load_nn_out_ones("../test_NN_module/nn_ones.txt") + call load_nn_out_ones("../test_YOG_convection/nn_ones.txt") call test_nn("Test NN ones") call test_param("Test param simple") From bbdab720f138eaa354ceb0c17b56b0e555b12dcb Mon Sep 17 00:00:00 2001 From: Jack Atkinson <109271713+jatkinson1000@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:32:45 +0000 Subject: [PATCH 10/10] Typo: Update formatting of directory README.md Co-authored-by: Marion <56403724+MarionBWeinzierl@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f12950..ff2be69 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ as part of the CESM model suite. It also includes a link to an implementation in ### ``tests/`` -There are some tests for the NN_module and interface code in the test/ +There are some tests for the NN_module and interface code in the `test/` subdirectory. These require a Fortran compiler, `netcdf` and `netcdf-fortran` libraries, and CMake to build.