Skip to content

Introduce discrete state choice specific continuous grids - #212

Open
MaxBlesch wants to merge 30 commits into
mainfrom
state_grids
Open

MaxBlesch wants to merge 30 commits into
mainfrom
state_grids

Conversation

@MaxBlesch

@MaxBlesch MaxBlesch commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

PR Summary: State-Choice-Specific Continuous Grids

Main features

  1. State-choice-specific continuous grids — continuous_grid_functions, a new top-level argument to create_model_dict/setup_model, lets a grid (assets_end_of_period, assets_begin_of_period, or any additional continuous state) depend on the discrete state and choice, not just be one fixed global array. model_config["continuous_states"] entries can now be None (fully state-specific, no default array).
  2. Representative-parent grid selection — since the solution lives on the state-choice space, every place that evaluates a transition into a child now distinguishes the child (drives the transition function) from a representative parent (supplies the grid values), consistency-checked once at model-build time.
  3. Choice-dependence detection (transition_funcs_depend_on_choice) — when neither the budget equation nor the continuous-state transition declares choice, the law of motion is evaluated once per unique child state instead of once per state-choice, a pure cost optimization.
  4. Shared batch-dedup logic — factored out of the two batch-size algorithms into child_state_dedup.py, removing duplicated code and exposing the state-level dedup that (3) relies on.
  5. N-D regular-grid interpolation — new interpnd_regular.py for reading stored solutions on own (possibly state-specific) regular grids under Druedahl-Jorgensen.
  6. Final period unified onto the main code path — the final period now goes through the same calc_law_of_motion entry point as every other period instead of a duplicated one.

Tests per feature

Feature Test file(s)
(1) Config plumbing (continuous_grid_functions, None-declared grids) test_state_specific_grids_config.py
(2) Representative-parent grid selection test_state_specific_grids_law_of_motion.py, test_state_specific_grids_end_to_end.py
(1)+(2) end-to-end, via solve()/simulate()/choice_values_for_states test_state_specific_grids_end_to_end.py
(1)+(2) absolute correctness (vs. closed-form and a hand-solved NumPy reference, incl. a second state-specific grid on an additional continuous state) test_state_specific_grids_reference.py
(3) Choice-dependence granularity (bit-for-bit equivalence of the two branches) test_state_specific_grids_law_of_motion.py
(3) Choice-dependent budget, absolute correctness over 4 periods with stochastic transitions test_state_specific_grids_reference.py (reference.py's work_cost arg)
(4) Batch dedup consistency test_state_specific_grids_law_of_motion.py, test_state_specific_grids_config.py
(5) N-D regular-grid interpolation test_interpnd_regular_own_grids.py, test_interpolation.py
(6) Final period / general regression coverage test_two_period_continuous_experience.py, test_law_of_motion.py

@codecov

codecov Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.56869% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.88%. Comparing base (578ff8d) to head (a76b24d).

Files with missing lines Patch % Lines
src/dcegm/interfaces/combined_solve.py 81.81% 20 Missing ⚠️
src/dcegm/egm/interpolate_marginal_utility.py 78.57% 3 Missing ⚠️
src/dcegm/interfaces/sol_interface.py 33.33% 2 Missing ⚠️
src/dcegm/interpolation/interp_interfaces.py 85.71% 2 Missing ⚠️
src/dcegm/interpolation/simulation_interp.py 92.30% 1 Missing ⚠️
...ocessing/model_structure/continuous_state_grids.py 98.71% 1 Missing ⚠️
src/dcegm/solve_single_period.py 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #212      +/-   ##
==========================================
+ Coverage   93.06%   93.88%   +0.81%     
==========================================
  Files          71       74       +3     
  Lines        2597     3125     +528     
==========================================
+ Hits         2417     2934     +517     
- Misses        180      191      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant