Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update model processing #85

Merged
merged 51 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6044788
Initial commit
timmens Jun 30, 2024
fd69501
Add new Model and Grid user interface
timmens Jul 1, 2024
4bb8299
Add new Model and Grid user interface
timmens Jul 1, 2024
2ad8eda
Add new Model and Grid user interface
timmens Jul 1, 2024
f951733
Merge branch 'main' into update-process-model
timmens Jul 2, 2024
21e876d
Save changes
timmens Jul 4, 2024
5a4cff0
Use user model class in Lcm
timmens Jul 5, 2024
cc68b6f
Fix mypy error
timmens Jul 5, 2024
d0aabe1
Merge branch 'update-process-model' of https://github.com/OpenSourceE…
timmens Jul 5, 2024
f51ffae
Add classes for Discrete and Continuous Grids
timmens Jul 10, 2024
d981304
Fix mypy and pre-commit hooks
timmens Jul 11, 2024
2a1b955
Update explanation notebooks
timmens Jul 11, 2024
45f106a
Remove all references to black formatter
timmens Jul 14, 2024
88a8a82
Add functionality to Grids class
timmens Jul 14, 2024
56a6329
Remove setup.py from codecov.yml
timmens Jul 16, 2024
8ce39ee
Rename grids module to grid_helpers module
timmens Jul 18, 2024
e54755f
Split user_input module into grids and model module
timmens Jul 18, 2024
0d9d454
Create exceptions module
timmens Jul 19, 2024
2c045d8
Autoupdate pre-commits
timmens Aug 11, 2024
85bcec4
Update pre-commit hooks
timmens Sep 2, 2024
db986f3
Remove N_GRID_POINTS dict
timmens Sep 2, 2024
d071cf3
Better error message handling
timmens Sep 2, 2024
28783c9
Better grid replace methods
timmens Sep 2, 2024
72a00f0
Fix mypy errors
timmens Sep 2, 2024
08779d5
Remove jaxlib from pre-commit mypy env
timmens Sep 2, 2024
666fae1
Skip mypy pre-commit hook on CI
timmens Sep 2, 2024
eb798ed
Skip mypy pre-commit hook on CI
timmens Sep 2, 2024
6135338
Add type hints to process model
timmens Sep 2, 2024
b501920
Fix tests
timmens Sep 4, 2024
9c877fd
Add grid tests
timmens Sep 4, 2024
4059f7d
Add model tests
timmens Sep 4, 2024
3cef907
Bump mypy version
timmens Sep 4, 2024
048ce87
Replace Params type by much simpler ParamsDict type
timmens Sep 5, 2024
316810c
Remove replace method from grids
timmens Sep 5, 2024
c5f2a28
Remove _skip_checks argument from Model class
timmens Sep 5, 2024
58db89d
Add get_coordinate method to grid classes
timmens Sep 5, 2024
a6b5f51
Remove redundant interpolation interface and fix explanation notebook
timmens Sep 5, 2024
6f47653
Replace NamedTuple instances by dataclasses
timmens Sep 5, 2024
1bae2e3
Remove Walrus operator
timmens Sep 5, 2024
216a583
Import pdbp in __init__.py
timmens Sep 9, 2024
d126dba
Integrate comments from review
timmens Sep 9, 2024
0b8f368
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 9, 2024
fac3512
Update pixi version
timmens Sep 9, 2024
6603e02
Create folder for input processing
timmens Sep 10, 2024
357e29e
Start refactoring input processing
timmens Sep 10, 2024
78d42c2
Refactor input processing
timmens Sep 10, 2024
07bb067
Delete unused util.py
timmens Sep 10, 2024
acfb506
Refactor model processing and add InternalModel type hint
timmens Sep 10, 2024
4cee309
Rename user_model -> model
timmens Sep 10, 2024
b767ccf
Rename model module -> user_model
timmens Sep 10, 2024
d73d1b5
Run pre-commit autoupdate
timmens Sep 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: actions/checkout@v4
- uses: prefix-dev/[email protected]
with:
pixi-version: v0.23.0
pixi-version: v0.29.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
environments: test-cpu
Expand All @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v4
- uses: prefix-dev/[email protected]
with:
pixi-version: v0.23.0
pixi-version: v0.29.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
environments: mypy
Expand All @@ -62,7 +62,7 @@ jobs:
- uses: actions/checkout@v4
- uses: prefix-dev/[email protected]
with:
pixi-version: v0.23.0
pixi-version: v0.29.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
environments: test-cpu
Expand Down
70 changes: 37 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,9 @@ repos:
- id: check-useless-excludes
# - id: identity # Prints all files passed to pre-commits. Debugging.
- repo: https://github.com/lyz-code/yamlfix
rev: 1.16.0
rev: 1.17.0
hooks:
- id: yamlfix
- repo: local
hooks:
- id: check-nbqa-version-mismatch
name: Check for version mismatch between black, ruff, and nbQA
entry: python scripts/check_nbqa_version_mismatch.py
language: python
always_run: true
require_serial: true
additional_dependencies:
- pyyaml
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
Expand Down Expand Up @@ -55,41 +45,55 @@ repos:
rev: v1.35.1
hooks:
- id: yamllint
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
language_version: python3.12
- repo: https://github.com/asottile/blacken-docs
rev: 1.18.0
hooks:
- id: blacken-docs
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
rev: v0.6.3
hooks:
# Run the linter.
- id: ruff
# args:
# - --verbose
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.8.5
hooks:
- id: nbqa-black
additional_dependencies:
- black==24.4.2
- id: nbqa-ruff
additional_dependencies:
- ruff==v0.5.0
types_or:
- python
- pyi
- jupyter
args:
- --fix
# Run the formatter.
- id: ruff-format
types_or:
- python
- pyi
- jupyter
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
- mdformat-gfm
- mdformat-gfm-alerts
- mdformat-black
- mdformat-ruff
args:
- --wrap
- '88'
files: (README\.md)
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
hooks:
- id: nbstripout
args:
- --drop-empty-cells
- --keep-output
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
files: src|tests
additional_dependencies:
- jax>=0.4.20
- numpy
- packaging
- pandas-stubs
args:
- --config=pyproject.toml
ci:
autoupdate_schedule: monthly
skip:
- mypy # installing jax is not possible on pre-commit.ci due to size limits.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Life Cycle Models

[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/OpenSourceEconomics/lcm/main.svg)](https://results.pre-commit.ci/latest/github/OpenSourceEconomics/lcm/main)
[![image](https://codecov.io/gh/OpenSourceEconomics/lcm/branch/main/graph/badge.svg)](https://codecov.io/gh/OpenSourceEconomics/lcm)

Expand Down
1 change: 0 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ coverage:
default:
target: 90%
ignore:
- setup.py
- tests/**/*
72 changes: 30 additions & 42 deletions examples/long_running.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

import jax.numpy as jnp

# ======================================================================================
# Numerical parameters and constants
# ======================================================================================
N_GRID_POINTS = {
"wealth": 100,
"health": 100,
"consumption": 100,
"exercise": 200,
}

RETIREMENT_AGE = 65
from lcm import DiscreteGrid, LinspaceGrid, Model

# ======================================================================================
# Model functions
Expand Down Expand Up @@ -62,9 +52,12 @@ def consumption_constraint(consumption, wealth, labor_income):
# ======================================================================================
# Model specification and parameters
# ======================================================================================
RETIREMENT_AGE = 65

MODEL_CONFIG = {
"functions": {

MODEL_CONFIG = Model(
n_periods=RETIREMENT_AGE - 18,
functions={
"utility": utility,
"next_wealth": next_wealth,
"next_health": next_health,
Expand All @@ -73,37 +66,32 @@ def consumption_constraint(consumption, wealth, labor_income):
"wage": wage,
"age": age,
},
"choices": {
"working": {"options": [0, 1]},
"consumption": {
"grid_type": "linspace",
"start": 1,
"stop": 100,
"n_points": N_GRID_POINTS["consumption"],
},
"exercise": {
"grid_type": "linspace",
"start": 0,
"stop": 1,
"n_points": N_GRID_POINTS["exercise"],
},
choices={
"working": DiscreteGrid([0, 1]),
"consumption": LinspaceGrid(
start=1,
stop=100,
n_points=100,
),
"exercise": LinspaceGrid(
start=0,
stop=1,
n_points=200,
),
},
"states": {
"wealth": {
"grid_type": "linspace",
"start": 1,
"stop": 100,
"n_points": N_GRID_POINTS["wealth"],
},
"health": {
"grid_type": "linspace",
"start": 0,
"stop": 1,
"n_points": N_GRID_POINTS["health"],
},
states={
"wealth": LinspaceGrid(
start=1,
stop=100,
n_points=100,
),
"health": LinspaceGrid(
start=0,
stop=1,
n_points=100,
),
},
"n_periods": RETIREMENT_AGE - 18,
}
)

PARAMS = {
"beta": 0.95,
Expand Down
Loading
Loading