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

Adding contribution guide and enable copyright checks as a pre-commit hook #91

Merged
merged 7 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]

copyright-check = True
copyright-author = Graphcore Ltd
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Pre-Commit Checks

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
args: [--select=C]
additional_dependencies: [flake8-copyright]
96 changes: 96 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Contributing to pyscf-ipu

This project is still evolving but at the moment is focused around a high-performance and easily hackable implementation of Gaussian basis set DFT.
We hope this is useful for the generation of large-scale datasets needed
for training machine-learning models. We are interested in hearing any and
all feedback so feel free to raise any questions, bugs encountered, or enhancement requests as [Issues](https://github.com/graphcore-research/pyscf-ipu/issues).

## Setting up a development environment
We recommend using the conda package manager as this can automatically enable
the Graphcore Poplar SDK. This is particularly useful in VS Code which can automatically
activate the conda environment in a variety of scenarios:
* visual debugging
* running quick experiments in an interactive Jupyter window
* using VS code for Jupyter notebook development.

The following assumes that you have already setup an install of conda and that
hatemhelal marked this conversation as resolved.
Show resolved Hide resolved
the conda command is available on your system path. Refer to your preferred conda
installer:
* [miniforge installation](https://github.com/conda-forge/miniforge#install)
* [conda installation documentation](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html).

1. Create a new conda environment with the same python version as you OS.
hatemhelal marked this conversation as resolved.
Show resolved Hide resolved
For example, on ubuntu 20 use `python=3.8.10`
```bash
conda create -n pyscf-ipu python=3.8.10
```

2. Confirm that you have the Poplar SDK installed on your machine and store the location
in an environment variable. The following will test that the SDK is found and
configured correctly:
```bash
export POPLAR_SDK=/path/to/sdk
source $POPLAR_SDK/enable
gc-monitor
```
hatemhelal marked this conversation as resolved.
Show resolved Hide resolved

3. Activate the environment and store a persistent environment variable for the
location of the downloaded Poplar SDK. This assumes that
you have already downloaded the Poplar SDK. The following example uses an
environment variable `$POPLAR_SDK` to store the root folder for the SDK.
```bash
conda activate pyscf-ipu
conda env config vars set POPLAR_SDK=$POPLAR_SDK
hatemhelal marked this conversation as resolved.
Show resolved Hide resolved
```

4. You have to reactivate the conda environment to use the `$POPLAR_SDK`
variable the environment.
hatemhelal marked this conversation as resolved.
Show resolved Hide resolved
```bash
conda deactivate
conda activate pyscf-ipu
```

5. Setup the conda environment to automatically enable the Poplar SDK whenever
the environment is activated.
```bash
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
echo "source $POPLAR_SDK/enable" > $CONDA_PREFIX/etc/conda/activate.d/enable.sh
```

6. Check that everything is working by once again reactivating the pyscf-ipu
environment and calling `gc-monitor`:
```bash
conda deactivate
conda activate pyscf-ipu
gc-monitor
```
hatemhelal marked this conversation as resolved.
Show resolved Hide resolved

7. Install all required packages for developing JAX DFT:
```bash
pip install -e ".[ipu,test]"
```

8. Install the pre-commit hooks
```bash
pre-commit install
```

9. Create a feature branch, make changes, and when you commit them the
pre-commit hooks will run.
```bash
git checkout -b feature
...
git push --set-upstream origin feature
```
The last command will prints a link that you can follow to open a PR.


## Testing
Run all the tests using `pytest`
```bash
pytest
```
We also use the nbmake package to check our notebooks work in the `IpuModel` environment. These checks can also be run on IPU hardware equiped machines e.g.:
```bash
pytest --nbmake --nbmake-timeout=3000 notebooks/nanoDFT-demo.ipynb
```
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![notebook-tests](https://github.com/graphcore-research/pyscf-ipu/actions/workflows/notebooks.yaml/badge.svg)](https://github.com/graphcore-research/pyscf-ipu/actions/workflows/notebooks.yaml)
[![nanoDFT CLI](https://github.com/graphcore-research/pyscf-ipu/actions/workflows/cli.yaml/badge.svg)](https://github.com/graphcore-research/pyscf-ipu/actions/workflows/cli.yaml)
[![unit tests](https://github.com/graphcore-research/pyscf-ipu/actions/workflows/unittest.yaml/badge.svg)](https://github.com/graphcore-research/pyscf-ipu/actions/workflows/unittest.yaml)
[![pre-commit checks](https://github.com/graphcore-research/pyscf-ipu/actions/workflows/pre-commit.yaml/badge.svg)](https://github.com/graphcore-research/pyscf-ipu/actions/workflows/pre-commit.yaml)

[**Installation guide**](#installation)
| [**Example DFT Computations**](#example-dft-computations)
Expand Down
1 change: 1 addition & 0 deletions notebooks/plot_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2023 Graphcore Ltd. All rights reserved.
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
Expand Down
1 change: 1 addition & 0 deletions pyscf_ipu/electron_repulsion/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2023 Graphcore Ltd. All rights reserved.
1 change: 1 addition & 0 deletions pyscf_ipu/exchange_correlation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2023 Graphcore Ltd. All rights reserved.
1 change: 1 addition & 0 deletions pyscf_ipu/exchange_correlation/b88.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2023 Graphcore Ltd. All rights reserved.
# The functional definition in this file was ported to Python
# from XCFun, which is Copyright Ulf Ekström and contributors 2009-2020
# and provided under the Mozilla Public License (v2.0)
Expand Down
1 change: 1 addition & 0 deletions pyscf_ipu/exchange_correlation/lyp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2023 Graphcore Ltd. All rights reserved.
# The functional definition in this file was ported to Python
# from XCFun, which is Copyright Ulf Ekström and contributors 2009-2020
# and provided under the Mozilla Public License (v2.0)
Expand Down
1 change: 1 addition & 0 deletions pyscf_ipu/exchange_correlation/vwn.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2023 Graphcore Ltd. All rights reserved.
# The functional definition in this file was ported to Python
# from XCFun, which is Copyright Ulf Ekström and contributors 2009-2020
# and provided under the Mozilla Public License (v2.0)
Expand Down
1 change: 1 addition & 0 deletions pyscf_ipu/nanoDFT/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Copyright (c) 2023 Graphcore Ltd. All rights reserved.
from .nanoDFT import *
1 change: 1 addition & 0 deletions pyscf_ipu/nanoDFT/sparse_ERI.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2023 Graphcore Ltd. All rights reserved.
import numpy as np
import jax.numpy as jnp
import os
Expand Down
1 change: 1 addition & 0 deletions pyscf_ipu/nanoDFT/symmetric_ERI.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright (c) 2023 Graphcore Ltd. All rights reserved.
import numpy as np
import jax.numpy as jnp
import os
Expand Down
3 changes: 3 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
# requirements_ipu.txt for ipu backend configuration
pytest
nbmake
pre-commit
flake8
flake8-copyright