Skip to content

Fix the Defined Benefits and Points System pensions so they can actually run#1167

Open
marcelolafleur wants to merge 6 commits into
PSLmodels:masterfrom
marcelolafleur:fix-pension-system-dims
Open

Fix the Defined Benefits and Points System pensions so they can actually run#1167
marcelolafleur wants to merge 6 commits into
PSLmodels:masterfrom
marcelolafleur:fix-pension-system-dims

Conversation

@marcelolafleur

@marcelolafleur marcelolafleur commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

The non-US pension systems in pensions.py crash when used with a real Specifications object. We found this calibrating OG-BRA: Brazil's pension system (RGPS) is a defined benefits scheme, so OG-BRA is the first country model to use pension_system = "Defined Benefits" — and it crashes on the first solve. Same family of bugs as the Points System crash reported in #1075.

The cause is that these code paths were never updated after some parameters became time-varying: the functions pass arrays where the numba loops expect scalars, and scalars where they expect arrays. The existing tests didn't catch this because they feed the loops pre-cleaned inputs from mock objects instead of a real Specifications object.

Three changes (the third was added after testing a full transition path downstream):

  • Fix the Defined Benefits and Points System paths so they run. They use the steady-state retirement age and earnings profile for now; full time variation stays open in Defined Benefits pension system not handling parameters object sizes correctly #1014. The NDC system needs more than this — its growth-rate settings aren't in default_parameters.json yet — so it remains unusable for now.
  • Add tests that call the pension functions with a real Specifications object (these fail on master with the Bug: Points System crashes with ValueError due to p.retire being a list (plus subsequent TypingError) #1075 errors), plus a steady-state solve test with the DB system.
  • Make the DB system solve the transition path, not just the steady state. Two pieces were missing: the benefit formulas reference pre-time-path wages and labor that nothing ever supplied (labor now comes from the model's initial condition — the same baseline object that initializes wealth — and wages are anchored to the period-0 wage of the current path), and there was no evaluation of DB amounts over the full (T, S, J) path for the TPI's aggregate revenue step (added as DB_3dim_loop, built from each cohort's own wage history so aggregates match household behavior; it reproduces the steady-state solution to machine precision on a constant path).

Fixes #1075. Part of #1014.

Tested: full pension and tax suites pass (71 tests); the DB steady state solves. Downstream check: the OG-BRA Defined Benefits calibration solves both the baseline and a reform transition path against this branch, passes the resource-constraint check on both, and hits its pension spending target to four decimals.

cc @rickecon @jdebacker

@codecov-commenter

codecov-commenter commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.87%. Comparing base (7cae932) to head (a494b31).

Files with missing lines Patch % Lines
ogcore/pensions.py 56.25% 21 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1167      +/-   ##
==========================================
- Coverage   72.95%   72.87%   -0.08%     
==========================================
  Files          22       22              
  Lines        5480     5516      +36     
==========================================
+ Hits         3998     4020      +22     
- Misses       1482     1496      +14     
Flag Coverage Δ
unittests 72.87% <57.14%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
ogcore/TPI.py 36.29% <100.00%> (+0.11%) ⬆️
ogcore/pensions.py 67.30% <56.25%> (-0.93%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Pre-time-path wages are anchored to the period-0 wage of the current
path (trend growth is handled by the de-trending in the benefit
formulas); labor comes from the model's initial condition. The bulk
(T,S,J) evaluation reconstructs each retiree's benefit from their own
cohort's wage history so aggregates match household behavior exactly.
@marcelolafleur marcelolafleur force-pushed the fix-pension-system-dims branch from 31f7cf2 to a494b31 Compare July 15, 2026 20:06
@jdebacker

Copy link
Copy Markdown
Member

@marcelolafleur I appreciate the clarity in this PR about what is addressed and what is not. While not totally solving all of Issue #1014, I think this PR is an important addition and fix of the DB and PS pension systems. I want to merge this and create a new release. Can you update the version to 0.17.0 and include in the change log not just this PR, but the changes in PRs #1174, #1171, and #1166?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Points System crashes with ValueError due to p.retire being a list (plus subsequent TypingError)

3 participants