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 73.29%. Comparing base (a12ecf5) to head (31f7cf2).

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   73.37%   73.29%   -0.09%     
==========================================
  Files          21       21              
  Lines        5374     5410      +36     
==========================================
+ Hits         3943     3965      +22     
- Misses       1431     1445      +14     
Flag Coverage Δ
unittests 73.29% <57.14%> (-0.09%) ⬇️

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

Files with missing lines Coverage Δ
ogcore/TPI.py 39.12% <100.00%> (+0.12%) ⬆️
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.

@marcelolafleur marcelolafleur marked this pull request as draft July 10, 2026 14:54
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.
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)

2 participants