diff --git a/.github/workflow/lint.yml b/.github/workflow/lint.yml index 1a31c24b..998ae250 100644 --- a/.github/workflow/lint.yml +++ b/.github/workflow/lint.yml @@ -7,7 +7,7 @@ on: [] # branches: [] # pull_request: # branches: [] - + jobs: build-linux: @@ -43,4 +43,4 @@ jobs: # run: mypy --config-file=.mypy.ini . - name: Test with pytest - run: python -m pytest tests \ No newline at end of file + run: python -m pytest tests diff --git a/.github/workflow/pre-commit.yaml b/.github/workflow/pre-commit.yaml new file mode 100644 index 00000000..6cfe0e02 --- /dev/null +++ b/.github/workflow/pre-commit.yaml @@ -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/action@v3.0.0 diff --git a/.github/workflow/unittest.yaml b/.github/workflow/unittest.yaml new file mode 100644 index 00000000..6da196d6 --- /dev/null +++ b/.github/workflow/unittest.yaml @@ -0,0 +1,29 @@ +name: unit tests +on: + pull_request: + push: + branches: [main] + +jobs: + pytest-container: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + cache: "pip" + + - name: Install requirements + run: | + pip install -U pip + pip install .[dev] + + - name: Log installed environment + run: | + python3 -m pip freeze + + - name: Run unit tests + run: | + pytest tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..32319396 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,50 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 23.12.1 + hooks: + - id: black + name: Black Formating + + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + name: Sort imports + + # Failing - to be investigated separately + # - repo: local + # hooks: + # - id: pylint + # name: Pylint Checks + # entry: pylint + # language: system + # types: [python] + # args: + # [ + # "--rcfile=pyproject.toml", + # "mace", + # "tests", + # "scripts" + # ] + + # - repo: local + # hooks: + # - id: mypy + # name: mypy type checks + # entry: mypy + # language: system + # types: [python] + # args: + # [ + # --config-file=.mypy.ini, + # mace, + # tests, + # scripts + # ] + \ No newline at end of file diff --git a/README.md b/README.md index 064128fd..ec9a3693 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ mace_eval_configs \ ## Tutorial -You can run our [Colab tutorial](https://colab.research.google.com/drive/1D6EtMUjQPey_GkuxUAbPgld6_9ibIa-V?authuser=1#scrollTo=Z10787RE1N8T) to quickly get started with MACE. +You can run our [Colab tutorial](https://colab.research.google.com/drive/1D6EtMUjQPey_GkuxUAbPgld6_9ibIa-V?authuser=1#scrollTo=Z10787RE1N8T) to quickly get started with MACE. We also have a more detailed user and developer tutorial at https://github.com/ilyes319/mace-tutorials @@ -193,7 +193,7 @@ print(atoms.get_potential_energy()) ### MACE-OFF: Transferable Organic Force Fields -There is a series (small, medium, large) transferable organic force fields. These can be used for the simulation of organic molecules, crystals and molecular liquids, or as a starting point for fine-tuning on a new dataset. The models are released under the [ASL license](https://github.com/gabor1/ASL). +There is a series (small, medium, large) transferable organic force fields. These can be used for the simulation of organic molecules, crystals and molecular liquids, or as a starting point for fine-tuning on a new dataset. The models are released under the [ASL license](https://github.com/gabor1/ASL). The models are releaed on GitHub at https://github.com/ACEsuit/mace-off. If you use them please cite [our paper](https://arxiv.org/abs/2312.15211) which also contains detailed benchmarks and example applications. @@ -210,13 +210,15 @@ print(atoms.get_potential_energy()) ## Development -We use `black`, `isort`, `pylint`, and `mypy`. -Run the following to format and check your code: - -```sh -bash ./scripts/run_checks.sh +This project uses [pre-commit](https://pre-commit.com/) to execute code formatting and linting on commit. +We also use `black`, `isort`, `pylint`, and `mypy`. +We recommend setting up your development environment by installing the `dev` packages +into your python environment: +```bash +pip install -e ".[dev]" +pre-commit install ``` - +The second line will initialise `pre-commit` to automaticaly run code checks on commit. We have CI set up to check this, but we _highly_ recommend that you run those commands before you commit (and push) to avoid accidentally committing bad code. diff --git a/pyproject.toml b/pyproject.toml index abadfe96..8de9c0dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,4 +36,4 @@ disable = [ ignore-paths = [ "^mace/tools/torch_geometric/.*$", "^mace/tools/scatter.py$", -] \ No newline at end of file +] diff --git a/setup.cfg b/setup.cfg index 3cc4c920..704c0389 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,3 +36,10 @@ console_scripts = [options.extras_require] wandb = wandb +dev = + black + isort + mypy + pre-commit + pytest + pylint diff --git a/tests/test_calculator.py b/tests/test_calculator.py index f7f33e3d..3b2c816b 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -6,10 +6,10 @@ import ase.io import numpy as np import pytest +from ase import build from ase.atoms import Atoms from ase.calculators.test import gradient_test from ase.constraints import ExpCellFilter -from ase import build from mace.calculators import mace_mp, mace_off from mace.calculators.foundations_models import local_model_path