From 28d55aaf52ca62c6d97a8b9125ad6bae9c2d3aac Mon Sep 17 00:00:00 2001 From: Ilyes Batatia <48651863+ilyes319@users.noreply.github.com> Date: Tue, 23 Apr 2024 20:53:42 +0100 Subject: [PATCH 1/9] add pylint to pre-commit --- .pre-commit-config.yaml | 71 ++++++++++++++++++++----------------- mace/cli/run_train.py | 2 +- mace/tools/scripts_utils.py | 4 +-- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 32319396..ae573d90 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,17 @@ +exclude: &exclude_files > + (?x)^( + docs/.*| + tests/.*| + .github/.*| + LICENSE| + )$ + repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v2.5.0 hooks: - - id: end-of-file-fixer - - id: trailing-whitespace + - id: mixed-line-ending + - id: trailing-whitespace - repo: https://github.com/psf/black-pre-commit-mirror rev: 23.12.1 @@ -17,34 +25,31 @@ repos: - 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 - # ] + - repo: https://github.com/PyCQA/pylint + rev: pylint-2.5.2 + hooks: + - id: pylint + language: system + args: [ + '--disable=line-too-long', + '--disable=no-member', + '--disable=missing-module-docstring', + '--disable=missing-class-docstring', + '--disable=missing-function-docstring', + '--disable=too-many-arguments', + '--disable=too-many-locals', + '--disable=not-callable', + '--disable=logging-fstring-interpolation', + '--disable=logging-not-lazy', + '--disable=invalid-name', + '--disable=too-few-public-methods', + '--disable=too-many-instance-attributes', + '--disable=too-many-statements', + '--disable=too-many-branches', + '--disable=import-outside-toplevel', + '--disable=cell-var-from-loop', + '--disable=duplicate-code', + ] + exclude: *exclude_files + \ No newline at end of file diff --git a/mace/cli/run_train.py b/mace/cli/run_train.py index 050e896a..d1957dea 100644 --- a/mace/cli/run_train.py +++ b/mace/cli/run_train.py @@ -823,7 +823,7 @@ def main() -> None: path_complied, _extra_files=extra_files, ) - except Exception as e: # pylint: disable=W070344 + except Exception as e: # pylint: disable=W0703 pass if args.distributed: diff --git a/mace/tools/scripts_utils.py b/mace/tools/scripts_utils.py index 756627ad..17630bf3 100644 --- a/mace/tools/scripts_utils.py +++ b/mace/tools/scripts_utils.py @@ -388,9 +388,9 @@ def step(self, metrics=None, epoch=None): # pylint: disable=E1123 if self.scheduler == "ExponentialLR": self.lr_scheduler.step(epoch=epoch) elif self.scheduler == "ReduceLROnPlateau": - self.lr_scheduler.step( + self.lr_scheduler.step( # pylint: disable=E1123 metrics=metrics, epoch=epoch - ) # pylint: disable=E1123 + ) def __getattr__(self, name): if name == "step": From 4b1fc6950eb6edba9e25e17d89ae3f1f9f0ad05b Mon Sep 17 00:00:00 2001 From: Ilyes Batatia <48651863+ilyes319@users.noreply.github.com> Date: Tue, 23 Apr 2024 21:07:23 +0100 Subject: [PATCH 2/9] format with black --- .github/workflows/pre-commit.yaml | 13 +++++++ mace/cli/active_learning_md.py | 1 + mace/data/utils.py | 6 ++-- mace/tools/finetuning_utils.py | 58 +++++++++++++++---------------- 4 files changed, 46 insertions(+), 32 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 6cfe0e02..74b8bf13 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -11,4 +11,17 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 + with: + python-version: "3.10" + cache: "pip" + + - name: Install requirements + run: | + pip install -U pip + pip install pylint + + - name: Log installed environment + run: | + python3 -m pip freeze + - uses: pre-commit/action@v3.0.0 diff --git a/mace/cli/active_learning_md.py b/mace/cli/active_learning_md.py index cd5c8cb0..de4bbc1d 100644 --- a/mace/cli/active_learning_md.py +++ b/mace/cli/active_learning_md.py @@ -1,4 +1,5 @@ """Demonstrates active learning molecular dynamics with constant temperature.""" + import argparse import os import time diff --git a/mace/data/utils.py b/mace/data/utils.py index a6153665..ba76423e 100644 --- a/mace/data/utils.py +++ b/mace/data/utils.py @@ -246,9 +246,9 @@ def load_from_xyz( isolated_atom_config = atoms.info.get("config_type") == "IsolatedAtom" if isolated_atom_config: if energy_key in atoms.info.keys(): - atomic_energies_dict[ - atoms.get_atomic_numbers()[0] - ] = atoms.info[energy_key] + atomic_energies_dict[atoms.get_atomic_numbers()[0]] = ( + atoms.info[energy_key] + ) else: logging.warning( f"Configuration '{idx}' is marked as 'IsolatedAtom' " diff --git a/mace/tools/finetuning_utils.py b/mace/tools/finetuning_utils.py index 97cae96a..0aad091b 100644 --- a/mace/tools/finetuning_utils.py +++ b/mace/tools/finetuning_utils.py @@ -50,24 +50,24 @@ def load_foundations( for j in range(4): # Assuming 4 layers in conv_tp_weights, layer_name = f"layer{j}" if j == 0: - getattr( - model.interactions[i].conv_tp_weights, layer_name - ).weight = torch.nn.Parameter( - getattr( - model_foundations.interactions[i].conv_tp_weights, - layer_name, + getattr(model.interactions[i].conv_tp_weights, layer_name).weight = ( + torch.nn.Parameter( + getattr( + model_foundations.interactions[i].conv_tp_weights, + layer_name, + ) + .weight[:num_radial, :] + .clone() ) - .weight[:num_radial, :] - .clone() ) else: - getattr( - model.interactions[i].conv_tp_weights, layer_name - ).weight = torch.nn.Parameter( - getattr( - model_foundations.interactions[i].conv_tp_weights, - layer_name, - ).weight.clone() + getattr(model.interactions[i].conv_tp_weights, layer_name).weight = ( + torch.nn.Parameter( + getattr( + model_foundations.interactions[i].conv_tp_weights, + layer_name, + ).weight.clone() + ) ) model.interactions[i].linear.weight = torch.nn.Parameter( @@ -105,24 +105,24 @@ def load_foundations( for i in range(2): # Assuming 2 products modules max_range = max_L + 1 if i == 0 else 1 for j in range(max_range): # Assuming 3 contractions in symmetric_contractions - model.products[i].symmetric_contractions.contractions[ - j - ].weights_max = torch.nn.Parameter( - model_foundations.products[i] - .symmetric_contractions.contractions[j] - .weights_max[indices_weights, :, :] - .clone() - ) - - for k in range(2): # Assuming 2 weights in each contraction - model.products[i].symmetric_contractions.contractions[j].weights[ - k - ] = torch.nn.Parameter( + model.products[i].symmetric_contractions.contractions[j].weights_max = ( + torch.nn.Parameter( model_foundations.products[i] .symmetric_contractions.contractions[j] - .weights[k][indices_weights, :, :] + .weights_max[indices_weights, :, :] .clone() ) + ) + + for k in range(2): # Assuming 2 weights in each contraction + model.products[i].symmetric_contractions.contractions[j].weights[k] = ( + torch.nn.Parameter( + model_foundations.products[i] + .symmetric_contractions.contractions[j] + .weights[k][indices_weights, :, :] + .clone() + ) + ) model.products[i].linear.weight = torch.nn.Parameter( model_foundations.products[i].linear.weight.clone() From 3ad2021102b0a04c1498d7936e1330a44e5977f0 Mon Sep 17 00:00:00 2001 From: Ilyes Batatia <48651863+ilyes319@users.noreply.github.com> Date: Tue, 23 Apr 2024 21:19:31 +0100 Subject: [PATCH 3/9] exclude files in pre commit --- .github/workflows/pre-commit.yaml | 1 + .pre-commit-config.yaml | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 74b8bf13..9267ce44 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -19,6 +19,7 @@ jobs: run: | pip install -U pip pip install pylint + pip install -U black - name: Log installed environment run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ae573d90..8ac8fa5a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,6 +4,7 @@ exclude: &exclude_files > tests/.*| .github/.*| LICENSE| + README| )$ repos: @@ -12,18 +13,21 @@ repos: hooks: - id: mixed-line-ending - id: trailing-whitespace + exclude: *exclude_files - repo: https://github.com/psf/black-pre-commit-mirror rev: 23.12.1 hooks: - id: black name: Black Formating + exclude: *exclude_files - repo: https://github.com/pycqa/isort rev: 5.13.2 hooks: - id: isort name: Sort imports + exclude: *exclude_files - repo: https://github.com/PyCQA/pylint rev: pylint-2.5.2 @@ -50,6 +54,4 @@ repos: '--disable=cell-var-from-loop', '--disable=duplicate-code', ] - exclude: *exclude_files - - \ No newline at end of file + exclude: *exclude_files \ No newline at end of file From 4b3f1471acd212af2cf9a08a16d5df23389a0704 Mon Sep 17 00:00:00 2001 From: Ilyes Batatia <48651863+ilyes319@users.noreply.github.com> Date: Tue, 23 Apr 2024 21:23:50 +0100 Subject: [PATCH 4/9] add run black to pre commit --- .github/workflows/pre-commit.yaml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 9267ce44..a9e2859a 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -10,19 +10,16 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 with: python-version: "3.10" cache: "pip" - - name: Install requirements run: | pip install -U pip pip install pylint pip install -U black - - - name: Log installed environment + - name: Run black run: | - python3 -m pip freeze - + python -m black . - uses: pre-commit/action@v3.0.0 From c6a302b7f788860b07a967f579903da0afdd871f Mon Sep 17 00:00:00 2001 From: Ilyes Batatia <48651863+ilyes319@users.noreply.github.com> Date: Tue, 23 Apr 2024 21:26:28 +0100 Subject: [PATCH 5/9] update black rev in pre commit --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8ac8fa5a..bbaa104a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: exclude: *exclude_files - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.12.1 + rev: 24.4.0 hooks: - id: black name: Black Formating From c097eb34b7a6d66f51a111eb2f75753b3a0b1ae3 Mon Sep 17 00:00:00 2001 From: Ilyes Batatia <48651863+ilyes319@users.noreply.github.com> Date: Tue, 23 Apr 2024 21:44:47 +0100 Subject: [PATCH 6/9] install dep for pylint --- .github/workflows/pre-commit.yaml | 1 + .pre-commit-config.yaml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index a9e2859a..6e0b07bc 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -19,6 +19,7 @@ jobs: pip install -U pip pip install pylint pip install -U black + pip install .[dev] - name: Run black run: | python -m black . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bbaa104a..8d1b8ef3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,7 +30,7 @@ repos: exclude: *exclude_files - repo: https://github.com/PyCQA/pylint - rev: pylint-2.5.2 + rev: pylint-2.14.1 hooks: - id: pylint language: system From ed2d719b1115d257b80934777dd0f3de9446272f Mon Sep 17 00:00:00 2001 From: Ilyes Batatia <48651863+ilyes319@users.noreply.github.com> Date: Tue, 23 Apr 2024 21:48:17 +0100 Subject: [PATCH 7/9] remove lint.yml --- .github/workflows/lint.yml | 46 -------------------------------------- .pre-commit-config.yaml | 2 +- 2 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 998ae250..00000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Linting and code formatting - -on: [] - # Trigger the workflow on push or pull request, - # but only for the main branch - # push: - # branches: [] - # pull_request: - # branches: [] - - -jobs: - build-linux: - runs-on: ubuntu-latest - - steps: - # Setup - - name: Checkout - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.8.10 - - name: Get cache - uses: actions/cache@v2 - with: - path: /opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages - # Look to see if there is a cache hit for the corresponding requirements file - key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} - - # Install packages - - name: Install packages required for installation - run: python -m pip install --upgrade pip setuptools wheel - - name: Install dependencies - run: pip install -r requirements.txt - - # Check code - - name: Check formatting with yapf - run: python -m yapf --style=.style.yapf --diff --recursive . -# - name: Lint with flake8 -# run: flake8 --config=.flake8 . -# - name: Check type annotations with mypy -# run: mypy --config-file=.mypy.ini . - - - name: Test with pytest - run: python -m pytest tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8d1b8ef3..bbaa104a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,7 +30,7 @@ repos: exclude: *exclude_files - repo: https://github.com/PyCQA/pylint - rev: pylint-2.14.1 + rev: pylint-2.5.2 hooks: - id: pylint language: system From b553dce756648360f000f88927c2e86d1ae4bdfc Mon Sep 17 00:00:00 2001 From: Ilyes Batatia <48651863+ilyes319@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:08:40 +0100 Subject: [PATCH 8/9] fix pylint for precommit --- .github/workflows/pre-commit.yaml | 2 ++ .pre-commit-config.yaml | 1 + mace/cli/preprocess_data.py | 3 +-- pyproject.toml | 1 + setup.cfg | 1 + 5 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 6e0b07bc..aaf7f8b6 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -20,6 +20,8 @@ jobs: pip install pylint pip install -U black pip install .[dev] + pip install wandb + pip install tqdm - name: Run black run: | python -m black . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bbaa104a..e2634588 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -53,5 +53,6 @@ repos: '--disable=import-outside-toplevel', '--disable=cell-var-from-loop', '--disable=duplicate-code', + '--disable=use-dict-literal', ] exclude: *exclude_files \ No newline at end of file diff --git a/mace/cli/preprocess_data.py b/mace/cli/preprocess_data.py index 23dfd3f2..988cc3cc 100644 --- a/mace/cli/preprocess_data.py +++ b/mace/cli/preprocess_data.py @@ -78,8 +78,7 @@ def split_array(a: np.ndarray, max_size: int): for j in range(0, len(factors) - i + 1): if np.prod(factors[j : j + i]) <= max_size: test = np.prod(factors[j : j + i]) - if test > max_factor: - max_factor = test + max_factor = max(test, max_factor) return np.array_split(a, max_factor), drop_last diff --git a/pyproject.toml b/pyproject.toml index 8de9c0dc..05037dc7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,7 @@ disable = [ "import-outside-toplevel", "cell-var-from-loop", "duplicate-code", + "use-dict-literal", ] [tool.pylint.MASTER] diff --git a/setup.cfg b/setup.cfg index 6ed557ed..c8a246df 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,6 +27,7 @@ install_requires = python-hostlist configargparse GitPython + tqdm # for plotting: matplotlib pandas From 6388f5d4d988d0f0111c8a463eb52d55f3564f51 Mon Sep 17 00:00:00 2001 From: Ilyes Batatia <48651863+ilyes319@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:36:14 +0100 Subject: [PATCH 9/9] ignore readme in precommit --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e2634588..ae4223d7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,8 +3,8 @@ exclude: &exclude_files > docs/.*| tests/.*| .github/.*| - LICENSE| - README| + LICENSE.md| + README.md| )$ repos: