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/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 6cfe0e02..aaf7f8b6 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -10,5 +10,19 @@ 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 + pip install .[dev] + pip install wandb + pip install tqdm + - name: Run black + run: | + python -m black . - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 32319396..ae4223d7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,50 +1,58 @@ +exclude: &exclude_files > + (?x)^( + docs/.*| + tests/.*| + .github/.*| + LICENSE.md| + README.md| + )$ + 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 + 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 + exclude: *exclude_files - repo: https://github.com/pycqa/isort rev: 5.13.2 hooks: - id: isort name: Sort imports + exclude: *exclude_files - # 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 + - 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', + '--disable=use-dict-literal', + ] + exclude: *exclude_files \ No newline at end of file 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/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/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/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() 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": 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