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

ipython notebook test #330

Merged
merged 90 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
3fbb93e
fix formatting in mooring_example.ipynb
akeeste May 14, 2024
b74789e
update links in noaa.py
akeeste May 14, 2024
c612823
fix heading in metocean example
akeeste May 15, 2024
9064e45
clean up module docstrings
akeeste May 15, 2024
afffea8
add notebook and python <3.12 to dependencies
akeeste May 17, 2024
a2b861c
clarify warning in mooring example
akeeste May 17, 2024
b12cedd
update variable naming in hindcast.py
akeeste May 17, 2024
a6d8784
move notebook to a pip install in yaml file
akeeste May 17, 2024
3b83724
re-add pecos index_to_datetime function to mhkit.utils
akeeste May 17, 2024
bd11f44
update np.product to np.prod per the depreciation warning
akeeste May 17, 2024
44459c9
fix type checking in wave.performance capture length and maep matrix
akeeste May 17, 2024
b722e62
ensure data is sorted in tidal_example
akeeste May 17, 2024
71dcd1f
black formatting
akeeste May 17, 2024
63f502a
Fix Notebooks (#4)
ssolson May 21, 2024
34dd1d5
Pacwave Notebook fixes & Tidal Test fixes (#5)
ssolson May 22, 2024
d08a726
fix valueerror in tidal.graphics
akeeste Jun 11, 2024
63a17d8
slight speedup for utils.type_handling
akeeste Jun 11, 2024
8f0ed6b
Merge branch 'doc_fixes' of https://github.com/akeeste/MHKiT-Python i…
akeeste Jun 11, 2024
5d1bfee
revert minor utils type_handling change
akeeste Jun 13, 2024
7c89d7b
revert dataarray conversion in power_performance_workflow
akeeste Jun 13, 2024
f3852b6
fix mooring test
akeeste Jun 13, 2024
55d97de
ipython notebook test
ssolson Jun 14, 2024
5341646
create notebook job
ssolson Jun 14, 2024
8673de3
create dynamic list of notebooks
ssolson Jun 14, 2024
ea932bf
use cache and run notebooks in parallel
ssolson Jun 14, 2024
2993b82
handle hindcast logic in yml
ssolson Jun 14, 2024
bb7b5c9
Merge branch 'doc_fixes' of https://github.com/akeeste/MHKiT-Python i…
ssolson Jun 14, 2024
eaddc60
workflow dispatch
ssolson Jun 17, 2024
651cacb
fix numpy release
ssolson Jun 17, 2024
5a11a8a
numpy 2.0
ssolson Jun 17, 2024
c8665b5
np 2.0: np.float_ => np.float64
ssolson Jun 17, 2024
83d1d98
np.float_ => np.float64
ssolson Jun 17, 2024
8f8c8e6
np.float_ => np.float64
ssolson Jun 17, 2024
040c3b2
numpy <2.0
ssolson Jun 17, 2024
a546114
Merge branch 'develop' of https://github.com/MHKiT-Software/MHKiT-Pyt…
ssolson Jun 18, 2024
958305f
change job needs
ssolson Jun 18, 2024
d31d9c1
less needs
ssolson Jun 18, 2024
0d5839d
fix condition run on cache
ssolson Jun 18, 2024
3295c39
add hindcast back to needs
ssolson Jun 18, 2024
1166c53
add write permission
ssolson Jun 18, 2024
998f4e0
workflow_dispatch
ssolson Jun 18, 2024
fb2b808
run on main workflow completion
ssolson Jun 19, 2024
f7b8da0
use PAT
ssolson Jun 21, 2024
25542e5
workflow_dispatch
ssolson Jun 21, 2024
2beacae
debug CURL
ssolson Jun 21, 2024
070c838
nb test in main
ssolson Jun 25, 2024
db8c207
Remove less than numpy 2 requirement
ssolson Jun 25, 2024
5ebcbc9
fix np.RankWarning
ssolson Jun 25, 2024
5017aaf
np > 2.0.0
ssolson Jun 25, 2024
815c10e
scipy to pip
ssolson Jun 25, 2024
0ee3260
drop support for python 3.9 and 3.8
ssolson Jun 25, 2024
5ba6250
np.exceptions.RankWarning
ssolson Jun 25, 2024
f649f23
cumulative_trapezoid
ssolson Jun 25, 2024
9dc3694
NaN => nan
ssolson Jun 25, 2024
e207a84
Merge branch 'develop' of https://github.com/MHKiT-Software/MHKiT-Pyt…
ssolson Jul 1, 2024
e767c0b
revert np 2.0 update
ssolson Jul 1, 2024
e45bbf8
if always()
ssolson Jul 1, 2024
7f497d6
fix matrix OUTPUT
ssolson Jul 1, 2024
3e0ff69
fix indent
ssolson Jul 1, 2024
16a30de
remove conditional run
ssolson Jul 1, 2024
aedd5fa
remove seperate nb tests
ssolson Jul 1, 2024
07020e4
activate conda env
ssolson Jul 1, 2024
01fb1c1
fix indent
ssolson Jul 1, 2024
c177897
activate conda
ssolson Jul 1, 2024
5549614
fix indent
ssolson Jul 1, 2024
274aac0
add utm package
ssolson Jul 1, 2024
77513ac
skip metocean
ssolson Jul 1, 2024
e268e79
adjust data path for actions testing
ssolson Jul 1, 2024
d9af35f
folium
ssolson Jul 1, 2024
3659770
skip hindcast
ssolson Jul 1, 2024
0f0d397
fix substitution
ssolson Jul 1, 2024
03f61c1
Use full path for nb testing
ssolson Jul 1, 2024
223fe51
debug file path
ssolson Jul 1, 2024
c6eb428
increase timeout for D3D ADCP
ssolson Jul 2, 2024
635b091
.mat to .MAT
ssolson Jul 2, 2024
c5429a8
calc maep_matrix manually
ssolson Jul 3, 2024
62a3a7c
run output
ssolson Jul 3, 2024
24623f7
remove condition from generated matrix
ssolson Jul 3, 2024
fcf1a66
custom timeouts
ssolson Jul 4, 2024
b16bd37
remove if
ssolson Jul 4, 2024
e1a133d
if always
ssolson Jul 4, 2024
d9f3af8
fix string substitution
ssolson Jul 4, 2024
13ce5ae
increase ADCP timeout
ssolson Jul 4, 2024
6ab5196
increase D3D ADCP more
ssolson Jul 4, 2024
6e602ab
remove scipy from pip
ssolson Jul 5, 2024
cd01c92
Merge branch 'develop' of https://github.com/MHKiT-Software/MHKiT-Pyt…
ssolson Jul 5, 2024
61bda0f
revert numpy 2.0 updates
ssolson Jul 5, 2024
a5e695e
revert np 2 updates
ssolson Jul 5, 2024
f203642
run hindcast
ssolson Jul 5, 2024
30f6947
remove condition
ssolson Jul 5, 2024
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": 720,
"extreme_response_contour_example.ipynb": 360,
"extreme_response_full_sea_state_example.ipynb": 420,
"extreme_response_MLER_example.ipynb": 650,
"loads_example.ipynb": 180,
"metocean_example.ipynb": 240,
"mooring_example.ipynb": 300,
"PacWave_resource_characterization_example.ipynb": 780,
"power_example.ipynb": 180,
"qc_example.ipynb": 180,
"river_example.ipynb": 240,
"short_term_extremes_example.ipynb": 180,
"SWAN_example.ipynb": 180,
"tidal_example.ipynb": 240,
"tidal_performance_example.ipynb": 180,
"upcrossing_example.ipynb": 180,
"wave_example.ipynb": 180,
"wecsim_example.ipynb": 180,
"WPTO_hindcast_example.ipynb": 1200,
"default": 300, # 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": []}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the key "include" have to do with how Actions creates a testing matrix from the test variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

The include key is a dummy key/ catch all for Actions because you can only have a single variable json at the top level.
So its called include to include all the keys I want to use.

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}")
127 changes: 105 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 Down Expand Up @@ -52,7 +52,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 +95,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 +137,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 +183,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 +234,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 +244,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 +290,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 +344,104 @@ 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() &&
(
(
Comment on lines +357 to +358
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"always() &&" seems redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, however, I have become accustomed to this syntax in actions and you will find it throughout our tests.

There is discussion here agreeing that you should not need to but that you do:
https://github.com/orgs/community/discussions/25789#discussioncomment-3249273

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of the matrix_json variable here? Isn't matrix the only variable from generate_notebook_matrix.py that is used? Similarly, where is the matrix key "include" being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In bash here we are setting a variable matrix_json
On the next line we echo that variable to send it as std_out via ">>" to the variable matrix.

So the matrix_json variable is used in the echo command


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: 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will "ExecutePreprocessor" fail each notebook test if it hits the timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes each notebook in the repo has a custom timeout specified. It will fail if you go overtime. You can see some of these failures on previous commits such as the commit before "Increase ADCP timeout".

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
56 changes: 32 additions & 24 deletions examples/SWAN_example.ipynb

Large diffs are not rendered by default.

Loading
Loading