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

Allow general discrete grids #90

Merged
merged 41 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
41 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
e124a18
Allow for general discrete grids
timmens Jul 15, 2024
bc77ac6
Merge branch 'main' into allow-general-discrete-grids
timmens Sep 15, 2024
d1e3164
Update pixi setup on GHA
timmens Sep 15, 2024
5151735
Refactor model updating into single function call
timmens Sep 16, 2024
7510961
Add unit tests to model updating
timmens Sep 17, 2024
317262e
Fix bugs
timmens Sep 17, 2024
69c1338
Fix bugs in model solution discrete non-index states
timmens Sep 17, 2024
ec2ca70
Implement state and params converter
timmens Sep 17, 2024
24fb2ef
Run pre-commit on all files
timmens Sep 17, 2024
4b3143d
Move functionality into discrete conversion module
timmens Sep 17, 2024
27b8914
Remove unecessary complexity
timmens Sep 17, 2024
134caa0
Do not run CI commands in login shell (fix macos runner problem)
timmens Sep 17, 2024
000bc2a
Integrate comments from review
timmens Sep 18, 2024
770e56f
First step: Only allow dataclass as input to discrete grid
timmens Sep 19, 2024
4d30bf4
Solve #87
timmens Sep 19, 2024
bc27098
Use frozen solve in GHA
timmens Sep 19, 2024
8a28ceb
Update pixi.lock
timmens Sep 19, 2024
227b859
Test [1, 0] discrete grid case
timmens Sep 19, 2024
efb91ae
Add tests for DiscreteStateConverter class
timmens Sep 19, 2024
ff42633
Make validation easier to read.
hmgaudecker Sep 19, 2024
89b0718
Integrate most of the review comments
timmens Sep 20, 2024
d7fc729
Merge branch 'allow-general-discrete-grids' of https://github.com/Ope…
timmens Sep 20, 2024
10180f0
Integrate more comments from review
timmens Sep 20, 2024
2cf15b0
Add tests and fix simulation with non-index discrete grids
timmens Sep 20, 2024
b1264ec
Some fixes and more tests
timmens Sep 20, 2024
b4e7ac6
Integrate comments
timmens Sep 21, 2024
203d7c4
Integrate comments from Christian's review
timmens Sep 23, 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
15 changes: 9 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ jobs:
- '3.12'
steps:
- uses: actions/checkout@v4
- uses: prefix-dev/[email protected].0
- uses: prefix-dev/[email protected].1
with:
pixi-version: v0.29.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
environments: test-cpu
activate-environment: true
frozen: true
- name: Run pytest
shell: bash -l {0}
shell: bash {0}
run: pixi run -e test-cpu tests
- name: Upload coverage report
if: runner.os == 'Linux' && matrix.python-version == '3.12'
Expand All @@ -46,26 +47,28 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: prefix-dev/[email protected].0
- uses: prefix-dev/[email protected].1
with:
pixi-version: v0.29.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
environments: mypy
frozen: true
- name: Run mypy
shell: bash -l {0}
shell: bash {0}
run: pixi run mypy
run-explanation-notebooks:
name: Run explanation notebooks on Python 3.12
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: prefix-dev/[email protected].0
- uses: prefix-dev/[email protected].1
with:
pixi-version: v0.29.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
environments: test-cpu
frozen: true
- name: Run explanation notebooks
shell: bash -l {0}
shell: bash {0}
run: pixi run -e test-cpu explanation-notebooks
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ repos:
hooks:
- id: yamllint
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
rev: v0.6.5
hooks:
# Run the linter.
- id: ruff
Expand Down
13 changes: 12 additions & 1 deletion examples/long_running.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Example specification for a consumption-savings model with health and exercise."""

from dataclasses import dataclass

import jax.numpy as jnp

from lcm import DiscreteGrid, LinspaceGrid, Model
Expand All @@ -9,6 +11,15 @@
# ======================================================================================


# --------------------------------------------------------------------------------------
# Categorical variables
# --------------------------------------------------------------------------------------
@dataclass
class WorkingState:
timmens marked this conversation as resolved.
Show resolved Hide resolved
retired: int = 0
working: int = 1


# --------------------------------------------------------------------------------------
# Utility function
# --------------------------------------------------------------------------------------
Expand Down Expand Up @@ -67,7 +78,7 @@ def consumption_constraint(consumption, wealth, labor_income):
"age": age,
},
choices={
"working": DiscreteGrid([0, 1]),
"working": DiscreteGrid(WorkingState),
"consumption": LinspaceGrid(
start=1,
stop=100,
Expand Down
12 changes: 10 additions & 2 deletions explanations/dispatchers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"metadata": {},
"outputs": [],
"source": [
"from dataclasses import dataclass\n",
"\n",
"import jax.numpy as jnp\n",
"import pytest\n",
"from jax import vmap\n",
Expand Down Expand Up @@ -277,6 +279,12 @@
"from lcm import DiscreteGrid, LinspaceGrid, Model\n",
"\n",
"\n",
"@dataclass\n",
"class RetirementStatus:\n",
" working: int = 0\n",
" retired: int = 1\n",
"\n",
"\n",
"def utility(consumption, retirement, lagged_retirement, wealth):\n",
" working = 1 - retirement\n",
" retirement_habit = lagged_retirement * wealth\n",
Expand All @@ -296,11 +304,11 @@
" },\n",
" n_periods=1,\n",
" choices={\n",
" \"retirement\": DiscreteGrid([0, 1]),\n",
" \"retirement\": DiscreteGrid(RetirementStatus),\n",
" \"consumption\": LinspaceGrid(start=1, stop=2, n_points=2),\n",
" },\n",
" states={\n",
" \"lagged_retirement\": DiscreteGrid([0, 1]),\n",
" \"lagged_retirement\": DiscreteGrid(RetirementStatus),\n",
" \"wealth\": LinspaceGrid(start=1, stop=4, n_points=4),\n",
" },\n",
")"
Expand Down
10 changes: 9 additions & 1 deletion explanations/function_representation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,19 @@
"metadata": {},
"outputs": [],
"source": [
"from dataclasses import dataclass\n",
"\n",
"import jax.numpy as jnp\n",
"\n",
"from lcm import DiscreteGrid, LinspaceGrid, Model\n",
"\n",
"\n",
"@dataclass\n",
"class RetirementStatus:\n",
timmens marked this conversation as resolved.
Show resolved Hide resolved
" working: int = 0\n",
" retired: int = 1\n",
"\n",
"\n",
"def utility(consumption, working, disutility_of_work):\n",
" return jnp.log(consumption) - disutility_of_work * working\n",
"\n",
Expand Down Expand Up @@ -125,7 +133,7 @@
" \"age\": age,\n",
" },\n",
" choices={\n",
" \"retirement\": DiscreteGrid([0, 1]),\n",
" \"retirement\": DiscreteGrid(RetirementStatus),\n",
" \"consumption\": LinspaceGrid(start=1, stop=400, n_points=20),\n",
" },\n",
" states={\n",
Expand Down
Loading
Loading