Skip to content

Commit

Permalink
Merge branch 'master' into notebook-gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
Mridul Seth authored Jul 31, 2023
2 parents df8d877 + a547d08 commit 6ab3b4d
Show file tree
Hide file tree
Showing 50 changed files with 1,665 additions and 14,587 deletions.
27 changes: 25 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Python 3.9
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.9" # Numba doesn't support Python 3.11 [2023-05]
python-version: "3.10" # Interpolation.py doesn't support Python 3.11 [2023-07]
cache: 'pip'
cache-dependency-path: |
requirements/base.txt
Expand All @@ -52,6 +52,7 @@ jobs:
-M html Documentation HARK-docs
-T
-W
-j auto
- name: Set up git for deployment
run: |
Expand All @@ -73,3 +74,25 @@ jobs:
--force
https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}
`git subtree split --prefix HARK-docs/html gh-pages`:refs/heads/gh-pages
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade sphinx-lint
- name: Lint documentation with sphinx-lint
run: >
sphinx-lint
--ignore Documentation/example_notebooks/GenIncProcessModel.py
--enable all
--max-line-length 85
README.md
Documentation/
64 changes: 64 additions & 0 deletions .github/workflows/execute-notebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Execute notebooks

# Run on all pushes and pull requests, and on demand
on:
push:
branches:
- master
paths:
- ".github/workflows/execute-notebooks.yml"
- "examples/**"
workflow_dispatch:

# Limit workflow permissions
permissions:
contents: read

# Limit simultaneous workflow runs
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
FORCE_COLOR: "1"

jobs:
execute:
name: Execute
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: "3.10" # Numba doesn't support Python 3.11 [2023-05]
cache: 'pip'
cache-dependency-path: |
requirements/base.txt
- name: Install HARK
run: |
python -m pip install --upgrade pip
python -m pip install .
python -m pip install nbformat nbclient nbstripout
- name: Strip output
run: nbstripout examples/**/*.ipynb

- name: Execute notebooks
run: python tools/nb_exec.py examples/**/*.ipynb

- name: Open PR
uses: peter-evans/create-pull-request@v5
with:
author: "Econ-ARK Bot <noreply@econ-ark.org>"
branch: "bot/update-notebooks"
commit-message: "[bot] updated notebooks"
delete-branch: true
title: "[bot] Execute example notebooks"
body: |
This PR was automatically generated to re-execute
the example notebooks for use in the documentation.
2 changes: 1 addition & 1 deletion Documentation/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@
napoleon_use_ivar = True # solves duplicate object description warning

# nbsphinx configuration
nbsphinx_execute = "never" # This is currently not working
nbsphinx_execute = "never" # notebooks are executed via ``nb_exec.py``
2 changes: 1 addition & 1 deletion HARK/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ def func_wrapper(x: np.ndarray, *args: Any) -> np.ndarray:

if len(kwargs):
f_query = func(self.dataset, **kwargs)
ldd = DiscreteDistributionLabeled.from_dataset(f_query, self.pmv)
ldd = DiscreteDistributionLabeled.from_dataset(f_query, self.probability)

return ldd

Expand Down
39 changes: 39 additions & 0 deletions HARK/tests/test_distribution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest

import numpy as np
import xarray as xr

from HARK.distribution import (
Bernoulli,
Expand Down Expand Up @@ -603,3 +604,41 @@ def test_combine_labeled_dist(self):
np.concatenate([de.expected(), abc.expected()]),
)
)


class labeled_transition_tests(unittest.TestCase):
def setUp(self) -> None:
return super().setUp()

def test_expectation_transformation(self):
# Create a basic labeled distribution
base_dist = DiscreteDistributionLabeled(
pmv=np.array([0.5, 0.5]),
atoms=np.array([[1.0, 2.0], [3.0, 4.0]]),
var_names=["a", "b"],
)

# Define a transition function
def transition(shocks, state):
state_new = {}
state_new["m"] = state["m"] * shocks["a"]
state_new["n"] = state["n"] * shocks["b"]
return state_new

m = xr.DataArray(np.linspace(0, 10, 11), name="m", dims=("grid",))
n = xr.DataArray(np.linspace(0, -10, 11), name="n", dims=("grid",))
state_grid = xr.Dataset({"m": m, "n": n})

# Evaluate labeled transformation

# Direct expectation
exp1 = base_dist.expected(transition, state=state_grid)
# Expectation after transformation
new_state_dstn = base_dist.dist_of_func(transition, state=state_grid)
# TODO: needs a cluncky identity function with an extra argument because
# DDL.expected() behavior is very different with and without kwargs.
# Fix!
exp2 = new_state_dstn.expected(lambda x, unused: x, unused=0)

assert np.all(exp1["m"] == exp2["m"]).item()
assert np.all(exp1["n"] == exp2["n"]).item()
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ Looking for help? Please open a [GitHub issue](https://github.com/econ-ark/HARK/

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).

## API Documentation
## Documentation

Documentation for the latest release is at [docs.econ-ark.org](https://docs.econ-ark.org/reference/).
Documentation for the latest release is at [docs.econ-ark.org](https://docs.econ-ark.org/).

## Introduction

Expand Down
27 changes: 4 additions & 23 deletions examples/Calibration/Income_calibrations.ipynb

Large diffs are not rendered by default.

54 changes: 5 additions & 49 deletions examples/Calibration/Life_Cycle_example.ipynb

Large diffs are not rendered by default.

35 changes: 12 additions & 23 deletions examples/Calibration/SCF_distributions.ipynb

Large diffs are not rendered by default.

23 changes: 5 additions & 18 deletions examples/Calibration/Sabelhaus_Song_var_profiles.ipynb

Large diffs are not rendered by default.

45 changes: 6 additions & 39 deletions examples/Calibration/US_SSA_life_tables.ipynb

Large diffs are not rendered by default.

65 changes: 7 additions & 58 deletions examples/ConsBequestModel/example_AccidentalBequest.ipynb

Large diffs are not rendered by default.

148 changes: 128 additions & 20 deletions examples/ConsBequestModel/example_ConsIndShockComp.ipynb

Large diffs are not rendered by default.

83 changes: 16 additions & 67 deletions examples/ConsBequestModel/example_TerminalBequest.ipynb

Large diffs are not rendered by default.

42 changes: 7 additions & 35 deletions examples/ConsIndShockModel/Finite Cyclical Test.ipynb

Large diffs are not rendered by default.

126 changes: 22 additions & 104 deletions examples/ConsIndShockModel/IndShockConsumerType.ipynb

Large diffs are not rendered by default.

136 changes: 17 additions & 119 deletions examples/ConsIndShockModel/IndShockConsumerType_Jacobian_Example.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

71 changes: 12 additions & 59 deletions examples/ConsIndShockModel/KinkedRconsumerType.ipynb

Large diffs are not rendered by default.

135 changes: 24 additions & 111 deletions examples/ConsIndShockModel/PerfForesightConsumerType.ipynb

Large diffs are not rendered by default.

224 changes: 46 additions & 178 deletions examples/ConsPortfolioModel/example_ConsPortfolioModel.ipynb

Large diffs are not rendered by default.

217 changes: 28 additions & 189 deletions examples/ConsPortfolioModel/example_ConsRiskyAssetModel.ipynb

Large diffs are not rendered by default.

115 changes: 19 additions & 96 deletions examples/ConsPortfolioModel/example_ConsSequentialPortfolioModel.ipynb

Large diffs are not rendered by default.

138 changes: 34 additions & 104 deletions examples/ConsumptionSaving/example_ConsAggShockModel.ipynb

Large diffs are not rendered by default.

141 changes: 25 additions & 116 deletions examples/ConsumptionSaving/example_ConsGenIncProcessModel.ipynb

Large diffs are not rendered by default.

250 changes: 38 additions & 212 deletions examples/ConsumptionSaving/example_ConsIndShock.ipynb

Large diffs are not rendered by default.

192 changes: 33 additions & 159 deletions examples/ConsumptionSaving/example_ConsLaborModel.ipynb

Large diffs are not rendered by default.

188 changes: 28 additions & 160 deletions examples/ConsumptionSaving/example_ConsMarkovModel.ipynb

Large diffs are not rendered by default.

138 changes: 34 additions & 104 deletions examples/ConsumptionSaving/example_ConsMedModel.ipynb

Large diffs are not rendered by default.

131 changes: 20 additions & 111 deletions examples/ConsumptionSaving/example_ConsPrefShockModel.ipynb

Large diffs are not rendered by default.

66 changes: 12 additions & 54 deletions examples/ConsumptionSaving/example_ConsRepAgentModel.ipynb

Large diffs are not rendered by default.

108 changes: 16 additions & 92 deletions examples/ConsumptionSaving/example_TractableBufferStockModel.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 6ab3b4d

Please sign in to comment.