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

Move dependencies to pyproject toml and create ci/cd install and import test #37

Merged
merged 47 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
93190de
move deps to projects and add import tests
leifdenby May 22, 2024
afd6012
add cicd testing workflow
leifdenby May 22, 2024
4013796
test both with pdm and pip install
leifdenby May 22, 2024
de72b95
clean up test cicd
leifdenby May 22, 2024
4d78c68
remove requirements.txt
leifdenby May 23, 2024
2f6a87a
add GPU-based runner on cirun.io
leifdenby Jun 3, 2024
143cf2a
pdm install with cpu torch
leifdenby Jun 3, 2024
b760915
ensure exec in pdm venv
leifdenby Jun 3, 2024
7797cef
ensure exec in pdm venv
leifdenby Jun 3, 2024
e689650
check version #2
leifdenby Jun 3, 2024
fb8ef23
check version no 3
leifdenby Jun 3, 2024
51b0a0b
check versions
leifdenby Jun 3, 2024
70425ee
fix for pip install
leifdenby Jun 3, 2024
60110f6
switch cirun instance type
leifdenby Jun 3, 2024
6fff3fc
install py39 on cirun runner
leifdenby Jun 3, 2024
8054e9e
change ami image to gpu
leifdenby Jun 4, 2024
39fbf3a
Merge remote-tracking branch 'upstream/main' into maint/deps-in-pypro…
leifdenby Jun 4, 2024
97aeb2e
use cheaper gpu instance
leifdenby Jun 4, 2024
048f8c6
Merge branch 'main' of https://github.com/mllam/neural-lam into maint…
leifdenby Jul 11, 2024
5aaa239
add pooch and tweak pip cicd testing
leifdenby Jul 11, 2024
66c3b03
combine cicd tests with caching
leifdenby Jul 11, 2024
8566b8f
linting
leifdenby Jul 11, 2024
29bd9e5
add pyg dep
leifdenby Jul 11, 2024
bc7f028
set cirun aws region to frankfurt
leifdenby Jul 11, 2024
2070166
adapt image
leifdenby Jul 11, 2024
e4e86e5
set image
leifdenby Jul 11, 2024
1fba8fe
try different image
leifdenby Jul 11, 2024
02b77cf
add pooch to cicd
leifdenby Jul 11, 2024
b481929
add pdm gpu test
leifdenby Jul 16, 2024
bcec472
start work on readme
leifdenby Jul 16, 2024
421efed
use tmate in gpu pdm cicd
Aug 13, 2024
05f1e9f
remove requirements
Aug 13, 2024
3afe0e4
update pdm gpu cicd setup to pdm venv on nvme drive
Aug 13, 2024
f3d028b
don't try to use pdm venv in-project
Aug 13, 2024
2c35662
remove tmate
Aug 13, 2024
5f30255
update README with install instructions
Aug 14, 2024
b2b5631
changelog
Aug 14, 2024
c8ae829
update ci/cd badges to include gpu + gpu
Aug 14, 2024
9f3c014
Merge branch 'maint/refactor-as-package' into datastore
leifdenby Aug 19, 2024
41364a8
Merge branch 'main' of https://github.com/mllam/neural-lam into maint…
leifdenby Aug 19, 2024
3422298
update changelog
leifdenby Aug 19, 2024
689ef69
move dev deps optional dependencies group
leifdenby Aug 20, 2024
9a0d538
update cicd tests to install dev deps
leifdenby Aug 20, 2024
bddfcaf
update readme with new dev deps group
leifdenby Aug 20, 2024
b96cfdc
quote the skip step the install readme
leifdenby Aug 20, 2024
3cd0f8b
pin numpy to <2.0.0
leifdenby Aug 20, 2024
e4210e0
remove numpy <2.0.0 cap and update changelog
leifdenby Aug 20, 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
16 changes: 16 additions & 0 deletions .cirun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# setup for using github runners via https://cirun.io/
runners:
- name: "aws-runner"
# Cloud Provider: AWS
cloud: "aws"
# https://aws.amazon.com/ec2/instance-types/g4/
instance_type: "g4ad.xlarge"
# Deep Learning Base OSS Nvidia Driver GPU AMI (Ubuntu 22.04), Frankfurt region
machine_image: "ami-0ba41b554b28d24a4"
# use Frankfurt region
region: "eu-central-1"
preemptible: false
# Add this label in the "runs-on" param in .github/workflows/<workflow-name>.yml
# So that this runner is created for running the workflow
labels:
- "cirun-aws-runner"
55 changes: 55 additions & 0 deletions .github/workflows/ci-pdm-install-and-test-cpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# cicd workflow for running tests with pytest
# needs to first install pdm, then install torch cpu manually and then install the package
# then run the tests

name: test (pdm install, cpu)

on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install pdm
run: |
python -m pip install pdm

- name: Create venv
run: |
pdm venv create --with-pip
pdm use --venv in-project

- name: Install torch (CPU)
run: |
pdm run python -m pip install torch --index-url https://download.pytorch.org/whl/cpu
# check that the CPU version is installed

- name: Install package (including dev dependencies)
run: |
pdm install --group :all

- name: Print and check torch version
run: |
pdm run python -c "import torch; print(torch.__version__)"
pdm run python -c "import torch; assert torch.__version__.endswith('+cpu')"

- name: Load cache data
uses: actions/cache/restore@v4
with:
path: data
key: ${{ runner.os }}-meps-reduced-example-data-v0.1.0
restore-keys: |
${{ runner.os }}-meps-reduced-example-data-v0.1.0

- name: Run tests
run: |
pdm run pytest

- name: Save cache data
uses: actions/cache/save@v4
with:
path: data
key: ${{ runner.os }}-meps-reduced-example-data-v0.1.0
60 changes: 60 additions & 0 deletions .github/workflows/ci-pdm-install-and-test-gpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# cicd workflow for running tests with pytest
# needs to first install pdm, then install torch cpu manually and then install the package
# then run the tests

name: test (pdm install, gpu)

on: [push, pull_request]

jobs:
tests:
runs-on: "cirun-aws-runner--${{ github.run_id }}"
steps:
- name: Checkout
uses: actions/checkout@v2

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

- name: Install pdm
run: |
python -m pip install pdm

- name: Create venv
run: |
pdm config venv.in_project False
pdm config venv.location /opt/dlami/nvme/venv
pdm venv create --with-pip

- name: Install torch (GPU CUDA 12.1)
run: |
pdm run python -m pip install torch --index-url https://download.pytorch.org/whl/cu121

- name: Print and check torch version
run: |
pdm run python -c "import torch; print(torch.__version__)"
pdm run python -c "import torch; assert not torch.__version__.endswith('+cpu')"

- name: Install package (including dev dependencies)
run: |
pdm install --group :all

- name: Load cache data
uses: actions/cache/restore@v4
with:
path: data
key: ${{ runner.os }}-meps-reduced-example-data-v0.1.0
restore-keys: |
${{ runner.os }}-meps-reduced-example-data-v0.1.0

- name: Run tests
run: |
pdm run pytest

- name: Save cache data
uses: actions/cache/save@v4
with:
path: data
key: ${{ runner.os }}-meps-reduced-example-data-v0.1.0
45 changes: 45 additions & 0 deletions .github/workflows/ci-pip-install-and-test-cpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# cicd workflow for running tests with pytest
# needs to first install pdm, then install torch cpu manually and then install the package
# then run the tests

name: test (pip install, cpu)

on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install torch (CPU)
run: |
python -m pip install torch --index-url https://download.pytorch.org/whl/cpu

- name: Install package (including dev dependencies)
run: |
python -m pip install ".[dev]"

- name: Print and check torch version
run: |
python -c "import torch; print(torch.__version__)"
python -c "import torch; assert torch.__version__.endswith('+cpu')"

- name: Load cache data
uses: actions/cache/restore@v4
with:
path: data
key: ${{ runner.os }}-meps-reduced-example-data-v0.1.0
restore-keys: |
${{ runner.os }}-meps-reduced-example-data-v0.1.0

- name: Run tests
run: |
python -m pytest

- name: Save cache data
uses: actions/cache/save@v4
with:
path: data
key: ${{ runner.os }}-meps-reduced-example-data-v0.1.0
50 changes: 50 additions & 0 deletions .github/workflows/ci-pip-install-and-test-gpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# cicd workflow for running tests with pytest
# needs to first install pdm, then install torch cpu manually and then install the package
# then run the tests

name: test (pip install, gpu)

on: [push, pull_request]

jobs:
tests:
runs-on: "cirun-aws-runner--${{ github.run_id }}"
steps:
- name: Checkout
uses: actions/checkout@v2

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

- name: Install torch (GPU CUDA 12.1)
run: |
python -m pip install torch --index-url https://download.pytorch.org/whl/cu121

- name: Install package (including dev dependencies)
run: |
python -m pip install ".[dev]"

- name: Print and check torch version
run: |
python -c "import torch; print(torch.__version__)"
python -c "import torch; assert not torch.__version__.endswith('+cpu')"

- name: Load cache data
uses: actions/cache/restore@v4
with:
path: data
key: ${{ runner.os }}-meps-reduced-example-data-v0.1.0
restore-keys: |
${{ runner.os }}-meps-reduced-example-data-v0.1.0

- name: Run tests
run: |
python -m pytest

- name: Save cache data
uses: actions/cache/save@v4
with:
path: data
key: ${{ runner.os }}-meps-reduced-example-data-v0.1.0
43 changes: 0 additions & 43 deletions .github/workflows/run_tests.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ tags

# Coc configuration directory
.vim

# pdm (https://pdm-project.org/en/stable/)
.pdm-python
# exclude pdm.lock file so that both cpu and gpu versions of torch will be accepted by pdm
pdm.lock
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- added github pull-request template to ease contribution and review process
[\#53](https://github.com/mllam/neural-lam/pull/53), @leifdenby

- ci/cd setup for running both CPU and GPU-based testing both with pdm and pip based installs [\#37](https://github.com/mllam/neural-lam/pull/37), @khintz, @leifdenby

### Changed

Optional multi-core/GPU support for statistics calculation in `create_parameter_weights.py`
Expand Down Expand Up @@ -88,17 +90,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[\#52](https://github.com/mllam/neural-lam/pull/52)
@joeloskarsson

- Cap numpy version to < 2.0.0
- Cap numpy version to < 2.0.0 (this cap was removed in #37, see below)
[\#68](https://github.com/mllam/neural-lam/pull/68)
@joeloskarsson

- Remove numpy < 2.0.0 version cap
[\#37](https://github.com/mllam/neural-lam/pull/37)
@leifdenby

- turn `neural-lam` into a python package by moving all `*.py`-files into the
`neural_lam/` source directory and updating imports accordingly. This means
all cli functions are now invoke through the package name, e.g. `python -m
neural_lam.train_model` instead of `python train_model.py` (and can be done
anywhere once the package has been installed).
[\#32](https://github.com/mllam/neural-lam/pull/32), @leifdenby

- move from `requirements.txt` to `pyproject.toml` for defining package dependencies.
[\#37](https://github.com/mllam/neural-lam/pull/37), @leifdenby

## [v0.1.0](https://github.com/joeloskarsson/neural-lam/releases/tag/v0.1.0)

First tagged release of `neural-lam`, matching Oskarsson et al 2023 publication
Expand Down
42 changes: 33 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
![Linting](https://github.com/mllam/neural-lam/actions/workflows/pre-commit.yml/badge.svg?branch=main)
![Automatic tests](https://github.com/mllam/neural-lam/actions/workflows/run_tests.yml/badge.svg?branch=main)
[![test (pdm install, gpu)](https://github.com/mllam/neural-lam/actions/workflows/ci-pdm-install-and-test-gpu.yml/badge.svg)](https://github.com/mllam/neural-lam/actions/workflows/ci-pdm-install-and-test-gpu.yml)
[![test (pdm install, cpu)](https://github.com/mllam/neural-lam/actions/workflows/ci-pdm-install-and-test-cpu.yml/badge.svg)](https://github.com/mllam/neural-lam/actions/workflows/ci-pdm-install-and-test-cpu.yml)

<p align="middle">
<img src="figures/neural_lam_header.png" width="700">
Expand Down Expand Up @@ -57,15 +58,38 @@ See the issues https://github.com/joeloskarsson/neural-lam/issues/2, https://git
Below follows instructions on how to use Neural-LAM to train and evaluate models.

## Installation
Follow the steps below to create the necessary python environment.

1. Install GEOS for your system. For example with `sudo apt-get install libgeos-dev`. This is necessary for the Cartopy requirement.
2. Use python 3.9.
3. Install version 2.0.1 of PyTorch. Follow instructions on the [PyTorch webpage](https://pytorch.org/get-started/previous-versions/) for how to set this up with GPU support on your system.
4. Install `neural-lam` with pip:
```
pip install -e .
```
When installing `neural-lam` you have a choice of either installing with
directly `pip` or using the `pdm` package manager.
We recommend using `pdm` as it makes it easy to add/remove packages while
keeping versions consistent (it automatically updates the `pyproject.toml`
file), makes it easy to handle virtual environments and includes the
development toolchain packages installation too.

**regarding `torch` installation**: because `torch` creates different package
variants for different CUDA versions and cpu-only support you will need to install
`torch` separately if you don't want the most recent GPU variant that also
expects the most recent version of CUDA on your system.

We cover all the installation options in our [github actions ci/cd
setup](.github/workflows/) which you can use as a reference.

### Using `pdm`

1. Clone this repository and navigate to the root directory.
2. Install `pdm` if you don't have it installed on your system (either with `pip install pdm` or [following the install instructions](https://pdm-project.org/latest/#installation)).
> If you are happy using the latest version of `torch` with GPU support (expecting the latest version of CUDA is installed on your system) you can skip to step 5.
3. Create a virtual environment for pdm to use with `pdm venv create --with-pip`.
4. Install a specific version of `torch` with `pdm run python -m pip install torch --index-url https://download.pytorch.org/whl/cpu` for a CPU-only version or `pdm run python -m pip install torch --index-url https://download.pytorch.org/whl/cu111` for CUDA 11.1 support (you can find the correct URL for the variant you want on [PyTorch webpage](https://pytorch.org/get-started/locally/)).
5. Install the dependencies with `pdm install` (by default this in include the). If you will be developing `neural-lam` we recommend to install the development dependencies with `pdm install --group dev`. By default `pdm` installs the `neural-lam` package in editable mode, so you can make changes to the code and see the effects immediately.

### Using `pip`

1. Clone this repository and navigate to the root directory.
> If you are happy using the latest version of `torch` with GPU support (expecting the latest version of CUDA is installed on your system) you can skip to step 3.
2. Install a specific version of `torch` with `python -m pip install torch --index-url https://download.pytorch.org/whl/cpu` for a CPU-only version or `python -m pip install torch --index-url https://download.pytorch.org/whl/cu111` for CUDA 11.1 support (you can find the correct URL for the variant you want on [PyTorch webpage](https://pytorch.org/get-started/locally/)).
3. Install the dependencies with `python -m pip install .`. If you will be developing `neural-lam` we recommend to install in editable mode and install the development dependencies with `python -m pip install -e ".[dev]"` so you can make changes to the code and see the effects immediately.


## Data
Datasets should be stored in a directory called `data`.
Expand Down
Loading
Loading