Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c89dd36
Split functions dictionary (#161)
timmens Oct 16, 2025
3e64996
Rename model to regime (#162)
timmens Oct 16, 2025
f61149a
Merge regime processing and component initialization (#163)
timmens Oct 17, 2025
d136d95
Re-add the model class (#164)
mj023 Oct 27, 2025
b9acb73
Replace function dictionaries in InternalRegime (#165)
mj023 Oct 29, 2025
975fe9d
Support multiple regimes per model (#166)
mj023 Nov 18, 2025
167a3a6
Add new example model (#169)
mj023 Dec 1, 2025
12c05ce
Update transitions interface (#182)
timmens Dec 5, 2025
bf2bb3f
Align regime transitions with stochastic transitions interface (#186)
timmens Dec 5, 2025
a3237c1
Support deterministic regime transitions (#188)
timmens Dec 6, 2025
cf2ff39
Use regime_id_cls for regime_name_to_id mapping (#189)
timmens Dec 6, 2025
9a93fa1
Implement flat transitions interface for user-facing API (#190)
timmens Dec 9, 2025
b4647ef
Add terminal regime support with active periods (#191)
timmens Dec 22, 2025
decb35f
Allow for state- and action-less regimes (#196)
timmens Dec 23, 2025
1ce586f
Rename 'beta' to 'discount_factor' (#197)
timmens Dec 23, 2025
a96ab22
Replace mypy by ty (#199)
hmgaudecker Dec 23, 2025
51540ca
Implement simulation result object (#195)
timmens Dec 25, 2025
bca01e2
Normalize regime transition probabilities (#200)
timmens Dec 30, 2025
72225a6
Add `to_pickle` and `from_pickle` methods to `SimulationResult` objec…
timmens Dec 30, 2025
81961de
Bump the github-actions group with 2 updates (#202)
dependabot[bot] Jan 2, 2026
51fb110
Add age grid (#203)
timmens Jan 4, 2026
8b34c23
Fix terminal regime ID preservation in simulation (#205)
timmens Jan 5, 2026
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
25 changes: 14 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
python-version:
- '3.12'
steps:
- uses: actions/checkout@v5
- uses: prefix-dev/[email protected].1
- uses: actions/checkout@v6
- uses: prefix-dev/[email protected].3
with:
pixi-version: v0.52.0
pixi-version: v0.62.2
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
environments: test-cpu
Expand All @@ -45,29 +45,32 @@ jobs:
- name: Upload coverage report
if: runner.os == 'Linux' && matrix.python-version == '3.12'
uses: codecov/codecov-action@v5
run-mypy:
name: Run mypy on Python 3.12
run-ty:
name: Run ty on Python 3.12
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version:
- '3.12'
steps:
- uses: actions/checkout@v5
- uses: prefix-dev/[email protected].1
- uses: actions/checkout@v6
- uses: prefix-dev/[email protected].3
with:
pixi-version: v0.52.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
environments: test-cpu
frozen: true
- name: Run mypy
- name: Run ty
shell: bash {0}
run: pixi run -e test-cpu mypy
run: pixi run -e test-cpu ty
# run-explanation-notebooks:
# name: Run explanation notebooks on Python 3.12
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v5
# - uses: prefix-dev/[email protected].1
# - uses: actions/checkout@v6
# - uses: prefix-dev/[email protected].3
# with:
# pixi-version: v0.52.0
# cache: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
- name: Set up Python 3.13
uses: actions/setup-python@v6
with:
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ venv.bak/
# mkdocs documentation
/site

# mypy
.mypy_cache/

*notes/

.idea/
Expand Down
38 changes: 15 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: check-useless-excludes
# - id: identity # Prints all files passed to pre-commits. Debugging.
- repo: https://github.com/lyz-code/yamlfix
rev: 1.18.0
rev: 1.19.1
hooks:
- id: yamlfix
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -33,7 +33,7 @@ repos:
- id: name-tests-test
args:
- --pytest-test-first
exclude: ^tests/test_models/
exclude: tests/regime_mock.py|^tests/test_models/
- id: no-commit-to-branch
args:
- --branch
Expand All @@ -46,7 +46,7 @@ repos:
hooks:
- id: yamllint
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.13.3
rev: v0.14.10
hooks:
# Run the linter.
- id: ruff
Expand All @@ -63,7 +63,7 @@ repos:
- pyi
- jupyter
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.22
rev: 1.0.0
hooks:
- id: mdformat
additional_dependencies:
Expand All @@ -75,29 +75,21 @@ repos:
- '88'
files: (README\.md)
- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
rev: 0.8.2
hooks:
- id: nbstripout
args:
- --drop-empty-cells
- --keep-output
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.17.1
hooks:
- id: mypy
files: src|tests
additional_dependencies:
- dags>=0.4.1
- jax>=0.7
- jaxtyping>=0.3.2
- numpy
- packaging
- pandas-stubs
- pytest
- scipy-stubs
args:
- --config=pyproject.toml
# - repo: local
# hooks:
# - id: ty
# name: ty
# entry: ty
# language: system
# types: [python]
# args: [--config-file=pyproject.toml]
ci:
autoupdate_schedule: monthly
skip:
- mypy # installing jax is not possible on pre-commit.ci due to size limits.
# skip:
# - ty # installing jax is not possible on pre-commit.ci due to size limits.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ simulation of finite-horizon discrete-continuous dynamic choice models.
## Installation

PyLCM can be installed via PyPI or via GitHub. To do so, type the following in a
terminal:
terminal (or install via uv):

```console
$ pip install pylcm
Expand Down Expand Up @@ -43,10 +43,10 @@ $ pixi run tests
```

This will install the development environment and run the tests. You can run
[mypy](https://mypy-lang.org/) using
[ty](https://docs.astral.sh/ty) using

```console
$ pixi run mypy
$ pixi run ty
```

Before committing, install the pre-commit hooks using
Expand Down
37 changes: 18 additions & 19 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
# Example model specifications

## Choosing an example
## Example Model Stats

| Example name | Description | Runtime |
| ----------------------------------- | ------------------------------------------------- | ------------- |
| [`long_running`](./long_running.py) | Consumption-savings model with health and leisure | a few minutes |
| Example name | Description | Runtime |
| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| [`consumption_saving`](./consumption_saving.py) | Simple illustrative consumption-savings model with health and leisure | CPU: ~20s, GPU: \<5s |
| [`mahler_yum_2024`](./mahler_yum_2024.py) | Replication of the lifecycle model from the paper "Lifestyle Behaviors and Wealth-Health Gaps in Germany" by Lukas Mahler and Minchul Yum (Econometrica, 2024) | CPU: ~20min, GPU: \<40s |

## Running an example
> [!NOTE]
> Runtime refers to a single simulation call for 1,000 individuals. CPU times come from
> a MacBook Pro with M4 Pro chip with 24GB RAM. GPU times were recorded on a Nvidia
> Geforce RTX 3050.

Say you want to solve the `long_running` example locally. First, clone this repository,
[install pixi if required](https://pixi.sh/latest/#installation), move into the examples
folder, and open the interactive Python shell. In a console, type:
## Running an example model

If you want to solve and simulate an example locally,
[install pixi](https://pixi.sh/latest/#installation) and follow these steps:

```console
$ git clone https://github.com/opensourceeconomics/pylcm.git
$ cd lcm/examples
$ pixi run ipython
$ cd pylcm/examples/#example name#
$ pixi run python model.py
```

In that shell, run the following code:

```python
from lcm.entry_point import get_lcm_function

from long_running import MODEL_CONFIG, PARAMS
If you want to run a model on the GPU you need to use the pixi 'cuda' environment, run


solve_model, _ = get_lcm_function(model=MODEL_CONFIG, targets="solve")
V_arr_list = solve_model(PARAMS)
```console
$ pixi run -e cuda python model.py
```
Loading