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

Update and test example notebooks #6

Merged
merged 21 commits into from
Jun 22, 2022
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
1 change: 1 addition & 0 deletions .github/workflows/ci-cd-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- name: Formatting and linters
run: |
black --check src scripts tests setup.py --exclude doc/conf.py
black-nb --check notebooks
isort --check-only --quiet src scripts tests setup.py doc/conf.py
flake8 src scripts tests setup.py doc/conf.py

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
mkdir -p bin/magicc/magicc-v7.5.3
wget -O "bin/magicc/magicc-v7.5.3.tar.gz" "${{ secrets.MAGICC_LINK_FROM_MAGICC_DOT_ORG }}"
tar -xf bin/magicc/magicc-v7.5.3.tar.gz -C bin/magicc/magicc-v7.5.3
cp -r bin/magicc/magicc-v7.5.3/run/defaults/* bin/magicc/magicc-v7.5.3/run/
MAGICC_RUN_DIR=bin/magicc/magicc-v7.5.3/run/ python scripts/generate-magicc-sr15-input-files.py
mkdir -p data/magicc-drawnsets
wget -O "data/magicc-drawnsets/magicc-ar6-0fd0f62-f023edb-drawnset.tar.gz" "${{ secrets.MAGICC_PROB_DISTRIBUTION_LINK_FROM_MAGICC_DOT_ORG }}"
Expand Down
68 changes: 55 additions & 13 deletions .github/workflows/wg3.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Exact reproduction of WG3 database
on:
# Uncomment these two lines for debugging, but leave them commented on 'main'
# # Uncomment these two lines for debugging, but leave them commented on 'main'
# pull_request:
# branches: [ main ]
push:
Expand All @@ -24,13 +24,27 @@ jobs:
- name: Install dev dependencies
run: |
pip install --upgrade pip wheel
pip install -e .[tests]
pip install -e .[tests,notebooks]

- name: Test with pytest
- name: Get infiller database
env:
SCENARIO_EXPLORER_USER: ${{ secrets.SCENARIO_EXPLORER_USER }}
SCENARIO_EXPLORER_PASSWORD: ${{ secrets.SCENARIO_EXPLORER_PASSWORD }}
run: pytest tests/nightly/test_wg3_reproduction_ciceroscm.py -m wg3 -r a -vv
INFILLER_DATABASE_NAME: "1652361598937-ar6_emissions_vetted_infillerdatabase_10.5281-zenodo.6390768.csv"
INFILLER_DATABASE_DIR: "data"
INFILLER_HASH: "30fae0530d76cbcb144f134e9ed0051f"
run: |
python -c 'import os.path; from climate_assessment.testing import _get_infiller_download_link, _file_available_or_downloaded; infiller_link = _get_infiller_download_link(os.environ.get("INFILLER_DATABASE_NAME")); _file_available_or_downloaded(os.path.join(os.environ.get("INFILLER_DATABASE_DIR"), os.environ.get("INFILLER_DATABASE_NAME")), os.environ.get("INFILLER_HASH"), infiller_link)'

- name: Test with pytest
# scenario explorer stuff needed here too so we don't skip the run with
# pytest
env:
SCENARIO_EXPLORER_USER: ${{ secrets.SCENARIO_EXPLORER_USER }}
SCENARIO_EXPLORER_PASSWORD: ${{ secrets.SCENARIO_EXPLORER_PASSWORD }}
run: |
pytest notebooks/run-example-ciceroscm.ipynb -r a --nbval-lax --no-cov
pytest tests/nightly/test_wg3_reproduction_ciceroscm.py -m wg3 -r a -vv

fair:
runs-on: ubuntu-latest
Expand All @@ -46,13 +60,27 @@ jobs:
- name: Install dev dependencies
run: |
pip install --upgrade pip wheel
pip install -e .[tests]
pip install -e .[tests,notebooks]

- name: Get infiller database
env:
SCENARIO_EXPLORER_USER: ${{ secrets.SCENARIO_EXPLORER_USER }}
SCENARIO_EXPLORER_PASSWORD: ${{ secrets.SCENARIO_EXPLORER_PASSWORD }}
INFILLER_DATABASE_NAME: "1652361598937-ar6_emissions_vetted_infillerdatabase_10.5281-zenodo.6390768.csv"
INFILLER_DATABASE_DIR: "data"
INFILLER_HASH: "30fae0530d76cbcb144f134e9ed0051f"
run:
python -c 'import os.path; from climate_assessment.testing import _get_infiller_download_link, _file_available_or_downloaded; infiller_link = _get_infiller_download_link(os.environ.get("INFILLER_DATABASE_NAME")); _file_available_or_downloaded(os.path.join(os.environ.get("INFILLER_DATABASE_DIR"), os.environ.get("INFILLER_DATABASE_NAME")), os.environ.get("INFILLER_HASH"), infiller_link)'

- name: Test with pytest
- name: Test with pytest
# scenario explorer stuff needed here too so we don't skip the run with
# pytest
env:
SCENARIO_EXPLORER_USER: ${{ secrets.SCENARIO_EXPLORER_USER }}
SCENARIO_EXPLORER_PASSWORD: ${{ secrets.SCENARIO_EXPLORER_PASSWORD }}
run: pytest tests/nightly/test_wg3_reproduction_fair.py -m wg3 -r a -vv
run: |
pytest notebooks/run-example-fair.ipynb -r a --nbval-lax --no-cov
pytest tests/nightly/test_wg3_reproduction_fair.py -m wg3 -r a -vv

magicc:
runs-on: ubuntu-latest
Expand All @@ -68,7 +96,17 @@ jobs:
- name: Install dev dependencies
run: |
pip install --upgrade pip wheel
pip install -e .[tests]
pip install -e .[tests,notebooks]

- name: Get infiller database
env:
SCENARIO_EXPLORER_USER: ${{ secrets.SCENARIO_EXPLORER_USER }}
SCENARIO_EXPLORER_PASSWORD: ${{ secrets.SCENARIO_EXPLORER_PASSWORD }}
INFILLER_DATABASE_NAME: "1652361598937-ar6_emissions_vetted_infillerdatabase_10.5281-zenodo.6390768.csv"
INFILLER_DATABASE_DIR: "data"
INFILLER_HASH: "30fae0530d76cbcb144f134e9ed0051f"
run:
python -c 'import os.path; from climate_assessment.testing import _get_infiller_download_link, _file_available_or_downloaded; infiller_link = _get_infiller_download_link(os.environ.get("INFILLER_DATABASE_NAME")); _file_available_or_downloaded(os.path.join(os.environ.get("INFILLER_DATABASE_DIR"), os.environ.get("INFILLER_DATABASE_NAME")), os.environ.get("INFILLER_HASH"), infiller_link)'

- name: Download MAGICC
env:
Expand All @@ -77,18 +115,22 @@ jobs:
mkdir -p bin/magicc/magicc-v7.5.3
wget -O "bin/magicc/magicc-v7.5.3.tar.gz" "${{ secrets.MAGICC_LINK_FROM_MAGICC_DOT_ORG }}"
tar -xf bin/magicc/magicc-v7.5.3.tar.gz -C bin/magicc/magicc-v7.5.3
cp -r bin/magicc/magicc-v7.5.3/run/defaults/* bin/magicc/magicc-v7.5.3/run/
MAGICC_RUN_DIR=bin/magicc/magicc-v7.5.3/run/ python scripts/generate-magicc-sr15-input-files.py
mkdir -p data/magicc-drawnsets
wget -O "data/magicc-drawnsets/magicc-ar6-0fd0f62-f023edb-drawnset.tar.gz" "${{ secrets.MAGICC_PROB_DISTRIBUTION_LINK_FROM_MAGICC_DOT_ORG }}"
tar -xf "data/magicc-drawnsets/magicc-ar6-0fd0f62-f023edb-drawnset.tar.gz" -C data/magicc-drawnsets

- name: Test with pytest
# scenario explorer stuff needed here too so we don't skip the run with
# pytest
env:
SCENARIO_EXPLORER_USER: ${{ secrets.SCENARIO_EXPLORER_USER }}
SCENARIO_EXPLORER_PASSWORD: ${{ secrets.SCENARIO_EXPLORER_PASSWORD }}
MAGICC_EXECUTABLE_7: /home/runner/work/climate-assessment/climate-assessment/bin/magicc/magicc-v7.5.3/bin/magicc
MAGICC_LINK_FROM_MAGICC_DOT_ORG: ${{ secrets.MAGICC_LINK_FROM_MAGICC_DOT_ORG }}
MAGICC_PROB_DISTRIBUTION_LINK_FROM_MAGICC_DOT_ORG: ${{ secrets.MAGICC_PROB_DISTRIBUTION_LINK_FROM_MAGICC_DOT_ORG }}
MAGICC_WORKER_NUMBER: 4
MAGICC_WORKER_ROOT_DIR: /tmp
MAGICC_PROBABILISTIC_FILE: data/magicc-drawnsets/0fd0f62-derived-metrics-id-f023edb-drawnset.json
SCENARIO_EXPLORER_USER: ${{ secrets.SCENARIO_EXPLORER_USER }}
SCENARIO_EXPLORER_PASSWORD: ${{ secrets.SCENARIO_EXPLORER_PASSWORD }}
run: pytest tests/nightly/test_wg3_reproduction_magicc.py -m wg3 -r a -vv
run: |
pytest notebooks/run-example-magicc.ipynb -r a --nbval-lax --no-cov
pytest tests/nightly/test_wg3_reproduction_magicc.py -m wg3 -r a -vv
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*1652361598937-ar6_emissions_vetted_infillerdatabase_10.5281-zenodo.6390768.csv
tests/test-data/fair-1.6.2-wg3-params*.json
tests/test-data/rcmip-emissions-annual-means-v5-1-0.csv
magicc-files

scripts/*cluster*
20211003*
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ master
Added
~~~~~

- (`#6 <https://github.com/iiasa/climate-assessment/pull/6>`_) Added example run notebooks and tests thereof
- (`#1 <https://github.com/iiasa/climate-assessment/pull/1>`_) Added :func:`climate_assessment.cli.run_workflow`

v0.1.0 - 2022-06-08
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
VENV_DIR ?= ./venv
DATA_DIR ?= ./data
SCRIPTS_DIR ?= ./scripts
NOTEBOOKS_DIR ?= ./notebooks

FILES_TO_FORMAT_PYTHON=scripts src tests setup.py doc/conf.py

Expand Down Expand Up @@ -40,6 +41,15 @@ checks: $(VENV_DIR) ## run all the checks
echo "\n\n=== flake8 ==="; $(VENV_DIR)/bin/flake8 $(FILES_TO_FORMAT_PYTHON) || echo "--- flake8 failed ---" >&2; \
echo

.PHONY: format-notebooks
format-notebooks: $(VENV_DIR) ## format the notebooks
@status=$$(git status --porcelain $(NOTEBOOKS_DIR)); \
if test ${FORCE} || test "x$${status}" = x; then \
$(VENV_DIR)/bin/black-nb $(NOTEBOOKS_DIR); \
else \
echo Not trying any formatting. Working directory is dirty ... >&2; \
fi;

.PHONY: format
format: ## re-format files
make isort
Expand Down
Loading