Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MHKiT v0.8.2 #347

Merged
merged 7 commits into from
Aug 13, 2024
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
56 changes: 56 additions & 0 deletions .github/workflows/generate_notebook_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Dynamically creates a matrix for the GitHub Actions workflow that
runs the notebooks in the examples directory.
"""

import os
import json

# Dictionary to store custom timeouts for each notebook
notebook_timeouts = {
"ADCP_Delft3D_TRTS_example.ipynb": 1200,
"adcp_example.ipynb": 240,
"adv_example.ipynb": 180,
"cdip_example.ipynb": 180,
"Delft3D_example.ipynb": 180,
"directional_waves.ipynb": 180,
"environmental_contours_example.ipynb": 360,
"extreme_response_contour_example.ipynb": 360,
"extreme_response_full_sea_state_example.ipynb": 360,
"extreme_response_MLER_example.ipynb": 360,
"loads_example.ipynb": 180,
"metocean_example.ipynb": 180,
"mooring_example.ipynb": 240,
"PacWave_resource_characterization_example.ipynb": 780,
"power_example.ipynb": 180,
"qc_example.ipynb": 180,
"river_example.ipynb": 180,
"short_term_extremes_example.ipynb": 180,
"SWAN_example.ipynb": 180,
"tidal_example.ipynb": 180,
"tidal_performance_example.ipynb": 180,
"upcrossing_example.ipynb": 180,
"wave_example.ipynb": 180,
"wecsim_example.ipynb": 180,
"WPTO_hindcast_example.ipynb": 180,
"default": 60, # Default timeout for other notebooks
}
notebooks = []
for root, dirs, files in os.walk("examples"):
for file in files:
if file.endswith(".ipynb"):
notebooks.append(os.path.join(root, file))

# Generate the matrix configuration
matrix = {"include": []}
for notebook in notebooks:
timeout = notebook_timeouts.get(
os.path.basename(notebook), notebook_timeouts["default"]
)

matrix["include"].append({"notebook": notebook, "timeout": timeout})


# Print the matrix as a properly formatted JSON string
matrix_json = json.dumps(matrix)
print(f"matrix={matrix_json}")
161 changes: 139 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Py 3.8, 3.9, 3.10, 3.11 | Windows Mac Linux
name: Py 3.10, 3.11 | Windows Mac Linux

on:
push:
Expand All @@ -9,6 +9,7 @@ on:
branches:
- master
- develop

jobs:
set-os:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -52,7 +53,7 @@ jobs:
prepare-nonhindcast-cache:
runs-on: ubuntu-latest
env:
PYTHON_VER: 3.9
PYTHON_VER: 3.11
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -95,7 +96,7 @@ jobs:
needs: [check-changes]
runs-on: ubuntu-latest
env:
PYTHON_VER: 3.9
PYTHON_VER: 3.11
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
steps:
- name: Checkout code
Expand Down Expand Up @@ -137,7 +138,7 @@ jobs:
needs: [check-changes, prepare-wave-hindcast-cache]
runs-on: ubuntu-latest
env:
PYTHON_VER: 3.9
PYTHON_VER: 3.11
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
steps:
- name: Checkout code
Expand Down Expand Up @@ -183,7 +184,7 @@ jobs:
fail-fast: false
matrix:
os: ${{fromJson(needs.set-os.outputs.matrix_os)}}
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']
env:
PYTHON_VER: ${{ matrix.python-version }}

Expand Down Expand Up @@ -234,7 +235,7 @@ jobs:
fail-fast: false
matrix:
os: ${{fromJson(needs.set-os.outputs.matrix_os)}}
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']

steps:
- uses: conda-incubator/setup-miniconda@v3
Expand All @@ -244,21 +245,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install HDF5 (macOS with Python 3.8)
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8'
run: brew install hdf5

- name: Install NetCDF (macOS with Python 3.8)
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8'
run: brew install netcdf

- name: Set environment variables (macOS with Python 3.8)
if: startsWith(runner.os, 'macOS') && matrix.python-version == '3.8'
run: |
echo "HDF5_DIR=$(brew --prefix hdf5)" >> $GITHUB_ENV
echo "NETCDF4_DIR=$(brew --prefix netcdf)" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$(brew --prefix hdf5)/lib/pkgconfig:$(brew --prefix netcdf)/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV

- name: Set up Git repository
uses: actions/checkout@v4

Expand Down Expand Up @@ -305,7 +291,7 @@ jobs:
fail-fast: false
matrix:
os: ${{fromJson(needs.set-os.outputs.matrix_os)}}
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.10', '3.11']

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -359,6 +345,137 @@ jobs:
parallel: true
path-to-lcov: ./coverage.lcov

notebook-matrix:
runs-on: ubuntu-latest
needs:
[
check-changes,
prepare-nonhindcast-cache,
prepare-wave-hindcast-cache,
prepare-wind-hindcast-cache,
]
if: |
always() &&
(
(
needs.prepare-nonhindcast-cache.result == 'success' &&
needs.prepare-wave-hindcast-cache.result == 'skipped' &&
needs.prepare-wind-hindcast-cache.result == 'skipped' &&
needs.check-changes.outputs.should-run-hindcast == 'false'
) ||
(
needs.prepare-nonhindcast-cache.result == 'success' &&
needs.prepare-wave-hindcast-cache.result == 'success' &&
needs.prepare-wind-hindcast-cache.result == 'success' &&
needs.check-changes.outputs.should-run-hindcast == 'true'
)
)
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'

- name: Generate matrix
id: set-matrix
run: |
matrix_json=$(python .github/workflows/generate_notebook_matrix.py)
echo "$matrix_json" >> $GITHUB_OUTPUT

test-notebooks:
needs:
[
notebook-matrix,
check-changes,
prepare-nonhindcast-cache,
prepare-wave-hindcast-cache,
prepare-wind-hindcast-cache,
]
strategy:
matrix: ${{ fromJson(needs.notebook-matrix.outputs.matrix) }}
if: |
always()
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: 'latest'
auto-update-conda: true
python-version: '3.11'
activate-environment: TESTconda
use-only-tar-bz2: true

- name: Install dependencies
shell: bash -l {0}
run: |
conda install numpy cython pip hdf5 libnetcdf cftime netcdf4 --strict-channel-priority
pip install -e . --force-reinstall
python -m pip install --upgrade pip wheel
pip install nbval jupyter
pip install utm folium

- name: Ensure Conda environment is activated
shell: bash -l {0}
run: |
echo "source ~/miniconda3/etc/profile.d/conda.sh" >> ~/.bashrc
echo "conda activate TESTconda" >> ~/.bashrc
source ~/.bashrc

- name: Download non-hindcast data
uses: actions/download-artifact@v4
with:
name: data
path: ~/.cache/mhkit

- name: Download Wave Hindcast data (if available)
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
uses: actions/download-artifact@v4
with:
name: wave-hindcast-data
path: ~/.cache/mhkit/wave-hindcast

- name: Download Wind Hindcast data (if available)
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
uses: actions/download-artifact@v4
with:
name: wind-hindcast-data
path: ~/.cache/mhkit/wind-hindcast

- name: Consolidate hindcast data
if: (needs.check-changes.outputs.should-run-hindcast == 'true')
run: |
mkdir -p ~/.cache/mhkit/hindcast
mv ~/.cache/mhkit/wave-hindcast/hindcast/* ~/.cache/mhkit/hindcast/
mv ~/.cache/mhkit/wind-hindcast/hindcast/* ~/.cache/mhkit/hindcast/
shell: bash

- name: Copy .hscfg file to examples directory
shell: bash -l {0}
run: |
cp .hscfg examples/

- name: Run notebook
shell: bash -l {0}
run: |
if [[ "${{ matrix.notebook }}" == "examples/metocean_example.ipynb" || "${{ matrix.notebook }}" == "examples/WPTO_hindcast_example.ipynb" ]]; then
if [[ "${{ needs.check-changes.outputs.should-run-hindcast }}" == 'true' ]]; then
jupyter nbconvert --to notebook --execute --inplace --ExecutePreprocessor.timeout=${{ matrix.timeout }} "${{ matrix.notebook }}"
else
echo "Skipping ${{ matrix.notebook }}"
fi
else
jupyter nbconvert --to notebook --execute --inplace --ExecutePreprocessor.timeout=${{ matrix.timeout }} "${{ matrix.notebook }}"
fi

coveralls:
name: Indicate completion to coveralls.io
needs:
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
- pandas>=1.0.0
- numpy>=1.21.0, <2.0.0
- scipy<=1.13.1
- matplotlib
- matplotlib>=3.8.0
- requests
- lxml
- scikit-learn
Expand Down
56 changes: 32 additions & 24 deletions examples/SWAN_example.ipynb

Large diffs are not rendered by default.

Loading
Loading