Skip to content

Commit

Permalink
Update model processing (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
timmens authored Sep 10, 2024
1 parent a73ad76 commit ff66bad
Show file tree
Hide file tree
Showing 58 changed files with 7,690 additions and 7,562 deletions.
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.4
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

0 comments on commit ff66bad

Please sign in to comment.