Skip to content

Commit c1ffb2a

Browse files
committed
create_model: default max_consumption into fixed_params
The runtime-upper-bound change requires every caller to supply `max_consumption` via `fixed_params`; estimation tasks (e.g. `task_simulate_aca`) hit a `KeyError` mid-pipeline because they construct the model from data-derived `fixed_params` that have no reason to mention a grid bracket. Centralise the default in both `baseline.model.create_model` and `aca.model.create_model` so existing callers keep working with the prior 300k bracket and only opt-in callers need to override.
1 parent e08fc19 commit c1ffb2a

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/aca_model/aca/model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from aca_model.aca import PolicyVariant
1313
from aca_model.aca.regimes import build_all_regimes
14+
from aca_model.baseline.model import _with_max_consumption_default
1415
from aca_model.baseline.regimes import RegimeId
1516
from aca_model.config import GRID_CONFIG, MODEL_CONFIG, GridConfig
1617

@@ -51,6 +52,7 @@ def create_model(
5152
stop=MODEL_CONFIG.end_age - 1,
5253
step="Y",
5354
)
55+
fixed_params = _with_max_consumption_default(fixed_params)
5456
regimes = build_all_regimes(
5557
policy=policy,
5658
grid_config=grid_config,
@@ -63,6 +65,6 @@ def create_model(
6365
ages=ages,
6466
regime_id_class=RegimeId,
6567
description=f"Structural retirement model ({policy.name})",
66-
fixed_params=fixed_params or {},
68+
fixed_params=fixed_params,
6769
derived_categoricals=derived_categoricals,
6870
)

src/aca_model/baseline/model.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
from aca_model.baseline.regimes import RegimeId, build_all_regimes
1919
from aca_model.config import GRID_CONFIG, MODEL_CONFIG, GridConfig
2020

21+
_DEFAULT_MAX_CONSUMPTION: float = 300_000.0
22+
"""Upper bound of the consumption grid in $/year. Brackets the unconstrained
23+
CRRA optimum for the highest-asset, highest-income agents in the state space.
24+
Callers can override by passing `max_consumption` in `fixed_params`."""
25+
2126

2227
def create_model(
2328
*,
@@ -59,6 +64,7 @@ def create_model(
5964
stop=MODEL_CONFIG.end_age - 1,
6065
step="Y",
6166
)
67+
fixed_params = _with_max_consumption_default(fixed_params)
6268
regimes = build_all_regimes(
6369
grid_config,
6470
fixed_params=fixed_params,
@@ -71,6 +77,15 @@ def create_model(
7177
ages=ages,
7278
regime_id_class=RegimeId,
7379
description="Baseline structural retirement model (pre-ACA)",
74-
fixed_params=fixed_params or {},
80+
fixed_params=fixed_params,
7581
derived_categoricals=derived_categoricals,
7682
)
83+
84+
85+
def _with_max_consumption_default(
86+
fixed_params: Mapping[str, Any] | None,
87+
) -> dict[str, Any]:
88+
"""Return a copy of `fixed_params` with `max_consumption` defaulted."""
89+
out = dict(fixed_params or {})
90+
out.setdefault("max_consumption", _DEFAULT_MAX_CONSUMPTION)
91+
return out

0 commit comments

Comments
 (0)