From d673eeca9fa052747e685362e0581130a9896d3e Mon Sep 17 00:00:00 2001 From: Alan Lujan Date: Tue, 19 Nov 2024 16:25:30 -0500 Subject: [PATCH] install cookie --- .copier-answers.yml | 12 + .git_archival.txt | 3 + .gitattributes | 1 + .github/CONTRIBUTING.md | 89 ++++++++ .github/dependabot.yml | 11 + .github/release.yml | 5 + .github/workflows/cd.yml | 60 +++++ .github/workflows/ci.yml | 71 ++++++ .gitignore | 292 +++++++----------------- .pre-commit-config.yaml | 91 +++++++- .readthedocs.yaml | 17 ++ LICENSE | 221 ++---------------- README.md | 243 +++++++++++++++----- docs/conf.py | 56 +++-- docs/example_notebooks/Include_list.txt | 28 +-- docs/{index_core.rst => index.rst} | 16 +- index.rst | 1 - noxfile.py | 107 +++++++++ pyproject.toml | 204 +++++++++++++---- src/HARK/__init__.py | 13 +- src/HARK/_version.pyi | 4 + src/HARK/py.typed | 0 tests/test_package.py | 9 + 23 files changed, 974 insertions(+), 580 deletions(-) create mode 100644 .copier-answers.yml create mode 100644 .git_archival.txt create mode 100644 .gitattributes create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/dependabot.yml create mode 100644 .github/release.yml create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .readthedocs.yaml rename docs/{index_core.rst => index.rst} (87%) delete mode 100644 index.rst create mode 100644 noxfile.py create mode 100644 src/HARK/_version.pyi create mode 100644 src/HARK/py.typed create mode 100644 tests/test_package.py diff --git a/.copier-answers.yml b/.copier-answers.yml new file mode 100644 index 000000000..7b50606ab --- /dev/null +++ b/.copier-answers.yml @@ -0,0 +1,12 @@ +# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY +_commit: 2024.08.19 +_src_path: gh:scientific-python/cookie +backend: hatch +email: econ-ark@jhuecon.org +full_name: Econ-ARK Team +license: MIT +org: econ-ark +project_name: HARK +project_short_description: Heterogeneous Agents Resources and toolKit +url: https://github.com/econ-ark/HARK +vcs: true diff --git a/.git_archival.txt b/.git_archival.txt new file mode 100644 index 000000000..7c5100942 --- /dev/null +++ b/.git_archival.txt @@ -0,0 +1,3 @@ +node: $Format:%H$ +node-date: $Format:%cI$ +describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..00a7b00c9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +.git_archival.txt export-subst diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 000000000..368750a6b --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,89 @@ +See the [Scientific Python Developer Guide][spc-dev-intro] for a detailed +description of best practices for developing scientific packages. + +[spc-dev-intro]: https://learn.scientific-python.org/development/ + +# Quick development + +The fastest way to start with development is to use nox. If you don't have nox, +you can use `pipx run nox` to run it without installing, or `pipx install nox`. +If you don't have pipx (pip for applications), then you can install with +`pip install pipx` (the only case were installing an application with regular +pip is reasonable). If you use macOS, then pipx and nox are both in brew, use +`brew install pipx nox`. + +To use, run `nox`. This will lint and test using every installed version of +Python on your system, skipping ones that are not installed. You can also run +specific jobs: + +```console +$ nox -s lint # Lint only +$ nox -s tests # Python tests +$ nox -s docs -- --serve # Build and serve the docs +$ nox -s build # Make an SDist and wheel +``` + +Nox handles everything for you, including setting up an temporary virtual +environment for each run. + +# Setting up a development environment manually + +You can set up a development environment by running: + +```bash +python3 -m venv .venv +source ./.venv/bin/activate +pip install -v -e .[dev] +``` + +If you have the +[Python Launcher for Unix](https://github.com/brettcannon/python-launcher), you +can instead do: + +```bash +py -m venv .venv +py -m install -v -e .[dev] +``` + +# Pre-commit + +You should prepare pre-commit, which will help you by checking that commits pass +required checks: + +```bash +pip install pre-commit # or brew install pre-commit on macOS +pre-commit install # Will install a pre-commit hook into the git repo +``` + +You can also/alternatively run `pre-commit run` (changes only) or +`pre-commit run --all-files` to check even without installing the hook. + +# Testing + +Use pytest to run the unit checks: + +```bash +pytest +``` + +# Coverage + +Use pytest-cov to generate coverage reports: + +```bash +pytest --cov=HARK +``` + +# Building docs + +You can build the docs using: + +```bash +nox -s docs +``` + +You can see a preview with: + +```bash +nox -s docs -- --serve +``` diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..6c4b36953 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + groups: + actions: + patterns: + - "*" diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 000000000..9d1e0987b --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,5 @@ +changelog: + exclude: + authors: + - dependabot + - pre-commit-ci diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 000000000..efc7d0612 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,60 @@ +name: CD + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + release: + types: + - published + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + # Many color libraries just need this to be set to any value, but at least + # one distinguishes color depth, where "3" -> "256-bit color". + FORCE_COLOR: 3 + +jobs: + dist: + name: Distribution build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: hynek/build-and-inspect-python-package@v2 + + publish: + needs: [dist] + name: Publish to PyPI + environment: pypi + permissions: + id-token: write + attestations: write + contents: read + runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'published' + + steps: + - uses: actions/download-artifact@v4 + with: + name: Packages + path: dist + + - name: Generate artifact attestation for sdist and wheel + uses: actions/attest-build-provenance@v1.4.1 + with: + subject-path: "dist/*" + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + # Remember to tell (test-)pypi about this repo before publishing + # Remove this line to publish to PyPI + repository-url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..98cc7c240 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,71 @@ +name: CI + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + # Many color libraries just need this to be set to any value, but at least + # one distinguishes color depth, where "3" -> "256-bit color". + FORCE_COLOR: 3 + +jobs: + pre-commit: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + - uses: pre-commit/action@v3.0.1 + with: + extra_args: --hook-stage manual --all-files + - name: Run PyLint + run: pipx run nox -s pylint -- --output-format=github + + checks: + name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }} + runs-on: ${{ matrix.runs-on }} + needs: [pre-commit] + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.13"] + runs-on: [ubuntu-latest, windows-latest, macos-14] + + include: + - python-version: "pypy-3.10" + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + allow-prereleases: true + + - name: Install package + run: python -m pip install .[test] + + - name: Test package + run: >- + python -m pytest -ra --cov --cov-report=xml --cov-report=term + --durations=20 + + - name: Upload coverage report + uses: codecov/codecov-action@v4.5.0 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 8e1d27dc0..25cf9a498 100644 --- a/.gitignore +++ b/.gitignore @@ -3,16 +3,11 @@ __pycache__/ *.py[cod] *$py.class -# Virtual Environments -venv/ -econ-ark/ - # C extensions *.so # Distribution / packaging .Python -env/ build/ develop-eggs/ dist/ @@ -24,9 +19,12 @@ lib64/ parts/ sdist/ var/ +wheels/ +share/python-wheels/ *.egg-info/ .installed.cfg *.egg +MANIFEST # PyInstaller # Usually these files are written by a python script from a template @@ -41,13 +39,17 @@ pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ +.nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml -*,cover +*.cover +*.py,cover .hypothesis/ +.pytest_cache/ +cover/ # Translations *.mo @@ -55,240 +57,102 @@ coverage.xml # Django stuff: *.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy # Sphinx documentation -docs/generated -docs/_build -docs/TractableBufferStockModel.rst -docs/MultithreadDemo.rst -docs/modules.rst -docs/ConsumerParameters.rst -docs/ConsPrefShockModel.rst -docs/ConsMarkovModel.rst -docs/ConsIndShockModel.rst -docs/ConsAggShockModel.rst -docs/StructEstimation.rst -docs/SetupSCFdata.rst -docs/EstimationParameters.rst -docs/SetupParamsCSTW.rst -docs/cstwMPC.rst -docs/FashionVictimParams.rst -docs/FashionVictimModel.rst -docs/HARKutilities.rst -docs/HARKsimulation.rst -docs/HARKparallel.rst -docs/HARKinterpolation.rst -docs/HARKestimation.rst -docs/HARKcore.rst -doc/_build/ -doc/generated/ +docs/_build/ # PyBuilder +.pybuilder/ target/ -#Ipython Notebook +# Jupyter Notebook .ipynb_checkpoints -#Windows files -Thumbs.db - -## Core latex/pdflated auxiliary files: -*.aux -*.lof -*.log -*.lot -*.fls -*.out -*.toc -*.fmt - -## Intermediate documents: -*.dvi -*-converted-to.* - -## Bibliography auxiliary files (bibtex/biblatex/biber): -*.bbl -*.bcf -*.blg -*-blx.aux -*-blx.bib -*.brf -*.run.xml - -## Files created by htlatex -*.4tc -*.tmp -*.xref - -## Build tool auxiliary files: -*.fdb_latexmk -*.synctex -*.synctex.gz -*.synctex.gz(busy) -*.pdfsync - -## Auxiliary and intermediate files from other packages: -# algorithms -*.alg -*.loa - -# achemso -acs-*.bib - -# amsthm -*.thm - -# beamer -*.nav -*.snm -*.vrb - -# cprotect -*.cpt - -#(e)ledmac/(e)ledpar -*.end -*.[1-9] -*.[1-9][0-9] -*.[1-9][0-9][0-9] -*.[1-9]R -*.[1-9][0-9]R -*.[1-9][0-9][0-9]R -*.eledsec[1-9] -*.eledsec[1-9]R -*.eledsec[1-9][0-9] -*.eledsec[1-9][0-9]R -*.eledsec[1-9][0-9][0-9] -*.eledsec[1-9][0-9][0-9]R - -# glossaries -*.acn -*.acr -*.glg -*.glo -*.gls - -# gnuplottex -*-gnuplottex-* - -# hyperref -*.brf - -# knitr -*-concordance.tex -*.tikz -*-tikzDictionary - -# listings -*.lol +# IPython +profile_default/ +ipython_config.py -# makeidx -*.idx -*.ilg -*.ind -*.ist +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version -# minitoc -*.maf -*.mtc -*.mtc[0-9] -*.mtc[1-9][0-9] +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock -# minted -_minted* -*.pyg +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ -# morewrites -*.mw +# Celery stuff +celerybeat-schedule +celerybeat.pid -# mylatexformat -*.fmt +# SageMath parsed files +*.sage.py -# nomencl -*.nlo - -# sagetex -*.sagetex.sage -*.sagetex.py -*.sagetex.scmd - -# sympy -*.sout -*.sympy -sympy-plots-for-*.tex/ - -#pdfcomment -*.upa -*.upb - -# pythontex -*.pytxcode -pythontex-filse-*/ - -# Texpad -*.texpadtmp +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ -# TikZ & PGF -*.dpth -*.md5 -*.auxlock +# Spyder project settings +.spyderproject +.spyproject -# todonotes -*.tdo +# Rope project settings +.ropeproject -# xindy -*.xdy +# mkdocs documentation +/site -# xypic precompiled matrices -*.xyc +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json -# WinEdt -*.bak -*.sav +# Pyre type checker +.pyre/ -# endfloat -*.ttt -*.fff +# pytype static type analyzer +.pytype/ -# Latexian -TSWLatexianTemp +# Cython debug symbols +cython_debug/ -# Files for initializing subfolders -# Filename.md +# setuptools_scm +src/*/_version.py -# Version that generates html -Web +# ruff +.ruff_cache/ -# Mac system files +# OS specific stuff .DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db -# Emacs automatic backup and hash files +# Common editor files *~ -\#*# - -# Vim swap files *.swp - -# Autogenerated equations -eq - -# Emacs -*.el - -# Particular user scratchwork directories -nate-notes/ - -*_region_*.* - -# VSCode -settings.json -.idea - -# Spyder project settings -.spyderproject -spyproject -.spyproject - -# 20240608: CDC added *private* to avoid accidentally uploading private material -*private* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b8c2caa44..5f1b88c78 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,20 +1,91 @@ -exclude: docs/example_notebooks/ +ci: + autoupdate_commit_msg: "chore: update pre-commit hooks" + autofix_commit_msg: "style: pre-commit fixes" + +exclude: ^.cruft.json|.copier-answers.yml$|docs/example_notebooks/ repos: + - repo: https://github.com/adamchainz/blacken-docs + rev: "1.18.0" + hooks: + - id: blacken-docs + additional_dependencies: [black==24.*] + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: "v4.6.0" + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: name-tests-test + args: ["--pytest-test-first"] + - id: requirements-txt-fixer + - id: trailing-whitespace + + - 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/rbubley/mirrors-prettier + rev: "v3.3.3" + hooks: + - id: prettier + types_or: [yaml, markdown, html, css, scss, javascript, json] + args: [--prose-wrap=always] + - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.2 + rev: "v0.6.1" hooks: - id: ruff types_or: [python, pyi, jupyter] - args: - - --fix + args: ["--fix"] - id: ruff-format types_or: [python, pyi, jupyter] - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + # - repo: https://github.com/pre-commit/mirrors-mypy + # rev: "v1.11.1" + # hooks: + # - id: mypy + # files: src|tests + # args: [] + # additional_dependencies: + # - pytest + + - repo: https://github.com/codespell-project/codespell + rev: "v2.3.0" hooks: - - id: end-of-file-fixer - - id: trailing-whitespace - - id: requirements-txt-fixer - exclude: ^examples/ + - id: codespell + + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: "v0.10.0.1" + hooks: + - id: shellcheck + + - repo: local + hooks: + - id: disallow-caps + name: Disallow improper capitalization + language: pygrep + entry: PyBind|Numpy|Cmake|CCache|Github|PyTest + exclude: .pre-commit-config.yaml + + - repo: https://github.com/abravalheri/validate-pyproject + rev: "v0.19" + hooks: + - id: validate-pyproject + additional_dependencies: ["validate-pyproject-schema-store[all]"] + + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: "0.29.1" + hooks: + - id: check-dependabot + - id: check-github-workflows + - id: check-readthedocs diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 000000000..67c194c82 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,17 @@ +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +version: 2 + +build: + os: ubuntu-22.04 + tools: + python: "3.12" + commands: + - asdf plugin add uv + - asdf install uv latest + - asdf global uv latest + - uv venv + - uv pip install .[docs] + - .venv/bin/python -m sphinx -T -b html -d docs/_build/doctrees -D + language=en docs $READTHEDOCS_OUTPUT/html diff --git a/LICENSE b/LICENSE index d64569567..bc78a2f35 100644 --- a/LICENSE +++ b/LICENSE @@ -1,202 +1,19 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Copyright 2024 Econ-ARK Team + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 5004e1a92..276a1d664 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,15 @@ # Heterogeneous Agents Resources and toolKit (HARK) -HARK is a toolkit for the structural modeling of economic choices of optimizing and non-optimizing heterogeneous agents. For more information on using HARK, see the [Econ-ARK Website](https://econ-ark.org). +HARK is a toolkit for the structural modeling of economic choices of optimizing +and non-optimizing heterogeneous agents. For more information on using HARK, see +the [Econ-ARK Website](https://econ-ark.org). -The Econ-ARK project is fiscally sponsored by [NumFOCUS](https://numfocus.org/). Consider making a [tax-deductible donation](https://numfocus.org/donate-to-econ-ark) to help the project pay for developer time, professional services, travel, workshops, and a variety of other needs. +The Econ-ARK project is fiscally sponsored by [NumFOCUS](https://numfocus.org/). +Consider making a +[tax-deductible donation](https://numfocus.org/donate-to-econ-ark) to help the +project pay for developer time, professional services, travel, workshops, and a +variety of other needs.
@@ -48,26 +54,32 @@ The Econ-ARK project is fiscally sponsored by [NumFOCUS](https://numfocus.org/). # Questions/Comments/Help -We have a [Gitter](https://gitter.im) Econ-ARK [community](https://gitter.im/econ-ark/community). +We have a [Gitter](https://gitter.im) Econ-ARK +[community](https://gitter.im/econ-ark/community). # Table of Contents -- [Install](#install) -- [Usage](#usage) -- [Citation](#citation) -- [Support](#support) -- [Release Types](#release-types) -- [Documentation](#Documentation) -- [Introduction](#introduction) - - [For Students: A Gentle Introduction to Hark](#for-students-a-gentle-introduction-to-hark) - - [For Economists: Structural Modeling with Hark](#for-economists-structural-modeling-with-hark) - - [For Computational Economics Developers](#for-computational-economics-developers) -- [Contributing to HARK](#contributing-to-hark) -- [Disclaimer](#disclaimer) +- [Heterogeneous Agents Resources and toolKit (HARK)](#heterogeneous-agents-resources-and-toolkit-hark) +- [Questions/Comments/Help](#questionscommentshelp) +- [Table of Contents](#table-of-contents) + - [Install](#install) + - [Usage](#usage) + - [Citation](#citation) + - [Support](#support) + - [Release Types](#release-types) + - [Documentation](#documentation) + - [Introduction](#introduction) + - [For Students: A Gentle Introduction to HARK](#for-students-a-gentle-introduction-to-hark) + - [For Economists: Structural Modeling with HARK](#for-economists-structural-modeling-with-hark) + - [For Computational Economics Developers](#for-computational-economics-developers) + - [Contributing to HARK](#contributing-to-hark) + - [Disclaimer](#disclaimer) +- [HARK](#hark) ## Install -Install from [Anaconda Cloud](https://docs.anaconda.com/anaconda/install/) by running: +Install from [Anaconda Cloud](https://docs.anaconda.com/anaconda/install/) by +running: `conda install -c conda-forge econ-ark` @@ -77,7 +89,8 @@ Install from [PyPi](https://pypi.org/) by running: ## Usage -We start with almost the simplest possible consumption model: A consumer with CRRA utility +We start with almost the simplest possible consumption model: A consumer with +CRRA utility
@@ -85,7 +98,8 @@ We start with almost the simplest possible consumption model: A consumer with CR has perfect foresight about everything except the (stochastic) date of death. -The agent's problem can be written in [Bellman form](https://en.wikipedia.org/wiki/Bellman_equation) as: +The agent's problem can be written in +[Bellman form](https://en.wikipedia.org/wiki/Bellman_equation) as:
@@ -93,7 +107,9 @@ The agent's problem can be written in [Bellman form](https://en.wikipedia.org/wi
-To model the above problem, start by importing the `PerfForesightConsumerType` model from the appropriate `HARK` module then create an agent instance using the appropriate paramaters: +To model the above problem, start by importing the `PerfForesightConsumerType` +model from the appropriate `HARK` module then create an agent instance using the +appropriate paramaters: ```python import HARK @@ -115,40 +131,53 @@ PF_params = { PFexample = PerfForesightConsumerType(**PF_params) ``` -Once the model is created, ask the the agent to solve the problem with `.solve()`: +Once the model is created, ask the the agent to solve the problem with +`.solve()`: ```python # Tell the agent to solve the problem PFexample.solve() ``` -Solving the problem populates the agent's `.solution` list attribute with solutions to each period of the problem. In the case of an infinite horizon model, there is just one element in the list, at **index-zero**. +Solving the problem populates the agent's `.solution` list attribute with +solutions to each period of the problem. In the case of an infinite horizon +model, there is just one element in the list, at **index-zero**. -You can retrieve the solution's consumption function from the `.cFunc` attribute: +You can retrieve the solution's consumption function from the `.cFunc` +attribute: ```python # Retrieve the consumption function of the solution PFexample.solution[0].cFunc ``` -Or you can retrieve the solved value for human wealth normalized by permanent income from the solution's `.hNrm` attribute: +Or you can retrieve the solved value for human wealth normalized by permanent +income from the solution's `.hNrm` attribute: ```python # Retrieve the solved value for human wealth normalized by permanent income PFexample.solution[0].hNrm ``` -For a detailed explanation of the above example please see the demo notebook [_A Gentle Introduction to HARK_](https://docs.econ-ark.org/examples/Gentle-Intro/Gentle-Intro-To-HARK.html). +For a detailed explanation of the above example please see the demo notebook +[_A Gentle Introduction to HARK_](https://docs.econ-ark.org/examples/Gentle-Intro/Gentle-Intro-To-HARK.html). -For more examples please visit the [examples](https://docs.econ-ark.org/docs/overview/index.html) section of the [documentation](https://docs.econ-ark.org/index.html), or the [econ-ark/DemARK](https://github.com/econ-ark/DemARK) repository. +For more examples please visit the +[examples](https://docs.econ-ark.org/docs/overview/index.html) section of the +[documentation](https://docs.econ-ark.org/index.html), or the +[econ-ark/DemARK](https://github.com/econ-ark/DemARK) repository. ## Citation -If using Econ-ARK in your work or research please [cite our Digital Object Identifier](https://doi.org/10.5281/zenodo.1332015) or copy the BibTex below. +If using Econ-ARK in your work or research please +[cite our Digital Object Identifier](https://doi.org/10.5281/zenodo.1332015) or +copy the BibTex below. [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1332015.svg)](https://doi.org/10.5281/zenodo.1332015) -[1] Carroll, Christopher D, Palmer, Nathan, White, Matthew N., Kazil, Jacqueline, Low, David C, & Kaufman, Alexander. (2017, October 3). _econ-ark/HARK_ +[1] Carroll, Christopher D, Palmer, Nathan, White, Matthew N., Kazil, +Jacqueline, Low, David C, & Kaufman, Alexander. (2017, October 3). +_econ-ark/HARK_ **BibText** @@ -164,77 +193,173 @@ If using Econ-ARK in your work or research please [cite our Digital Object Ident } ``` -For more on acknowledging Econ-ARK [visit our website](https://econ-ark.org/acknowledging). +For more on acknowledging Econ-ARK +[visit our website](https://econ-ark.org/acknowledging). ## Support -Looking for help? Please open a [GitHub issue](https://github.com/econ-ark/HARK/issues/new) or reach out to us through the gitter [community](https://gitter.im/econ-ark/community). +Looking for help? Please open a +[GitHub issue](https://github.com/econ-ark/HARK/issues/new) or reach out to us +through the gitter [community](https://gitter.im/econ-ark/community). ## Release Types -- **Current**: Under active development. Code for the Current release is in the branch for its major version number (for example, v0.10.x). -- **Development**: Under active development. Code for the Current release is in the development. +- **Current**: Under active development. Code for the Current release is in the + branch for its major version number (for example, v0.10.x). +- **Development**: Under active development. Code for the Current release is in + the development. -Current releases follow [Semantic Versioning](https://semver.org/). For more information please see the [Release documentation](https://github.com/econ-ark/OverARK/wiki/Release-Management). +Current releases follow [Semantic Versioning](https://semver.org/). For more +information please see the +[Release documentation](https://github.com/econ-ark/OverARK/wiki/Release-Management). ## Documentation -Documentation for the latest release is at [docs.econ-ark.org](https://docs.econ-ark.org/). +Documentation for the latest release is at +[docs.econ-ark.org](https://docs.econ-ark.org/). ## Introduction ### For Students: A Gentle Introduction to HARK -Most of what economists have done so far with 'big data' has been like what Kepler did with astronomical data: Organizing the data, and finding patterns and regularities and interconnections. +Most of what economists have done so far with 'big data' has been like what +Kepler did with astronomical data: Organizing the data, and finding patterns and +regularities and interconnections. -An alternative approach called 'structural modeling' aims to do, for economic data, what Newton did for astronomical data: Provide a deep and rigorous mathematical (or computational) framework that distills the essence of the underlying behavior that produces the 'big data.' +An alternative approach called 'structural modeling' aims to do, for economic +data, what Newton did for astronomical data: Provide a deep and rigorous +mathematical (or computational) framework that distills the essence of the +underlying behavior that produces the 'big data.' -The notebook [_A Gentle Introduction to HARK_](https://mybinder.org/v2/gh/econ-ark/DemARK/master?filepath=notebooks/Gentle-Intro-To-HARK-PerfForesightCRRA.ipynb) details how you can easily utilize our toolkit for structural modeling. Starting with a simple [Perfect Foresight Model](https://en.wikipedia.org/wiki/Rational_expectations) we solve an agent problem, then experiment with adding [income shocks]() and changing constructed attributes. +The notebook +[_A Gentle Introduction to HARK_](https://mybinder.org/v2/gh/econ-ark/DemARK/master?filepath=notebooks/Gentle-Intro-To-HARK-PerfForesightCRRA.ipynb) +details how you can easily utilize our toolkit for structural modeling. Starting +with a simple +[Perfect Foresight Model](https://en.wikipedia.org/wiki/Rational_expectations) +we solve an agent problem, then experiment with adding +[income shocks]() and changing +constructed attributes. ### For Economists: Structural Modeling with HARK -Dissatisfaction with the ability of Representative Agent models to answer important questions raised by the Great Recession has led to a strong movement in the macroeconomics literature toward 'Heterogeneous Agent' models, in which microeconomic agents (consumers; firms) solve a structural problem calibrated to match microeconomic data; aggregate outcomes are derived by explicitly simulating the equilibrium behavior of populations solving such models. - -The same kinds of modeling techniques are also gaining popularity among microeconomists, in areas ranging from labor economics to industrial organization. In both macroeconomics and structural micro, the chief barrier to the wide adoption of these techniques has been that programming a structural model has, until now, required a great deal of specialized knowledge and custom software development. - -HARK provides a robust, well-designed, open-source toolkit for building such models much more efficiently than has been possible in the past. - -Our [_DCEGM Upper Envelope_](https://mybinder.org/v2/gh/econ-ark/DemARK/master?filepath=notebooks%2FDCEGM-Upper-Envelope.ipynb) notebook illustrates using HARK to replicate the [Iskhakov, Jørgensen, Rust, and Schjerning paper](https://onlinelibrary.wiley.com/doi/abs/10.3982/QE643) for solving the discrete-continuous retirement saving problem. - -The notebook [_Making Structural Estimates From Empirical Results_](https://mybinder.org/v2/gh/econ-ark/DemARK/master?filepath=notebooks%2FStructural-Estimates-From-Empirical-MPCs-Fagereng-et-al.ipynb) is another demonstration of using HARK to conduct a quick structural estimation based on Table 9 of [_MPC Heterogeneity and Household Balance Sheets_ by Fagereng, Holm, and Natvik](https://www.ssb.no/en/forskning/discussion-papers/_attachment/286054?_ts=158af859c98). +Dissatisfaction with the ability of Representative Agent models to answer +important questions raised by the Great Recession has led to a strong movement +in the macroeconomics literature toward 'Heterogeneous Agent' models, in which +microeconomic agents (consumers; firms) solve a structural problem calibrated to +match microeconomic data; aggregate outcomes are derived by explicitly +simulating the equilibrium behavior of populations solving such models. + +The same kinds of modeling techniques are also gaining popularity among +microeconomists, in areas ranging from labor economics to industrial +organization. In both macroeconomics and structural micro, the chief barrier to +the wide adoption of these techniques has been that programming a structural +model has, until now, required a great deal of specialized knowledge and custom +software development. + +HARK provides a robust, well-designed, open-source toolkit for building such +models much more efficiently than has been possible in the past. + +Our +[_DCEGM Upper Envelope_](https://mybinder.org/v2/gh/econ-ark/DemARK/master?filepath=notebooks%2FDCEGM-Upper-Envelope.ipynb) +notebook illustrates using HARK to replicate the +[Iskhakov, Jørgensen, Rust, and Schjerning paper](https://onlinelibrary.wiley.com/doi/abs/10.3982/QE643) +for solving the discrete-continuous retirement saving problem. + +The notebook +[_Making Structural Estimates From Empirical Results_](https://mybinder.org/v2/gh/econ-ark/DemARK/master?filepath=notebooks%2FStructural-Estimates-From-Empirical-MPCs-Fagereng-et-al.ipynb) +is another demonstration of using HARK to conduct a quick structural estimation +based on Table 9 of +[_MPC Heterogeneity and Household Balance Sheets_ by Fagereng, Holm, and Natvik](https://www.ssb.no/en/forskning/discussion-papers/_attachment/286054?_ts=158af859c98). ### For Computational Economics Developers -HARK provides a modular and extensible open-source toolkit for solving heterogeneous-agent partial-and general-equilibrium structural models. The code for such models has always been handcrafted, idiosyncratic, poorly documented, and sometimes not generously shared from leading researchers to outsiders. The result being that it can take years for a new researcher to become proficient. By building an integrated system from the bottom up using object-oriented programming techniques and other tools, we aim to provide a platform that will become a focal point for people using such models. - -HARK is written in Python, making significant use of libraries such as numpy and scipy which offer a wide array of mathematical and statistical functions and tools. Our modules are generally categorized into Tools (mathematical functions and techniques), Models (particular economic models and solvers) and Applications (use of tools to simulate an economic phenomenon). - -For more information on how you can create your own Models or use Tools and Model to create Applications please see the [documentation](https://docs.econ-ark.org/docs/guides/quick_start.html#for-other-developers-of-software-for-computational-economics) +HARK provides a modular and extensible open-source toolkit for solving +heterogeneous-agent partial-and general-equilibrium structural models. The code +for such models has always been handcrafted, idiosyncratic, poorly documented, +and sometimes not generously shared from leading researchers to outsiders. The +result being that it can take years for a new researcher to become proficient. +By building an integrated system from the bottom up using object-oriented +programming techniques and other tools, we aim to provide a platform that will +become a focal point for people using such models. + +HARK is written in Python, making significant use of libraries such as numpy and +scipy which offer a wide array of mathematical and statistical functions and +tools. Our modules are generally categorized into Tools (mathematical functions +and techniques), Models (particular economic models and solvers) and +Applications (use of tools to simulate an economic phenomenon). + +For more information on how you can create your own Models or use Tools and +Model to create Applications please see the +[documentation](https://docs.econ-ark.org/docs/guides/quick_start.html#for-other-developers-of-software-for-computational-economics) ### Contributing to HARK -**We want contributing to Econ-ARK to be fun, enjoyable, and educational for anyone, and everyone.** +**We want contributing to Econ-ARK to be fun, enjoyable, and educational for +anyone, and everyone.** -Contributions go far beyond pull requests and commits. Although we love giving you the opportunity to put your stamp on HARK, we are also thrilled to receive a variety of other contributions including: +Contributions go far beyond pull requests and commits. Although we love giving +you the opportunity to put your stamp on HARK, we are also thrilled to receive a +variety of other contributions including: - Documentation updates, enhancements, designs, or bugfixes - Spelling or grammar fixes - REAME.md corrections or redesigns - Adding unit, or functional tests -- [Triaging GitHub issues](https://github.com/econ-ark/HARK/issues?utf8=%E2%9C%93&q=label%3A%E2%80%9DTag%3A+Triage+Needed%E2%80%9D+) -- e.g. pointing out the relevant files, checking for reproducibility -- [Searching for #econ-ark on twitter](https://twitter.com/search?q=econ-ark) and helping someone else who needs help -- Answering questions from StackOverflow tagged with [econ-ark](https://stackoverflow.com/questions/tagged/econ-ark) +- [Triaging GitHub issues](https://github.com/econ-ark/HARK/issues?utf8=%E2%9C%93&q=label%3A%E2%80%9DTag%3A+Triage+Needed%E2%80%9D+) + -- e.g. pointing out the relevant files, checking for reproducibility +- [Searching for #econ-ark on twitter](https://twitter.com/search?q=econ-ark) + and helping someone else who needs help +- Answering questions from StackOverflow tagged with + [econ-ark](https://stackoverflow.com/questions/tagged/econ-ark) - Teaching others how to contribute to HARK - Blogging, speaking about, or creating tutorials about HARK - Helping others in our mailing list -If you are worried or don’t know how to start, you can always reach out to us through the gitter [community](https://gitter.im/econ-ark/community)(#tsc-technical-steering-committee) or simply submit [an issue](https://github.com/econ-ark/HARK/issues/new) and a member can help give you guidance! +If you are worried or don’t know how to start, you can always reach out to us +through the gitter +[community](https://gitter.im/econ-ark/community)(#tsc-technical-steering-committee) +or simply submit [an issue](https://github.com/econ-ark/HARK/issues/new) and a +member can help give you guidance! -To install for development see the [Quickstart Guide](https://docs.econ-ark.org/docs/guides/installation.html). +To install for development see the +[Quickstart Guide](https://docs.econ-ark.org/docs/guides/installation.html). -For more information on contributing to HARK please see [the contributing guide](https://docs.econ-ark.org/docs/guides/contributing.html). +For more information on contributing to HARK please see +[the contributing guide](https://docs.econ-ark.org/docs/guides/contributing.html). This is the guide that collaborators follow in maintaining the Econ-ARK project. ## Disclaimer -This is a beta version of HARK. The code has not been extensively tested as it should be. We hope it is useful, but there are absolutely no guarantees (expressed or implied) that it works or will do what you want. Use at your own risk. And please, let us know if you find bugs by posting an issue to [the GitHub page](https://github.com/econ-ark/HARK)! +This is a beta version of HARK. The code has not been extensively tested as it +should be. We hope it is useful, but there are absolutely no guarantees +(expressed or implied) that it works or will do what you want. Use at your own +risk. And please, let us know if you find bugs by posting an issue to +[the GitHub page](https://github.com/econ-ark/HARK)! + +# HARK + +[![Actions Status][actions-badge]][actions-link] +[![Documentation Status][rtd-badge]][rtd-link] + +[![PyPI version][pypi-version]][pypi-link] +[![Conda-Forge][conda-badge]][conda-link] +[![PyPI platforms][pypi-platforms]][pypi-link] + +[![GitHub Discussion][github-discussions-badge]][github-discussions-link] + + + + +[actions-badge]: https://github.com/econ-ark/HARK/workflows/CI/badge.svg +[actions-link]: https://github.com/econ-ark/HARK/actions +[conda-badge]: https://img.shields.io/conda/vn/conda-forge/HARK +[conda-link]: https://github.com/conda-forge/HARK-feedstock +[github-discussions-badge]: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github +[github-discussions-link]: https://github.com/econ-ark/HARK/discussions +[pypi-link]: https://pypi.org/project/HARK/ +[pypi-platforms]: https://img.shields.io/pypi/pyversions/HARK +[pypi-version]: https://img.shields.io/pypi/v/HARK +[rtd-badge]: https://readthedocs.org/projects/HARK/badge/?version=latest +[rtd-link]: https://HARK.readthedocs.io/en/latest/?badge=latest + + diff --git a/docs/conf.py b/docs/conf.py index bcab7bd01..37c217bf5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,3 +1,6 @@ +from __future__ import annotations + +import importlib.metadata import warnings from datetime import date import os @@ -20,9 +23,9 @@ # Project information project = "HARK" -copyright = f"{date.today().year}, Econ-ARK team" -author = "Econ-ARK team" -version = release = "latest" +copyright = f"{date.today().year}, Econ-ARK Team" +author = "Econ-ARK Team" +version = release = importlib.metadata.version("hark") # General configuration extensions = [ @@ -42,24 +45,25 @@ "myst_parser", "sphinx_copybutton", "sphinx_design", + "sphinx_autodoc_typehints", ] -include_patterns = [ - "docs**", - "index.rst", -] # Makes sure that only the file we want documented get documented +source_suffix = [".rst", ".md"] +# Makes sure that only the file we want documented get documented +include_patterns = ["**", "index.rst"] +# Adds example notebooks with open(os.path.join(dir, "example_notebooks", "Include_list.txt"), "r") as file: include_patterns += file.readlines() -include_patterns = [ - i.replace("\n", "") for i in include_patterns -] # Adds example notebooks - +include_patterns = [i.replace("\n", "") for i in include_patterns] +# Prevents sphinx from getting confused exclude_patterns = [ - "docs/_build", - "docs/Thumbs.db", - "docs/.DS_Store", - "docs/NARK", - "docs/index_core.rst", # Prevents sphinx from getting confused + "_build", + "**.ipynb_checkpoints", + "Thumbs.db", + ".DS_Store", + ".env", + ".venv", + "NARK", ] napoleon_custom_sections = [ @@ -79,11 +83,6 @@ pygments_style = "sphinx" -source_suffix = [ - ".rst", - ".md", -] - # HTML writer configuration html_theme = "pydata_sphinx_theme" html_static_path = [] @@ -137,9 +136,9 @@
Download notebook.
""" -myst_enable_extensions = [ - "colon_fence", -] + +myst_enable_extensions = ["colon_fence"] + # Point to Econ-ARK repo for edit buttons html_context = { "github_url": "https://github.com", @@ -159,9 +158,16 @@ # sphinx.ext.intersphinx configuration intersphinx_mapping = { - "python": ("https://docs.python.org/3/", None), + "python": ("https://docs.python.org/3", None), } +nitpick_ignore = [ + ("py:class", "_io.StringIO"), + ("py:class", "_io.BytesIO"), +] + +always_document_param_types = True + # sphinx.ext.autodoc configuration autodoc_default_flags = ["members"] # must add outside ']' bracket diff --git a/docs/example_notebooks/Include_list.txt b/docs/example_notebooks/Include_list.txt index 68332db4f..f8e151761 100644 --- a/docs/example_notebooks/Include_list.txt +++ b/docs/example_notebooks/Include_list.txt @@ -1,14 +1,14 @@ -examples/Gentle-Intro/Gentle-Intro-To-HARK.ipynb -examples/LifecycleModel/Cycles_tutorial.ipynb -examples/ConsIndShockModel/PerfForesightConsumerType.ipynb -examples/ConsIndShockModel/IndShockConsumerType.ipynb -examples/ConsIndShockModel/KinkedRconsumerType.ipynb -examples/ConsPortfolioModel/example_ConsPortfolioModel.ipynb -examples/GenIncProcessModel/GenIncProcessModel.ipynb -examples/LifecycleModel/LifecycleModel.ipynb -examples/HowWeSolveIndShockConsumerType/HowWeSolveIndShockConsumerType.ipynb -examples/Journeys/Journey-PhD.ipynb -examples/ConsNewKeynesianModel/Transition_Matrix_Example.ipynb -examples/ConsNewKeynesianModel/Jacobian_Example.ipynb -examples/ConsNewKeynesianModel/KS-HARK-presentation.ipynb -examples/ConsNewKeynesianModel/SSJ_example.ipynb +../examples/Gentle-Intro/Gentle-Intro-To-HARK.ipynb +../examples/LifecycleModel/Cycles_tutorial.ipynb +../examples/ConsIndShockModel/PerfForesightConsumerType.ipynb +../examples/ConsIndShockModel/IndShockConsumerType.ipynb +../examples/ConsIndShockModel/KinkedRconsumerType.ipynb +../examples/ConsPortfolioModel/example_ConsPortfolioModel.ipynb +../examples/GenIncProcessModel/GenIncProcessModel.ipynb +../examples/LifecycleModel/LifecycleModel.ipynb +../examples/HowWeSolveIndShockConsumerType/HowWeSolveIndShockConsumerType.ipynb +../examples/Journeys/Journey-PhD.ipynb +../examples/ConsNewKeynesianModel/Transition_Matrix_Example.ipynb +../examples/ConsNewKeynesianModel/Jacobian_Example.ipynb +../examples/ConsNewKeynesianModel/KS-HARK-presentation.ipynb +../examples/ConsNewKeynesianModel/SSJ_example.ipynb diff --git a/docs/index_core.rst b/docs/index.rst similarity index 87% rename from docs/index_core.rst rename to docs/index.rst index ccad31e2c..9a495ab5b 100644 --- a/docs/index_core.rst +++ b/docs/index.rst @@ -5,13 +5,13 @@ Econ-ARK documentation -- HARK :maxdepth: 1 :hidden: - Guides - Overview & Examples - Reference + Guides + Overview & Examples + Reference **Useful links**: -:doc:`Install HARK ` | +:doc:`Install HARK ` | `Source Repository `__ | `Issues & Ideas `__ @@ -44,7 +44,7 @@ you might want to look at the `DemARK +++ - .. button-ref:: docs/guides/quick_start + .. button-ref:: guides/quick_start :ref-type: doc :color: info :click-parent: @@ -63,7 +63,7 @@ you might want to look at the `DemARK +++ - .. button-ref:: docs/overview/index + .. button-ref:: overview/index :ref-type: doc :color: info :click-parent: @@ -83,7 +83,7 @@ you might want to look at the `DemARK +++ - .. button-ref:: docs/reference/index + .. button-ref:: reference/index :ref-type: doc :color: info :click-parent: @@ -105,7 +105,7 @@ you might want to look at the `DemARK +++ - .. button-ref:: docs/guides/contributing + .. button-ref:: guides/contributing :ref-type: doc :color: info :click-parent: diff --git a/index.rst b/index.rst deleted file mode 100644 index 64e4dca2b..000000000 --- a/index.rst +++ /dev/null @@ -1 +0,0 @@ -.. include:: docs/index_core.rst diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 000000000..a9046471e --- /dev/null +++ b/noxfile.py @@ -0,0 +1,107 @@ +from __future__ import annotations + +import argparse +import shutil +from pathlib import Path + +import nox + +DIR = Path(__file__).parent.resolve() + +nox.needs_version = ">=2024.3.2" +nox.options.sessions = ["lint", "pylint", "tests"] +nox.options.default_venv_backend = "uv|virtualenv" + + +@nox.session +def lint(session: nox.Session) -> None: + """ + Run the linter. + """ + session.install("pre-commit") + session.run( + "pre-commit", "run", "--all-files", "--show-diff-on-failure", *session.posargs + ) + + +@nox.session +def pylint(session: nox.Session) -> None: + """ + Run PyLint. + """ + # This needs to be installed into the package environment, and is slower + # than a pre-commit check + session.install(".", "pylint>=3.2") + session.run("pylint", "hark", *session.posargs) + + +@nox.session +def tests(session: nox.Session) -> None: + """ + Run the unit and regular tests. + """ + session.install(".[test]") + session.run("pytest", *session.posargs) + + +@nox.session(reuse_venv=True) +def docs(session: nox.Session) -> None: + """ + Build the docs. Pass --non-interactive to avoid serving. First positional argument is the target directory. + """ + + parser = argparse.ArgumentParser() + parser.add_argument( + "-b", dest="builder", default="html", help="Build target (default: html)" + ) + parser.add_argument("output", nargs="?", help="Output directory") + args, posargs = parser.parse_known_args(session.posargs) + serve = args.builder == "html" and session.interactive + + session.install("-e.[docs]", "sphinx-autobuild") + + shared_args = ( + "-n", # nitpicky mode + "-T", # full tracebacks + f"-b={args.builder}", + "docs", + args.output or f"docs/_build/{args.builder}", + *posargs, + ) + + if serve: + session.run("sphinx-autobuild", "--open-browser", *shared_args) + else: + session.run("sphinx-build", "--keep-going", *shared_args) + + +@nox.session +def build_api_docs(session: nox.Session) -> None: + """ + Build (regenerate) API docs. + """ + + session.install("sphinx") + session.run( + "sphinx-apidoc", + "-o", + "docs/api/", + "--module-first", + "--no-toc", + "--force", + "src/hark", + ) + + +@nox.session +def build(session: nox.Session) -> None: + """ + Build an SDist and wheel. + """ + + build_path = DIR.joinpath("build") + if build_path.exists(): + shutil.rmtree(build_path) + + session.install("build") + session.run("python", "-m", "build") diff --git a/pyproject.toml b/pyproject.toml index e156cda8d..4e47daf31 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,61 +1,173 @@ [build-system] -requires = ["setuptools>=61.2", "setuptools_scm[toml]>=6.2"] -build-backend = "setuptools.build_meta" +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" + [project] -name = "econ-ark" -version = "0.15.1" -authors = [{name = "Econ-ARK team", email = "econ-ark@jhuecon.org"}] -classifiers = [ - "Development Status :: 3 - Alpha", - "Environment :: Console", - "Intended Audience :: Developers", - "Intended Audience :: Financial and Insurance Industry", - "Intended Audience :: Science/Research", - "Topic :: Scientific/Engineering", - "Topic :: Scientific/Engineering :: Mathematics", - "Topic :: Other/Nonlisted Topic", - "Natural Language :: English", - "Operating System :: OS Independent", - "License :: OSI Approved :: Apache Software License", - "License :: OSI Approved", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", -] -description = "Heterogenous Agents Resources & toolKit" +name = "HARK" +authors = [ + { name = "Econ-ARK Team", email = "econ-ark@jhuecon.org" }, +] +description = "Heterogeneous Agents Resources and toolKit" keywords = ["economics", "modelling", "modeling", "heterogeneity"] +readme = "README.md" +license.file = "LICENSE" requires-python = ">=3.10" -dynamic = ["dependencies", "optional-dependencies"] - - -[tool.setuptools.dynamic.dependencies] -file = "requirements/base.txt" +classifiers = [ + "Development Status :: 3 - Alpha", + "Environment :: Console", + "Intended Audience :: Financial and Insurance Industry", + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", + "License :: OSI Approved", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Mathematics", + "Topic :: Other/Nonlisted Topic", + "Typing :: Typed", +] +dynamic = ["version"] +dependencies = [] -[tool.setuptools.dynamic.optional-dependencies] -dev.file = "requirements/dev.txt" -doc.file = "requirements/doc.txt" +[project.optional-dependencies] +test = [ + "pytest >=6", + "pytest-cov >=3", +] +dev = [ + "pytest >=6", + "pytest-cov >=3", +] +docs = [ + "sphinx>=7.0", + "myst_parser>=0.13", + "sphinx_copybutton", + "sphinx_autodoc_typehints", + "furo>=2023.08.17", + # extension requirements + "ipython", # for the Pygments lexer + "myst-parser>=2", + "nbsphinx>=0.8", + # theme requirements + "pydata-sphinx-theme", + "sphinx>=6.1", + "sphinx-copybutton", + "sphinx-design", + "numpy", + "pandas" +] [project.urls] Homepage = "https://github.com/econ-ark/HARK" -"Bug Reports" = "https://github.com/econ-ark/HARK/issues" Documentation = "https://econ-ark.github.io/HARK" +"Bug Tracker" = "https://github.com/econ-ark/HARK/issues" +Discussions = "https://github.com/econ-ark/HARK/discussions" +Changelog = "https://github.com/econ-ark/HARK/releases" + + +[tool.hatch] +version.source = "vcs" +build.hooks.vcs.version-file = "src/HARK/_version.py" + +[tool.hatch.envs.default] +features = ["test"] +scripts.test = "pytest {args}" -[project.license] -file = "LICENSE" -[project.readme] -file = "README.md" -content-type = "text/markdown" +[tool.pytest.ini_options] +minversion = "6.0" +addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"] +xfail_strict = true +filterwarnings = [ + "error", +] +log_cli_level = "INFO" +testpaths = [ + "tests", +] + + +[tool.coverage] +run.source = ["HARK"] +report.exclude_also = [ + '\.\.\.', + 'if typing.TYPE_CHECKING:', +] + +[tool.mypy] +files = ["src", "tests"] +python_version = "3.10" +warn_unused_configs = true +strict = true +enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] +warn_unreachable = true +disallow_untyped_defs = false +disallow_incomplete_defs = false + +[[tool.mypy.overrides]] +module = "HARK.*" +disallow_untyped_defs = true +disallow_incomplete_defs = true -[tool.setuptools.packages.find] -# All the following settings are optional: -exclude = ["binder", "docs", "examples"] -namespaces = false -[tool.setuptools.package-data] -"*" = ["*.csv", "*.txt"] +[tool.ruff] -[tool.distutils.bdist_wheel] -universal = 1 +[tool.ruff.lint] +extend-select = [ + "B", # flake8-bugbear + "I", # isort + "ARG", # flake8-unused-arguments + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ICN", # flake8-import-conventions + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PT", # flake8-pytest-style + "PTH", # flake8-use-pathlib + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "T20", # flake8-print + "UP", # pyupgrade + "YTT", # flake8-2020 + "EXE", # flake8-executable + "NPY", # NumPy specific rules + "PD", # pandas-vet +] +ignore = [ + "PLR09", # Too many <...> + "PLR2004", # Magic value used in comparison + "ISC001", # Conflicts with formatter +] +isort.required-imports = ["from __future__ import annotations"] +# Uncomment if using a _compat.typing backport +# typing-modules = ["HARK._compat.typing"] + +[tool.ruff.lint.per-file-ignores] +"tests/**" = ["T20"] +"noxfile.py" = ["T20"] + + +[tool.pylint] +py-version = "3.10" +ignore-paths = [".*/_version.py"] +reports.output-format = "colorized" +similarities.ignore-imports = "yes" +messages_control.disable = [ + "design", + "fixme", + "line-too-long", + "missing-module-docstring", + "missing-function-docstring", + "wrong-import-position", +] diff --git a/src/HARK/__init__.py b/src/HARK/__init__.py index 4c2064e96..99d80df68 100644 --- a/src/HARK/__init__.py +++ b/src/HARK/__init__.py @@ -1,6 +1,17 @@ +""" +Copyright (c) 2024 Econ-ARK Team. All rights reserved. + +HARK: Heterogeneous Agents Resources and toolKit +""" + +from __future__ import annotations + +from ._version import version as __version__ + +__all__ = ["__version__"] + from .core import * -__version__ = "0.15.1" """ Logging tools for HARK. diff --git a/src/HARK/_version.pyi b/src/HARK/_version.pyi new file mode 100644 index 000000000..91744f983 --- /dev/null +++ b/src/HARK/_version.pyi @@ -0,0 +1,4 @@ +from __future__ import annotations + +version: str +version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str] diff --git a/src/HARK/py.typed b/src/HARK/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_package.py b/tests/test_package.py new file mode 100644 index 000000000..224b7ed54 --- /dev/null +++ b/tests/test_package.py @@ -0,0 +1,9 @@ +from __future__ import annotations + +import importlib.metadata + +import hark as m + + +def test_version(): + assert importlib.metadata.version("hark") == m.__version__