PSLmodels / OG-Core

An overlapping generations model framework for evaluating fiscal policies.
https://pslmodels.github.io/OG-Core/
Creative Commons Zero v1.0 Universal
65 stars 111 forks source link

Extensions to `demographics.py` #902

Closed jdebacker closed 6 months ago

jdebacker commented 6 months ago

This PR updates the demographics.py module to:

  1. Allow the user to have the population distribution from the initial period forward inferred from given fertility, mortality, and immigration rates (functionality to infer immigration from a given evolution of the population is retained, the user specifies what they want to do via arguments to the relevant function calls).
  2. Extends all series returned from the get_pop_objs() function over the full transition path of T+S periods (except those that apply only to a single period).

Addresses Issues #900 and #899

codecov-commenter commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (1331b6a) 80.52% compared to head (8fbbb9c) 80.72%.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/902/graphs/tree.svg?width=650&height=150&src=pr&token=98mQCVhspd&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels)](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/902?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels) ```diff @@ Coverage Diff @@ ## master #902 +/- ## ========================================== + Coverage 80.52% 80.72% +0.20% ========================================== Files 19 19 Lines 4452 4499 +47 ========================================== + Hits 3585 3632 +47 Misses 867 867 ``` | [Flag](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/902/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/902/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels) | `80.72% <100.00%> (+0.20%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/902?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels) | Coverage Δ | | |---|---|---| | [ogcore/demographics.py](https://app.codecov.io/gh/PSLmodels/OG-Core/pull/902?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PSLmodels#diff-b2djb3JlL2RlbW9ncmFwaGljcy5weQ==) | `84.31% <100.00%> (+2.84%)` | :arrow_up: |
rickecon commented 6 months ago

@jdebacker. This looks great. I ran the run_ogcore_example.py script on my local machine to make sure the TPI worked and converged. I will merge this as soon as the final tests pass.

You might consider updating the version to 0.11.2 in setup.py, ogcore/__init__.py, and adding a CHANGELOG.md entry that includes both the description at the top of the document and the GitHub compare hyperlink at the bottom of the document.

jdebacker commented 6 months ago

@rickecon Hold off. I want to try to figure out why the first period resource constraint isn't being satisfied and I think it's coming from demographics.py. I'm still testing to find exact reason and will follow up here when I find it.

rickecon commented 6 months ago

@jdebacker. Where is this error being manifest? Are you looking at the full TPI output after a run?

jdebacker commented 6 months ago

@rickecon asks:

Where is this error being manifest? Are you looking at the full TPI output after a run?

Yes. I need set ENFORCE_SOLUTION_CHECKS = False in TPI.py so that there's not an assertion raised before the output is saved. But when I do that and then look at the resource constraint errors along the time path, the only period with an error in excess of our tolerance is the first period.

rickecon commented 6 months ago

@jdebacker. There is currently one test failing in test_demographics.py::test_custom_series() .

rickecon commented 6 months ago

@jdebacker. Thanks for this PR. Looks great. Merging.