Skip to content

Commit

Permalink
Merge branch 'main' into python_error_checking
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Aug 7, 2024
2 parents c960085 + 42f5079 commit e64744c
Show file tree
Hide file tree
Showing 37 changed files with 2,871 additions and 355 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Publish Python Package

on:
workflow_dispatch:
release:
types:
- published

jobs:
build_sdist:
name: Build SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Build SDist
run: pipx run build --sdist

- name: Check metadata
run: pipx run twine check dist/*

- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: dist/*.tar.gz

build_wheels:
name: Build wheels on ${{ matrix.os }} with Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: arm64 x86_64
CIBW_SKIP: cp27-* cp34-* cp35-* cp36-* *musllinux*
CIBW_BUILD: cp37-* cp38-* cp39-* cp310-* cp311-* cp312-*

- name: Verify clean directory
run: git diff --exit-code
shell: bash

- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-py${{ matrix.python-version }}
path: wheelhouse/*.whl

upload_all:
name: Upload release
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/musica
permissions:
id-token: write

steps:
- uses: actions/setup-python@v5
with:
python-version: "3.x"

- uses: actions/download-artifact@v4
with:
pattern: cibw-*
path: dist
merge-multiple: true

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
1 change: 0 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ RUN dnf -y update \
gfortran \
gdb \
git \
lapack-devel \
lcov \
make \
netcdf-fortran-devel \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.fortran-gcc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ RUN dnf -y update \
git \
hdf5-devel \
json-devel \
lapack-devel \
lcov \
libcurl-devel \
m4 \
Expand All @@ -38,6 +37,7 @@ RUN cd musica \
&& cmake -S . \
-B build \
-D CMAKE_BUILD_TYPE=${BUILD_TYPE} \
-D MUSICA_GIT_TAG=${MUSICA_GIT_TAG} \
-D MUSICA_BUILD_FORTRAN_INTERFACE=ON \
-D MUSICA_ENABLE_MEMCHECK=ON \
&& cd build \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.fortran-gcc.integration
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN dnf -y update \
git \
hdf5-devel \
json-devel \
lapack-devel \
lcov \
libcurl-devel \
m4 \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.memcheck
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ RUN dnf -y update \
gfortran \
gdb \
git \
lapack-devel \
lcov \
make \
netcdf-fortran-devel \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.mpi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ RUN sudo dnf -y install \
gcc-c++ \
gfortran \
git \
lapack-devel \
lcov \
make \
netcdf-fortran-devel \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.mpi_openmp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ RUN sudo dnf -y install \
gcc-c++ \
gfortran \
git \
lapack-devel \
lcov \
make \
netcdf-fortran-devel \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.openmp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ RUN sudo dnf -y install \
gcc-c++ \
gfortran \
git \
lapack-devel \
lcov \
make \
netcdf-fortran-devel \
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.python
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ RUN dnf -y update \
gcc-fortran \
gdb \
git \
lapack-devel \
make \
netcdf-fortran-devel \
pip \
Expand Down
2 changes: 1 addition & 1 deletion fortran/test/fetch_content_integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ if (MUSICA_ENABLE_TUVX)
copy_tuvx_data_dir ALL ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/../../../build/_deps/tuvx-src/data ${CMAKE_BINARY_DIR}/data
)
endif()
endif()
173 changes: 161 additions & 12 deletions fortran/test/fetch_content_integration/test_tuvx_api.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
!
program combined_tuvx_tests
use iso_c_binding
use musica_tuvx, only: tuvx_t, grid_map_t, grid_t, profile_map_t, profile_t
use musica_tuvx, only: tuvx_t, grid_map_t, grid_t, profile_map_t, profile_t, &
radiator_map_t, radiator_t
use musica_util, only: assert, error_t

implicit none
Expand Down Expand Up @@ -55,22 +56,36 @@ end subroutine test_tuvx_api_invalid_config

subroutine test_tuvx_solve()

type(tuvx_t), pointer :: tuvx
type(error_t) :: error
type(grid_map_t), pointer :: grids
character(len=256) :: config_path
type(grid_t), pointer :: grid
type(profile_map_t), pointer :: profiles
type(profile_t), pointer :: profile, profile_copy
real*8, dimension(5), target :: edges, edge_values, temp_edge
real*8, dimension(4), target :: midpoints, midpoint_values, layer_densities, temp_midpoint
real*8 :: temp_real
type(tuvx_t), pointer :: tuvx
type(error_t) :: error
character(len=256) :: config_path
type(grid_map_t), pointer :: grids
type(grid_t), pointer :: grid, height_grid, wavelength_grid
type(profile_map_t), pointer :: profiles
type(profile_t), pointer :: profile, profile_copy
type(radiator_map_t), pointer :: radiators
type(radiator_t), pointer :: radiator, radiator_copy
real*8, dimension(5), target :: edges, edge_values, temp_edge
real*8, dimension(4), target :: midpoints, midpoint_values, layer_densities, temp_midpoint
real*8 :: temp_real
integer :: num_vertical_layers, num_wavelength_bins
real*8, dimension(3,2), target :: optical_depths, temp_od
real*8, dimension(3,2), target :: single_scattering_albedos, temp_ssa
real*8, dimension(3,2,1), target :: asymmetry_factors, temp_asym

edges = (/ 1.0, 2.0, 3.0, 4.0, 5.0 /)
midpoints = (/ 15.0, 25.0, 35.0, 45.0 /)
edge_values = (/ 10.0, 20.0, 30.0, 40.0, 50.0 /)
midpoint_values = (/ 15.0, 25.0, 35.0, 45.0 /)
layer_densities = (/ 2.0, 4.0, 1.0, 7.0 /)
num_vertical_layers = 3
num_wavelength_bins = 2
optical_depths(:,1) = (/ 30.0, 20.0, 10.0 /)
optical_depths(:,2) = (/ 70.0, 80.0, 90.0 /)
single_scattering_albedos(:,1) = (/ 300.0, 200.0, 100.0 /)
single_scattering_albedos(:,2) = (/ 700.0, 800.0, 900.0 /)
asymmetry_factors(:,1,1) = (/ 3.0, 2.0, 1.0 /)
asymmetry_factors(:,2,1) = (/ 7.0, 8.0, 9.0 /)

config_path = "examples/ts1_tsmlt.json"

Expand Down Expand Up @@ -312,12 +327,146 @@ subroutine test_tuvx_solve()
ASSERT_EQ( temp_edge(3), 36.0 )
ASSERT_EQ( temp_edge(4), 38.0 )
ASSERT_EQ( temp_edge(5), 40.0 )


radiators => tuvx%get_radiators( error )
ASSERT( error%is_success() )

radiator => radiators%get( "foo_radiator", error )
ASSERT( .not. error%is_success() )
deallocate( radiator )
deallocate( radiators )

radiators =>radiator_map_t( error )
ASSERT( error%is_success() )

height_grid => grid_t( "height", "km", num_vertical_layers, error )
wavelength_grid => grid_t( "wavelength", "nm", num_wavelength_bins, error )
radiator => radiator_t( "foo_radiator", height_grid, wavelength_grid, error )
ASSERT( error%is_success() )

call radiator%set_optical_depths( optical_depths, error )
ASSERT( error%is_success() )

call radiator%get_optical_depths( temp_od, error )
ASSERT( error%is_success() )
ASSERT_EQ( temp_od(1,1), 30.0 )
ASSERT_EQ( temp_od(2,1), 20.0 )
ASSERT_EQ( temp_od(3,1), 10.0 )
ASSERT_EQ( temp_od(1,2), 70.0 )
ASSERT_EQ( temp_od(2,2), 80.0 )
ASSERT_EQ( temp_od(3,2), 90.0 )

call radiator%set_single_scattering_albedos( single_scattering_albedos, error )
ASSERT( error%is_success() )

call radiator%get_single_scattering_albedos( temp_ssa, error )
ASSERT( error%is_success() )
ASSERT_EQ( temp_ssa(1,1), 300.0 )
ASSERT_EQ( temp_ssa(2,1), 200.0 )
ASSERT_EQ( temp_ssa(3,1), 100.0 )
ASSERT_EQ( temp_ssa(1,2), 700.0 )
ASSERT_EQ( temp_ssa(2,2), 800.0 )
ASSERT_EQ( temp_ssa(3,2), 900.0 )

call radiator%set_asymmetry_factors( asymmetry_factors, error )
ASSERT( error%is_success() )

call radiator%get_asymmetry_factors( temp_asym, error )
ASSERT( error%is_success() )
ASSERT_EQ( temp_asym(1,1,1), 3.0 )
ASSERT_EQ( temp_asym(2,1,1), 2.0 )
ASSERT_EQ( temp_asym(3,1,1), 1.0 )
ASSERT_EQ( temp_asym(1,2,1), 7.0 )
ASSERT_EQ( temp_asym(2,2,1), 8.0 )
ASSERT_EQ( temp_asym(3,2,1), 9.0 )
!
call radiators%add( radiator, error )
radiator_copy => radiators%get( "foo_radiator", error )

optical_depths(:,:) = 0.0
single_scattering_albedos(:,:) = 0.0
asymmetry_factors(:,:,:) = 0.0

call radiator_copy%get_optical_depths( optical_depths, error )
ASSERT( error%is_success() )
ASSERT_EQ( optical_depths(1,1), 30.0 )
ASSERT_EQ( optical_depths(2,1), 20.0 )
ASSERT_EQ( optical_depths(3,1), 10.0 )
ASSERT_EQ( optical_depths(1,2), 70.0 )
ASSERT_EQ( optical_depths(2,2), 80.0 )
ASSERT_EQ( optical_depths(3,2), 90.0 )

call radiator_copy%get_single_scattering_albedos( single_scattering_albedos, error )
ASSERT( error%is_success() )
ASSERT_EQ( single_scattering_albedos(1,1), 300.0 )
ASSERT_EQ( single_scattering_albedos(2,1), 200.0 )
ASSERT_EQ( single_scattering_albedos(3,1), 100.0 )
ASSERT_EQ( single_scattering_albedos(1,2), 700.0 )
ASSERT_EQ( single_scattering_albedos(2,2), 800.0 )
ASSERT_EQ( single_scattering_albedos(3,2), 900.0 )

call radiator_copy%get_asymmetry_factors( asymmetry_factors, error )
ASSERT( error%is_success() )
ASSERT_EQ( asymmetry_factors(1,1,1), 3.0 )
ASSERT_EQ( asymmetry_factors(2,1,1), 2.0 )
ASSERT_EQ( asymmetry_factors(3,1,1), 1.0 )
ASSERT_EQ( asymmetry_factors(1,2,1), 7.0 )
ASSERT_EQ( asymmetry_factors(2,2,1), 8.0 )
ASSERT_EQ( asymmetry_factors(3,2,1), 9.0 )

optical_depths(:,1) = (/ 90.0, 80.0, 70.0 /)
optical_depths(:,2) = (/ 75.0, 85.0, 95.0 /)
single_scattering_albedos(:,1) = (/ 900.0, 800.0, 700.0 /)
single_scattering_albedos(:,2) = (/ 750.0, 850.0, 950.0 /)
asymmetry_factors(:,1,1) = (/ 9.0, 8.0, 7.0 /)
asymmetry_factors(:,2,1) = (/ 5.0, 4.0, 3.0 /)

call radiator_copy%set_optical_depths( optical_depths, error )
call radiator_copy%set_single_scattering_albedos( single_scattering_albedos, error )
call radiator_copy%set_asymmetry_factors( asymmetry_factors, error )
ASSERT( error%is_success() )

optical_depths(:,:) = 0.0
single_scattering_albedos(:,:) = 0.0
asymmetry_factors(:,:,:) = 0.0

call radiator%get_optical_depths( optical_depths, error )
ASSERT( error%is_success() )
ASSERT_EQ( optical_depths(1,1), 90.0 )
ASSERT_EQ( optical_depths(2,1), 80.0 )
ASSERT_EQ( optical_depths(3,1), 70.0 )
ASSERT_EQ( optical_depths(1,2), 75.0 )
ASSERT_EQ( optical_depths(2,2), 85.0 )
ASSERT_EQ( optical_depths(3,2), 95.0 )

call radiator%get_single_scattering_albedos( single_scattering_albedos, error )
ASSERT( error%is_success() )
ASSERT_EQ( single_scattering_albedos(1,1), 900.0 )
ASSERT_EQ( single_scattering_albedos(2,1), 800.0 )
ASSERT_EQ( single_scattering_albedos(3,1), 700.0 )
ASSERT_EQ( single_scattering_albedos(1,2), 750.0 )
ASSERT_EQ( single_scattering_albedos(2,2), 850.0 )
ASSERT_EQ( single_scattering_albedos(3,2), 950.0 )

call radiator%get_asymmetry_factors( asymmetry_factors, error )
ASSERT( error%is_success() )
ASSERT_EQ( asymmetry_factors(1,1,1), 9.0 )
ASSERT_EQ( asymmetry_factors(2,1,1), 8.0 )
ASSERT_EQ( asymmetry_factors(3,1,1), 7.0 )
ASSERT_EQ( asymmetry_factors(1,2,1), 5.0 )
ASSERT_EQ( asymmetry_factors(2,2,1), 4.0 )
ASSERT_EQ( asymmetry_factors(3,2,1), 3.0 )

deallocate( grid )
deallocate( grids )
deallocate( profile )
deallocate( profile_copy )
deallocate( profiles )
deallocate( radiator_copy )
deallocate( radiator )
deallocate( radiators )
deallocate( height_grid )
deallocate( wavelength_grid )
deallocate( tuvx )

end subroutine test_tuvx_solve
Expand Down
2 changes: 2 additions & 0 deletions fortran/tuvx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ target_sources(musica-fortran
grid_map.F90
profile.F90
profile_map.F90
radiator.F90
radiator_map.F90
tuvx.F90
)
2 changes: 1 addition & 1 deletion fortran/tuvx/grid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ end subroutine get_grid_midpoints_c
procedure :: set_edges
! Get grid edges
procedure :: get_edges
! Set the grid edges and midpoints
! Set the grid midpoints
procedure :: set_midpoints
! Get the grid midpoints
procedure :: get_midpoints
Expand Down
2 changes: 1 addition & 1 deletion fortran/tuvx/profile.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module musica_tuvx_profile
interface
function create_profile_c(profile_name, profile_units, grid, error) &
bind(C, name="CreateProfile")
use iso_c_binding, only: c_ptr, c_char, c_size_t
use iso_c_binding, only: c_ptr, c_char
use musica_util, only: error_t_c
character(len=1, kind=c_char), intent(in) :: profile_name(*)
character(len=1, kind=c_char), intent(in) :: profile_units(*)
Expand Down
Loading

0 comments on commit e64744c

Please sign in to comment.