[v4] Accept dict reforms on Simulation(policy=/dynamic=)#297
Closed
MaxGhenis wants to merge 1 commit intov4-docs-refreshfrom
Closed
[v4] Accept dict reforms on Simulation(policy=/dynamic=)#297MaxGhenis wants to merge 1 commit intov4-docs-refreshfrom
MaxGhenis wants to merge 1 commit intov4-docs-refreshfrom
Conversation
Unifies the v4 reform surface: the same flat {"param.path": value} /
{"param.path": {date: value}} dict already accepted by
pe.{uk,us}.calculate_household(reform=...) now works on population
Simulation too. Dicts are compiled to Policy / Dynamic objects in a
model_validator(mode="after") using tax_benefit_model_version for
parameter-path validation and dataset.year for scalar effective-date
defaulting.
Adds compile_reform_to_policy / compile_reform_to_dynamic helpers
in tax_benefit_models.common.reform, tested directly in
tests/test_dict_reforms_on_simulation.py (6 tests covering scalar
defaulting, effective-date mappings, path validation, pass-through of
existing Policy objects, and the "no model_version" error path).
Unknown parameter paths raise with close-match suggestions (same
behaviour as the household calculator) so agents don't silently get a
no-op reform from a typo.
397/397 tests pass. End-to-end microsim with
Simulation(policy={"gov.irs.credits.ctc.amount.base[0].amount": 3000})
produces the same -$25.5B revenue impact as the manual
Policy+ParameterValue construction it replaces.
4 tasks
Contributor
Author
|
Superseded by #298 (consolidated v4 launch PR). All commits cherry-picked cleanly onto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Last piece of the v4 agent-first reform surface:
Simulation(policy={...})andSimulation(dynamic={...})now accept the same flat dict thatpe.{uk,us}.calculate_household(reform=...)accepts.Before
After
Same shape accepted by both entry points. Same effective-date semantics (scalars default to
{year}-01-01usingdataset.year). Same validation (unknown paths raise with close-match suggestions).Implementation
compile_reform_to_policy/compile_reform_to_dynamichelpers intax_benefit_models.common.reform.Simulation.policy/Simulation.dynamictyped asOptional[Union[Policy, dict[str, Any]]]/Optional[Union[Dynamic, dict[str, Any]]].@model_validator(mode="after")compiles dicts to fullPolicy/Dynamiconcetax_benefit_model_versionanddatasetare onself.tax_benefit_model_versionwith a dict reform raises a directed error.Tests
tests/test_dict_reforms_on_simulation.py(6 tests, no network, no HF token):ParameterValuewithstart_date = {year}-01-01{date: value}mapping → multipleParameterValues with matchingstart_dateValueErrorwith "did you mean" hintPolicyobject → passes through unchangedtax_benefit_model_version→ raisesdynamic={...}coerces toDynamicFull suite: 397/397 pass locally. End-to-end microsim sanity-checked:
Simulation(policy={"gov.irs.credits.ctc.amount.base[0].amount": 3_000})produces-$25.5Brevenue impact, identical to the hand-builtPolicypath.Stack
Stacked on #295 (docs refresh). Retargets to
mainonce the earlier stack merges.🤖 Generated with Claude Code