Skip to content

Commit

Permalink
Merge pull request #1357 from MridulS/pre_commit_clean_up
Browse files Browse the repository at this point in the history
Add linting action to run pre-commit
  • Loading branch information
alanlujan91 authored Nov 7, 2023
2 parents 3ec3404 + 78f0af8 commit ab14825
Show file tree
Hide file tree
Showing 48 changed files with 589 additions and 729 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/chatops-binder.yaml

This file was deleted.

130 changes: 65 additions & 65 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,73 +26,73 @@ jobs:
contents: write

steps:
- uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10" # Interpolation.py doesn't support Python 3.11 [2023-07]
cache: 'pip'
cache-dependency-path: |
requirements/base.txt
requirements/doc.txt
- name: Install Pandoc
run: sudo apt-get install --yes pandoc

- name: Update pip
run: python -m pip install --upgrade pip

- name: Install HARK
run: python -m pip install .[doc]

- name: Run Sphinx
run: >
sphinx-build
-M html Documentation HARK-docs
-T
-W
-j auto
- name: Set up git for deployment
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git config --local --unset-all http.https://github.com/.extraheader
- name: Commit all rendered HTML files
run: |
git switch --orphan gh-pages
git add --all HARK-docs/html
git commit -qm "Documentation from @ ${{ github.repository }}@${{ github.sha }}"
- name: Deploy to GitHub Pages
# Only deploy to Pages on pushes to HEAD
if: (github.repository_owner == 'Econ-ARK') && (github.event_name == 'push') && (github.ref_name == 'master')
run: >
git push
--force
https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}
`git subtree split --prefix HARK-docs/html gh-pages`:refs/heads/gh-pages
- uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10" # Interpolation.py doesn't support Python 3.11 [2023-07]
cache: "pip"
cache-dependency-path: |
requirements/base.txt
requirements/doc.txt
- name: Install Pandoc
run: sudo apt-get install --yes pandoc

- name: Update pip
run: python -m pip install --upgrade pip

- name: Install HARK
run: python -m pip install .[doc]

- name: Run Sphinx
run: >
sphinx-build
-M html Documentation HARK-docs
-T
-W
-j auto
- name: Set up git for deployment
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git config --local --unset-all http.https://github.com/.extraheader
- name: Commit all rendered HTML files
run: |
git switch --orphan gh-pages
git add --all HARK-docs/html
git commit -qm "Documentation from @ ${{ github.repository }}@${{ github.sha }}"
- name: Deploy to GitHub Pages
# Only deploy to Pages on pushes to HEAD
if: (github.repository_owner == 'Econ-ARK') && (github.event_name == 'push') && (github.ref_name == 'master')
run: >
git push
--force
https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}
`git subtree split --prefix HARK-docs/html gh-pages`:refs/heads/gh-pages
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade sphinx-lint
- name: Lint documentation with sphinx-lint
run: >
sphinx-lint
--ignore Documentation/example_notebooks/GenIncProcessModel.py
--enable all
--max-line-length 85
README.md
Documentation/
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade sphinx-lint
- name: Lint documentation with sphinx-lint
run: >
sphinx-lint
--ignore Documentation/example_notebooks/GenIncProcessModel.py
--enable all
--max-line-length 85
README.md
Documentation/
82 changes: 41 additions & 41 deletions .github/workflows/execute-notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
workflow_dispatch:
# 6.49 am (GMT) every Monday; time chosen at random
schedule:
- cron: "49 6 * * MON"
- cron: "49 6 * * MON"

# Limit workflow permissions
permissions:
Expand All @@ -29,47 +29,47 @@ jobs:
pull-requests: write

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10" # Numba doesn't support Python 3.11 [2023-05]
cache: 'pip'
cache-dependency-path: |
requirements/base.txt
.github/workflows/execute-notebooks.yml
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10" # Numba doesn't support Python 3.11 [2023-05]
cache: "pip"
cache-dependency-path: |
requirements/base.txt
.github/workflows/execute-notebooks.yml
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .
# For LabeledModels.ipynb
python -m pip install estimagic
# For nbstripout
python -m pip install nbstripout
# For nb_exec.py
python -m pip install ipykernel nbclient nbformat
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .
# For LabeledModels.ipynb
python -m pip install estimagic
# For nbstripout
python -m pip install nbstripout
# For nb_exec.py
python -m pip install ipykernel nbclient nbformat
- name: Strip output
run: nbstripout examples/**/*.ipynb
- name: Strip output
run: nbstripout examples/**/*.ipynb

# This step takes c. 20 minutes
- name: Execute notebooks
run: python tools/nb_exec.py examples/**/*.ipynb
env:
PYTHONUNBUFFERED: "1"
# This step takes c. 20 minutes
- name: Execute notebooks
run: python tools/nb_exec.py examples/**/*.ipynb
env:
PYTHONUNBUFFERED: "1"

- name: Open PR
uses: peter-evans/create-pull-request@v5
with:
author: "Econ-ARK Bot <[email protected]>"
branch: "bot/update-notebooks"
commit-message: "[bot] updated notebooks"
delete-branch: true
title: "[bot] Execute example notebooks"
# language=Markdown
body: >
This PR was [automatically generated] to re-execute
the example notebooks for use in the documentation.
[automatically generated]: https://github.com/Econ-ARK/HARK/actions/workflows/execute-notebooks.yml
- name: Open PR
uses: peter-evans/create-pull-request@v5
with:
author: "Econ-ARK Bot <[email protected]>"
branch: "bot/update-notebooks"
commit-message: "[bot] updated notebooks"
delete-branch: true
title: "[bot] Execute example notebooks"
# language=Markdown
body: >
This PR was [automatically generated] to re-execute
the example notebooks for use in the documentation.
[automatically generated]: https://github.com/Econ-ARK/HARK/actions/workflows/execute-notebooks.yml
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: pre-commit

on: [push, pull_request]

jobs:
format:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install packages
run: |
python -m pip install --upgrade pip
python -m pip install ".[dev]"
pip list
- name: Lint
run: pre-commit run --all-files --show-diff-on-failure --color always
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
exclude: Documentation/example_notebooks/

repos:
- repo: https://github.com/mwouts/jupytext
rev: v1.15.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.4
hooks:
- id: jupytext
args: [--sync, --set-formats, "ipynb", --pipe, black, --execute]
additional_dependencies: [jupytext, black, nbconvert]
files: ^examples/.*\.ipynb$
- id: ruff
types_or: [jupyter]
- id: ruff-format
args: [--check]
types_or: [jupyter]

- repo: https://github.com/psf/black
rev: 23.7.0
Expand Down
2 changes: 1 addition & 1 deletion Documentation/_static/override-nbsphinx-gallery.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.nbsphinx-gallery {
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
20 changes: 11 additions & 9 deletions Documentation/conf.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from datetime import date
import warnings
from datetime import date

try:
import numba
except ImportError:
pass
else:
warnings.filterwarnings("ignore",
message="numba.generated_jit.*",
category=numba.NumbaDeprecationWarning)
warnings.filterwarnings("ignore",
message=".* 'nopython' .*",
category=numba.NumbaDeprecationWarning)
warnings.filterwarnings(
"ignore",
message="numba.generated_jit.*",
category=numba.NumbaDeprecationWarning,
)
warnings.filterwarnings(
"ignore", message=".* 'nopython' .*", category=numba.NumbaDeprecationWarning
)

# Project information
project = "HARK"
Expand Down Expand Up @@ -64,7 +66,7 @@
html_theme = "pydata_sphinx_theme"
html_static_path = ["_static"]
html_css_files = [
'override-nbsphinx-gallery.css',
"override-nbsphinx-gallery.css",
]

html_theme_options = {
Expand Down Expand Up @@ -95,7 +97,7 @@
"type": "local",
"attributes": {"target": "_blank"},
},
]
],
}

# Point to Econ-ARK repo for edit buttons
Expand Down
2 changes: 0 additions & 2 deletions Documentation/overview/ARKitecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ After you [installed](https://docs.econ-ark.org/guides/quick_start.html) and [cl
HARK's root directory contains six tool modules, [^1] each containing a variety of functions and classes that can be used in many economic models-- or even for mathematical purposes that have nothing to do with economics. Some of the tool modules are very sparely populated at this time, while others are quite large. We expect that all of these modules will grow considerably in the near future, as new tools are ''low hanging fruit'' for contribution to the project. [^2]

[^1]: The ''taxonomy'' of these modules is in flux; the functions described here could be combined into fewer modules or further divided by purpose.

[^2]: That is, as the foundational, building-block elements of HARK, new tools are not difficult to program and do not require extensive integration with many moving parts.

#### HARK.core
Expand Down Expand Up @@ -87,7 +86,6 @@ Methods for optimizing an objective function for the purposes of estimating a mo
By default, processes in Python are single-threaded, using only a single CPU core. The **_HARK.parallel_** module provides basic tools for using multiple CPU cores simultaneously, with minimal effort. [^4] In particular, it provides the function **_multiThreadCommands_**, which takes two arguments: a list of **_AgentType_**s and a list of commands as strings; each command should be a method of the **_AgentType_**s. The function simply distributes the **_AgentType_**s across threads on different cores and executes each command in order, returning no output (the **_AgentType_**s themselves are changed by running the commands). Equivalent results would be achieved by simply looping over each type and running each method in the list. Indeed, **_HARK.parallel_** also has a function called **_multiThreadCommandsFake_** that does just that, with identical syntax to **_multiThreadCommands_**; multithreading in HARK can thus be easily turned on and off. [^5] The module also has functions for a parallel implementation of the Nelder-Mead simplex algorithm, as described in Wiswall and Lee (2011). See [here](https://docs.econ-ark.org/reference/tools/parallel.html) for full documentation.

[^4]: **_HARK.parallel_** uses two packages that aren't included in the default distribution of Anaconda: **_joblib_** and **_dill_**; see [here](https://docs.econ-ark.org/guides/quick_start.html#using-hark-with-anaconda) for instructions on how to install them.

[^5]: In the future, **_HARK.parallel_** might be absorbed into **_HARK.core_** and **_HARK.estimation_**, particularly if **_joblib_** and **_dill_** become part of the standard Anaconda distribution.

### AgentType Class
Expand Down
2 changes: 1 addition & 1 deletion HARK/Calibration/Income/tests/test_IncomeTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_Cagetti(self):
age_max=age_max,
adjust_infl_to=adjust_infl_to,
start_year=start_year,
**spec
**spec,
)
MeanP = find_profile(params["PermGroFac"], params["P0"])

Expand Down
Loading

0 comments on commit ab14825

Please sign in to comment.