Skip to content

Commit

Permalink
Merge pull request #119 from ax3l/pre-commit-setup
Browse files Browse the repository at this point in the history
Install pre-commit
  • Loading branch information
AngelFP authored Oct 10, 2023
2 parents 94042f8 + 2baa6d3 commit afda164
Show file tree
Hide file tree
Showing 99 changed files with 2,691 additions and 2,048 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ jobs:
conda install numpy pandas pytorch cpuonly -c pytorch
conda install -c conda-forge mpi4py mpich
pip install .[test]
- shell: bash -l {0}
name: Lint with flake8
run: |
flake8 ./optimas
flake8 ./examples --extend-ignore F821 --exclude custom_fld_diags.py,custom_ptcl_diags.py
- shell: bash -l {0}
name: Run unit tests with MPICH
run: |
Expand Down
136 changes: 136 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# To use:
#
# pre-commit run -a
#
# Or:
#
# pre-commit install # (runs every time you commit in git)
#
# To update this file:
#
# pre-commit autoupdate
#
# See https://pre-commit.com for more information

# Do not check/format anything from third party directories
#exclude: '^share/openPMD/thirdParty'

# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer
- id: mixed-line-ending
- id: check-json
- id: check-toml
- id: check-yaml
args: [--allow-multiple-documents]
- id: check-added-large-files
args: ['--maxkb=40']
- id: requirements-txt-fixer
# - id: fix-encoding-pragma
# exclude: ^noxfile.py$

# documentation files: .rst
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

#- repo: https://github.com/asottile/pyupgrade
# rev: v2.29.0
# hooks:
# - id: pyupgrade

# Changes tabs to spaces
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
hooks:
- id: remove-tabs

# CMake formatting
#- repo: https://github.com/cheshirekow/cmake-format-precommit
# rev: v0.6.13
# hooks:
# - id: cmake-format
# additional_dependencies: [pyyaml]
# types: [file]
# files: (\.cmake|CMakeLists.txt)(.in)?$

# Autoremoves unused Python imports
- repo: https://github.com/hadialqattan/pycln
rev: v2.2.2
hooks:
- id: pycln
name: pycln (python)

# Sorts Python imports according to PEP8
# https://www.python.org/dev/peps/pep-0008/#imports
#- repo: https://github.com/pycqa/isort
# rev: 5.12.0
# hooks:
# - id: isort
# name: isort (python)

# Python: Flake8 (checks only, does this support auto-fixes?)
#- repo: https://github.com/PyCQA/flake8
# rev: 4.0.1
# hooks:
# - id: flake8
# additional_dependencies: &flake8_dependencies
# - flake8-bugbear
# - pep8-naming
# exclude: ^(docs/.*|tools/.*)$
# Alternatively: use autopep8?

# Docstring formatting according to numpy style
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
additional_dependencies:
- tomli
exclude: |
(?x)(
^examples/multitask_lpa_fbpic_waket/custom_*|
^setup.py|
^doc/source/conf.py
)
# Python Formatting
- repo: https://github.com/psf/black
rev: 23.9.1 # Keep in sync with blacken-docs
hooks:
- id: black
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
args: [--line-length=80]
additional_dependencies:
- black==23.9.1 # keep in sync with black hook
# TODO: black-jupyter

# Jupyter Notebooks: clean up all cell outputs
# - repo: https://github.com/roy-ht/pre-commit-jupyter
# rev: v1.2.1
# hooks:
# - id: jupyter-notebook-cleanup
# args:
# - --pin-patterns
# - "[pin];[donotremove]"
# # - --remove-kernel-metadata

# Checks the manifest for missing files (native support)
- repo: https://github.com/mgedmin/check-manifest
rev: "0.49"
hooks:
- id: check-manifest
# This is a slow hook, so only run this if --hook-stage manual is passed
stages: [manual]
additional_dependencies: [cmake, ninja]
6 changes: 3 additions & 3 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"affiliation": "Deutsches Elektronen-Synchrotron, previously LBNL",
"name": "Th\u00e9venet, Maxence",
"orcid": "0000-0001-7216-2277"
},
},
{
"affiliation": "Argonne National Laboratory",
"name": "Larson, Jeffrey",
"orcid": "0000-0001-9924-2082"
},
},
{
"affiliation": "Argonne National Laboratory",
"name": "Hudson, Stephen",
Expand All @@ -40,7 +40,7 @@
"affiliation": "Lawrence Berkeley National Laboratory",
"name": "Huebl, Axel",
"orcid": "0000-0003-1943-7141"
},
},
{
"affiliation": "Lawrence Berkeley National Laboratory",
"name": "Vay, Jean-Luc",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</a>

<h3 align="center">
Optimization at scale, powered by
Optimization at scale, powered by
<a href="https://libensemble.readthedocs.io/"><strong>libEnsemble</strong></a>
</h3>

Expand Down
20 changes: 10 additions & 10 deletions doc/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pushd %~dp0
REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
Expand All @@ -14,15 +14,15 @@ if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
Expand Down
8 changes: 4 additions & 4 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ax-platform >= 0.2.9
libensemble >= 0.9.2
matplotlib
numpydoc
pydata-sphinx-theme
sphinx-design
sphinx-gallery
numpydoc
matplotlib
libensemble >= 0.9.2
ax-platform >= 0.2.9
2 changes: 1 addition & 1 deletion doc/source/_templates/autosummary/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

.. currentmodule:: {{ module }}

.. auto{{ objtype }}:: {{ objname }}
.. auto{{ objtype }}:: {{ objname }}
2 changes: 1 addition & 1 deletion doc/source/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
{% endif %}
{%- endfor %}
{% endif %}
{% endblock %}
{% endblock %}
29 changes: 15 additions & 14 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
import os
import sys
from datetime import date
sys.path.insert(0, os.path.abspath('../..'))

sys.path.insert(0, os.path.abspath("../.."))


# -- Import version ----------------------------------------------------------
from optimas import __version__ # noqa: E402


# -- Project information -----------------------------------------------------
project = 'optimas'
project_copyright = '2023-%s, the optimas collaborators' % date.today().year
author = 'The optimas collaborators'
project = "optimas"
project_copyright = "2023-%s, the optimas collaborators" % date.today().year
author = "The optimas collaborators"

# The full version, including alpha/beta/rc tags
release = __version__
Expand All @@ -35,18 +36,18 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.coverage',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.coverage",
# 'sphinx.ext.intersphinx',
'sphinx_design',
"sphinx_design",
# 'sphinx_gallery.gen_gallery',
'numpydoc',
"numpydoc",
"matplotlib.sphinxext.plot_directive",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -59,12 +60,12 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'pydata_sphinx_theme' # "sphinx_rtd_theme"
html_theme = "pydata_sphinx_theme" # "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Logo
html_logo = "_static/logo.png"
Expand All @@ -87,7 +88,7 @@
"pygment_light_style": "default",
"pygment_dark_style": "monokai",
"use_edit_page_button": True,
"navigation_depth": 2
"navigation_depth": 2,
}

html_context = {
Expand All @@ -98,7 +99,7 @@
}

# Do not show type hints.
autodoc_typehints = 'none'
autodoc_typehints = "none"

# Do not use numpydoc to generate autosummary.
numpydoc_show_class_members = False
Expand Down
2 changes: 1 addition & 1 deletion doc/source/examples/bo_basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Description
This example illustrates how to run a generic Bayesian optimization with
simulations. This typically requires:

- An `optimas` script for defining and running the optimization.
- An *optimas* script for defining and running the optimization.
- A template simulation script.
- A function to analyze the simulation output.

Expand Down
4 changes: 2 additions & 2 deletions doc/source/examples/bo_multitask_fbpic_waket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Scripts
Files included:

- :download:`run_opt.py <../../../examples/multitask_lpa_fbpic_waket/run_opt.py>`:
defines and launches the optimization with `optimas`.
defines and launches the optimization with *optimas*.
- :download:`template_simulation_script.py <../../../examples/multitask_lpa_fbpic_waket/template_simulation_script.py>`:
template used by `optimas` to generate the FBPIC and Wake-T simulation
template used by *optimas* to generate the FBPIC and Wake-T simulation
scripts.
- :download:`analysis_script.py <../../../examples/multitask_lpa_fbpic_waket/analysis_script.py>`:
defines how the simulation data is analyzed to yield the value of the
Expand Down
6 changes: 3 additions & 3 deletions doc/source/examples/ps_grid_sampling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ where :math:`l_b=0` and :math:`u_b=15`, the grid of sample looks like:
break
x0 = np.zeros(len(all_trials))
x1 = np.zeros(len(all_trials))

for i, trial in enumerate(all_trials):
trial_params = trial.parameters_as_dict()
x0[i] = trial_params['x0']
x1[i] = trial_params['x1']

fig, ax = plt.subplots()
ax.scatter(x0, x1, s=3, label='generated evaluations')
ax.set(
Expand Down Expand Up @@ -89,4 +89,4 @@ The example is executed by running

.. literalinclude:: ../../../examples/dummy_grid_sampling/template_simulation_script.py
:language: python
:caption: template_simulation_script.py (:download:`download <../../../examples/dummy_grid_sampling/template_simulation_script.py>`)
:caption: template_simulation_script.py (:download:`download <../../../examples/dummy_grid_sampling/template_simulation_script.py>`)
6 changes: 3 additions & 3 deletions doc/source/examples/ps_line_sampling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ where :math:`x_0` and :math:`x_1` have a default values of :math:`5` and
break
x0 = np.zeros(len(all_trials))
x1 = np.zeros(len(all_trials))

for i, trial in enumerate(all_trials):
trial_params = trial.parameters_as_dict()
x0[i] = trial_params['x0']
x1[i] = trial_params['x1']

fig, ax = plt.subplots()
ax.scatter(x0, x1, s=3, label='generated evaluations')
ax.set(
Expand Down Expand Up @@ -94,4 +94,4 @@ You can find both example scripts below.

.. literalinclude:: ../../../examples/dummy_line_sampling/template_simulation_script.py
:language: python
:caption: template_simulation_script.py (:download:`download <../../../examples/dummy_line_sampling/template_simulation_script.py>`)
:caption: template_simulation_script.py (:download:`download <../../../examples/dummy_line_sampling/template_simulation_script.py>`)
Loading

0 comments on commit afda164

Please sign in to comment.