Skip to content

Commit

Permalink
Add linting including gh action
Browse files Browse the repository at this point in the history
  • Loading branch information
PicoCentauri committed Jul 10, 2023
1 parent 137d239 commit fb9ac14
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 16 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Lint tests run on PR
# but should not run after push to main because reporting
# these after push is meaningless to the building of the package
name: lint

on:
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: pip install tox

- name: Test Lint
run: tox -e lint
11 changes: 8 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ COSMO Software Cookbook

.. marker-intro-start
The COSMO cookbook contains recipes for atomic-scale modelling for materials and molecules, with a particular focus on machine learning and statistical sampling methods.
Rather than focusing on the usage of a specific package (see the `COSMO github page <https://github.com/lab-cosmo>`_ for a list of available tools, and their documentations) this cookbook provides concrete examples of the solution of modeling problems using a combination of the various tools.
The COSMO cookbook contains recipes for atomic-scale modelling for materials and
molecules, with a particular focus on machine learning and statistical sampling methods.
Rather than focusing on the usage of a specific package (see the `COSMO github page
<https://github.com/lab-cosmo>`_ for a list of available tools, and their
documentations) this cookbook provides concrete examples of the solution of modeling
problems using a combination of the various tools.

.. marker-intro-end
Contributors
------------

If you want contribute an example, recipe or tutorial that combines multiple software tools together, check out the `contributing guidelines <CONTRIBUTING.rst>`_ first.
If you want contribute an example, recipe or tutorial that combines multiple software
tools together, check out the `contributing guidelines <CONTRIBUTING.rst>`_ first.
14 changes: 14 additions & 0 deletions docs/src/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

COSMO Software Cookbook
=======================

.. include:: ../../README.rst
:start-after: marker-intro-start
:end-before: marker-intro-end

.. toctree::
:caption: Table of Contents

mlp_models/index
uncategorized/index
sample_selection/index
7 changes: 3 additions & 4 deletions examples/mlp_models/linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@


import numpy as np
import matplotlib.pyplot as plt

# %%
# Explanation

X = np.random.rand(10000)*400
Y = 0.1*X+10.1
Y_p = Y + np.random.randn(10000)*1.5
X = np.random.rand(10000) * 400
Y = 0.1 * X + 10.1
Y_p = Y + np.random.randn(10000) * 1.5
11 changes: 4 additions & 7 deletions examples/sample_selection/sample_selection_librascal.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@
# First, import all the necessary packages
import ase.io
import numpy as np
from sklearn.decomposition import PCA

import chemiscope
from rascal.representations import SphericalInvariants
from rascal.utils import FPSFilter
from skmatter import sample_selection, feature_selection

from sklearn.decomposition import PCA
from skmatter import feature_selection, sample_selection

# %%
# Load molecular data
Expand Down Expand Up @@ -70,7 +66,8 @@
# Generate a SOAP spherical expansion
soap = SphericalInvariants(**soap_hypers)

# Perform a data trasnformation and get the descriptor with samples as atomic environments
# Perform a data trasnformation and get the descriptor with samples as atomic
# environments
atom_dscrptr = soap.transform(frames).get_features(soap)

# Calculate the stucture features as the mean over the atomic features for each
Expand Down
48 changes: 46 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,57 @@
[tox]
min_version = 4.0
envlist =
lint
docs

[testenv:docs]
lint_folders = "{toxinidir}/examples"

[testenv:lint]
skip_install = true
deps =
black
blackdoc
flake8
flake8-bugbear
isort
flake8-sphinx-links
sphinx-lint
commands =
flake8 {[tox]lint_folders}
black --check --diff {[tox]lint_folders}
blackdoc --check --diff {[tox]lint_folders}
isort --check-only --diff {[tox]lint_folders}
sphinx-lint --enable line-too-long --max-line-length 88 \
-i "{toxinidir}/docs/src" \
{[tox]lint_folders} "{toxinidir}/README.rst"

[testenv:docs]
deps =
-r docs/requirements.txt
commands =
pip install -r docs/requirements.txt
# tox's can not handle our custom requirement files in the deps section.
pip install -r docs/requirements-rascal.txt
pip install -r docs/requirements-equistore.txt

sphinx-build {posargs:-E} -W -b html docs/src docs/build/html

[testenv:format]
# Abuse tox to do actual formatting. Users can call `tox -e format` to run
# formatting on all files
skip_install = true
deps =
black
blackdoc
isort
commands =
black {[tox]lint_folders}
blackdoc {[tox]lint_folders}
isort {[tox]lint_folders}

[flake8]
max_line_length = 88
exclude =
docs/src/examples/
per-file-ignores =
# D205 and D400 are incompatible with the requirements of sphinx-gallery
examples/**:D205, D400

0 comments on commit fb9ac14

Please sign in to comment.