Repository navigation
Unify the engine for singles and households and support staged decisions - #670
hmgaudecker wants to merge 68 commits into
Conversation
A private switch, off by default, builds a regime declared with a plain utility function on the household kernels with the one member "self". With it on, value arrays carry a member axis of length one, the result column keeps the name `value`, and a route that names no role lands on that member, so `lcm_examples.collective_household` forms and dissolves couples as before. With it off no program changes. The health state of `lcm_examples.precautionary_savings_health` stays on its grid: exercise closes part of the gap to full health and work halves health. Its regression archives are not regenerated yet. `tests/test_single_on_household_path.py` compares both paths on four models: values within 16 units in the last place and identical discrete choices. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
With the measurement switch on, a gated edge reads its target, fallback and source members from the engine's member axis, so a single lands on the member "self". The rule for a member's copy of a name (`value`, `utility`, `V_target` for "self", `<name>_<member>` otherwise) and the rule for the member a route lands on are each stated once, in `regime_building/collective.py`. `tests/test_single_on_household_path.py` gains four gated-edge models and two single-agent exits; all agree bitwise with the single path at both precisions. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
`scaled_lottery_mean` computed each node's exponent, took the largest, and shifted every node by it: two readers of an array as large as the values at every node. On the GPU the compiler could keep that array whole, 93 GiB for one regime of a production model, and more often for a regime with members. One reduction over the nodes now carries the numerator as a sum with an exponent and rescales it as it goes; a second does the same for the mass. The sums have the bits of the old ones for the same order of addition. On the CPU the compiler adds in a different order than before, so values move by rounding. A row with live infinities of both signs now gives NaN on the GPU as well. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
A household with taste shocks publishes action values, and an exit with targets for several members demands the member seed like a transition with several routes does. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
While searching for block widths, the planner compiled a candidate and compared its memory with the budget. When XLA itself ran out of device memory during that compilation, the solve stopped. Such a candidate now counts as not fitting: it is compiled once more on its own and then skipped. If every candidate runs out, the planner raises its own error with XLA's as the cause. A width fixed by the user, or the only width a core admits, still raises XLA's error, and so does any other compilation error. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
Documentation build overview
48 files changed ·
|
Period capture and replay, invariant blocking, and the shared own-value read of an exit query refused a regime whose values carry a member axis. They take it as they take any other: the value's axis names include `member`, so a blocked view and a replayed period have the right rank. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
The places that choose a name or a role read a regime's members: the member "self" keeps the short name (`utility`, `value`, `V_target`) and is no role, so a start in such a regime carries no `own_member` and a route of that member carries none. The regime finder reads a recorded member "self" as an individual. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
Benchmark comparison (main → HEAD)Comparing
|
A solver declares whether it solves a regime of several members (`supports_several_members`); grid search does, the endogenous-grid family does not, and that capability is the one check on the number of members. A kernel's value carries the regime's member axis, so the solver API version moves to 4 and the fingerprint pin table with it. The solvers read the member's utility by its name and publish the trailing axis inside the compiled program. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
The integration over current-period shock nodes keeps the member axis, so a household that observes such shocks and has no exit solves on the grid-search kernel instead of a query kernel, and a household with taste shocks may observe them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
Every household argmax is one lexicographic reduction: the weighted objective, then each member's value in declared order, then the smallest action id. Signed zeros compare equal and a NaN ranks below every number, so the winner depends neither on the declaration order of the actions nor on the block schedule. A feasible action whose objective is NaN gives NaN for every member on the dense and the streamed route alike. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
`scaled_lottery_mean` raises `UnsupportedDifferentiationError` under differentiation, as the other scaled helpers do. The read ledger, the candidate-certificate mutation and the query period groups test follow the source they describe, and a reduction's result in the N-NB-EGM kernel has a name the carry probe knows. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
…ivalent The regime slots `koopmans_aggregator` and `certainty_equivalent` accept a mapping keyed by member, with parameters under `koopmans_aggregator_<member>` and `certainty_equivalent_<member>`; a bare declaration is shared by every member under the bare key. A household may use a nonlinear certainty equivalent, additive shocks in its continuation and a `Decoupled` aggregator: it chooses on the weighted sum of the members' objectives and publishes each member's value. Intermediates and NaN diagnostics read the solve's own kernels and so cover regimes with a member axis. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
A regime with a member axis streams its solve over action blocks as any other regime does, takes the one-block route when the action product fits the planned width, streams its simulation decision, and may partition its actions over devices. The dense-only disposition for households and the refusal to partition them are gone. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
…egimes Another regime's exit may read the decision of a household with taste shocks, and such a household may declare its own exit: the decider's logit runs over its kept stays and its exit payoff, and every other member gets its expected value under the decider's probabilities. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
The aggregate, grouped-mapper and process-grid certificate tests pin the registered population of 409 mutations and its digests, as the grid-search certificate test does. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
`Model(stages={stage: (regimes, ...)})` orders the regimes of a period into
stages. `period` and `age` are economic time in user functions, parameters and
results; the engine links the stages of a period without discounting, a
transition lands in the next stage, and the simulation frame of a staged model
carries a `stage` column. A Koopmans aggregator or an endogenous-grid solver on
a stage that is not the last of its period is refused, and so is the regime
finder on a staged model.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
…ingle's route A regime with a member axis shards its continuous states over devices. A household with taste shocks takes the disposition of any regime with taste shocks and its policy lookup keeps the intermediates. One wrapper per core publishes the member axis across periods, the collective merge places both partials alike before stacking, and the household kernel takes its aggregator's own arguments. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
dags compares the annotations of every function in a regime, and the lambdas beside these functions cannot carry any. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
A program that reads a value another regime publishes in the same period is dispatched in a later wave than its publisher; the planner takes the reads from each program's declared transfers and refuses a cycle by naming the regimes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
A formation by `Consent` pays nothing: its target cannot declare a `utility_adjustment`. An exit observes a shock group whole or not at all. `MutualConsent` requires a settlement. In a `Decoupled` household a tie in the objectives goes to the members' stored values in declared order before the smallest action id. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
An edge of a staged model lands at the first later step that belongs to the target regime's stage: a later stage of the same period without discounting, or the next period with one discount. The meaning is a generated pass-through in every stage the target sits out, with the target's states, no action, no shocks, zero utility and the identity transition, so every link still leads to the next step. An exit may read a destination that decides later in the period; subjects start in their regime's own stage. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
… state The law of a shock that an exit, a consent rule or a renegotiation observes may read only parameters and states the projection returns unchanged, so it is the same at the source's state and at the landing state. One build-time check covers a group the caller also draws and a group only the destination draws, and replaces the discrete-only projection check and the pinning refusal. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
Two regimes pool only if they renegotiate over equal lists: the pooling kind holds each renegotiated state's name and nodes, in the search and, written separately, in the layout checker. The value roots of a `Phased` utility, aggregator, household objective and discount factor are registered for the solve and for the simulation, so a state read by either variant is kept and the checker rejects a layout that drops it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
A regime that sits out a stage has an engine-generated pass-through that the user never names: the parameter template, parameters of an edge that skips a stage, regime codes, declared starts, solved values, raw results, saved files and error messages show only declared regimes. An unstaged model never enters the pass-through code, so declaration errors keep their messages. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
Every value array ends in a member axis; a single's coordinate is "self". The measurement switch and its helper are gone. Versions: solver API 5, saved-solution schema 4 and format 4, fragment format 3, fingerprint tag 9, chunk-profile tag 6. A saved simulation result carries a format version and older files are refused. A household query without action axes reads its one candidate directly, and the weighted objective only selects the action, so derivatives pass through the published value. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
… period `Model.n_periods` and the result's `n_periods` count periods; `Model.n_steps` counts steps, and `Model.step_of`, `period_of_step` and `stage_of_step` convert. `period=` on `Model.lookup_policy`, `state_grid` and `initial_state_bounds` is the economic period. What is indexed by step says so: `SolutionResult.value`, `value_array` and `value_frame` take `step=`; `SimulationResult.step_to_regime_to_V_arr`; the reachability queries; `SolutionMetadata.n_steps`, `ArtifactRef.step` and the saved keys `n_steps`, `step` and `last_completed_step`, inside the format versions this pull request already moved; the solver API contexts. Messages print the period, and the stage of a staged model, where they printed a step. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
The summary check of the starting states called a type-checked function for every subject, which cost about 2.6 microseconds per subject (3 s for a million). One array test per regime replaces the loop. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
The engine passes the step to user functions, and a staged model wraps each function so that it reads the period of that step. The test breaks four kinds of law in one period only and asserts that validation reports that period. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
…-pass lottery mean The household reduction ranked every regime's actions on (objective, member values, action id) and read the objective a second time for the NaN rule. The compiler then stored the action values for every cell and action, the planner refused the widths that main chooses, and a warm call repeated the width search (Mahler and Yum, V100: warm 23.7 to 42.2 s, cold 67 s to 4:33 min, device peak 0.6 to 1.3 GB). - The NaN flag is an operand of the same reduction, for every regime. - A regime with one member has no tie keys; its solve reduces on the value and the NaN flag, its decision also on the action id. This is the second place that looks at the number of members. - The lottery mean is the two-pass form again; the one-pass form cost 1.3 s per warm call on an A100 for the same model. - Values across action-block widths, across devices and against the stored archives agree within 8 ULP with identical discrete choices; the archives are regenerated (largest change 2 ULP). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
- Rules: PCOnActions (participation constraints on actions; what Unilateral() was by default), PCOnWeight (participation constraints on the Pareto weight, with or without a weight state), MutualConsent with a Transfer. Unilateral, Renegotiate, Settlement and the keyword compares are removed. - Regime(composition_action=CompositionAction(destinations=...)) with Destination replaces Regime(exit=Exit(targets=...)) with ExitTarget; module lcm.composition_actions; parameter keys composition_action and transfer. - An agent is one person; a member is an agent's position in a regime with several agents: n_agents, agent_id, agent_batch_size, agent_devices, simulation_sharding="agents". - Documentation, messages and docstrings use: the decision on the composition, the value of the outside option, Pareto weight, transfer, a regime with one member. No value changes. Model fingerprints change because class and field names enter them; four identity strings that seed draws or name compiled programs keep their bytes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
- A solve without compilation on several devices failed in the value-only reduction: the winner's missing id was a free constant. - Two device layouts, a ceiled block width, a kept-intermediates lookup and a four-device capture are different compiled programs from their references: their tests assert equal choices and values within 8 ULP (per period back from the last one for the two-block solve, where a last-bit difference compounds). A replay still reproduces the solve its capture came from bit for bit. - aca-model pin moves to c87fd32b9, which has n_agents. - Model functions in the age-specialized tests are named and annotated. - Text: a member who must consent, not a deciding member, for the decision on the composition; member index kappa in formulas. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
With the member axis carried through the two-pass mean, the GPU compiler stored each node's exponent between the passes: one integer per cell, action and lottery node (French and Jones, A100: compiler peak +13.5 GiB in the working-age regimes, device peak 51.7 against 42.3 GB on main, narrower action blocks in four periods). The mean is now taken per member and the results are stacked; the compiler memory of every regime equals main's at fixed widths. The aca-model pin moves to 93dadb903 (same code, its CI runs against this branch). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
Where every alternative is worth minus infinity to the deciding member, a logit has no choice probabilities. The solve and the regime's own simulation already treat such a node as worth minus infinity to every member and raise when a simulation reaches it. A query on behalf of an agent who arrives there through a composition action took the first alternative and published its stored value instead. The shared draw now takes no alternative, and the simulation raises NoFeasibleActionError. Without taste shocks, a separate objective at minus infinity still acts by the stored values. Also: a helper defined twice in one test file had made an older test pass for the wrong reason; three more identical duplicates are removed. The reference page says that solvers other than GridSearch are refused for a regime with several members. Found by the external audit of round 2 (F7, H-R2-TEST-SHADOW, H-R1-DOC). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
…eclaration Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
…s destination A composition action whose destination sits in a later stage of the period reads the destination's published value at the landing state. That value does not say whether the destination has a feasible action there, and the read counted every landing as available. So a regime with several members could separate into a state where one member has no feasible action, and it published a value where no outcome exists. The read now also evaluates the destination's constraints at the landing state, over the destination's action grid, as a read of a destination in the same stage does. A destination that is feasible and worth minus infinity stays available. For that the destination of a later stage is admitted by the same rule as one in the source's own stage: GridSearch over its whole action grid. A later-stage destination solved by an endogenous-grid solver built before and is now refused when the model is built. Found by the external audit of the stage object (track stages, round 0, F2). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
…e once Four defects of models with several decisions in one period, each observed before the repair: - A policy lookup read every target at the next step. It now reads each target where the edge into it lands, by the same function as the simulation, so a lookup works when an edge skips a stage or crosses into the next period. - A regime with composite states that sits in a later stage was started in the first stage of its period, missed its edge, and made a reachable state infeasible. It now starts in its own stage. - The check whether a composition action is open at a period converted time twice for a predicate that depends only on the period. An action that opens later lost its parameters, and a closed action was kept. - The transition law of a member of a composite state got the period where it expects the step and converted it again, so a law that reads the period moved the state to the wrong value. Found by the external audit of the stage object (track stages, round 0, F1, F3, F4, F5). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K77bhs11cpunKfPpouVQHT
A composition action in an earlier stage reads the destination's published value. Keep the destination's shock plan at its own occurrence, where the landing check needs the physical shocks for its constraints. Require a feasible action at each shock node with positive weight. Addresses part 1 of #679.
The native archive loader verifies the payload and admits a private copy of its cached leaf. Return that copy from the guarded store path. Exercise cold and preloaded archives, exact replay, independent buffer lifetimes, unchanged archive bytes, and refusal before copy dispatch. Decision: ekl-guarded-replay-copy-pr670-20261128
mj023
left a comment
There was a problem hiding this comment.
Thanks, just found one small correctness bug when combining shock_paths and stages. For the future it might be good to split large renames from technical PRs, so that the diff does not blow up so much. Rename PRs can then be merged without review.
1. shock_paths read the wrong column on an edge that skips a stage. simulate.py:1437 reads the supplied draw at step + 1, but the edge lands at landing_step. With stages a: (alpha,), b: (omega,) and alpha → alpha (a discrete health lottery), the value held at step 2 comes from column 1 and the value at step 4 from column 3. Columns 2 and 4 are never read, so an invalid code there passes silently. _agent_occupancy also advances agents to step + 1, so it loses them once their target sits out that step: no later column is validated, an invalid code in a read column only fails as an InvalidStateTransitionError on the law, and a path one column short is filled with code 0. The docs say the transition into a step reads that step's column, so I think the read, the occupancy and the lag-1 declarations in _shock_declarations should all use landing_step. Since targets of one source can land at different steps, the supplied argument would need to be per target. No current test combines shock_paths with stages.
2. Two deleted tests I'd keep. Nothing that remains covers what they check:
test_egm_solver.py::test_egm_agrees_with_dense_grid_searchis the only check of plain EGM against a solver that doesn't invert the Euler equation, and this PR changes how EGM publishes its value.test_decoupled.py::test_ev1_simulated_choices_follow_the_acting_selfs_probabilitiesis the only test of simulated choice frequencies underDecoupled, whiledecoupled.pychanges substantially.
Bind target-specific operands for staged paths and validate the columns reached through the simulation graph, including entry in a later stage. Restore the independent dense EGM comparison and Decoupled taste-shock frequency check.
Closes #679.
Singles and households now use one solve and simulation engine. A regime defined with a plain utility function has one member,
"self". The PR removes the separate single-agent kernels and query branches and adds support for several decisions within one economic period.Model and API changes
memberaxis. Singles use the coordinate"self"and keep the simulated columnvalue.Regime.membersreplacesRegime.member_axis.Model(stages={stage_name: (regime_name, ...)}). User functions receive economicperiodandage. A step identifies one stage of one period. Model queries takeperiod=and find the regime's step. Solution accessors takestep=. Staged simulation results include astagecolumn.GridSearch.SOLVER_API_VERSIONis 5.Collective model names
Regime(exit=Exit(targets=...)),ExitTargetRegime(composition_action=CompositionAction(destinations=...)),DestinationUnilateral(compares="each_action")PCOnActions(tie=...)Unilateral(renegotiate=Renegotiate(state=...))PCOnWeight(state=..., tie=...)Unilateral(compares="optimum")PCOnWeight(tie=...)MutualConsent(settle=Settlement(...))MutualConsent(transfer=Transfer(...))n_subjects,subject_id,subject_batch_size,subject_devices,simulation_sharding="subjects"n_agents,agent_id,agent_batch_size,agent_devices,simulation_sharding="agents"lcm.exits, parameter keysexitandsettlelcm.composition_actions, parameter keyscomposition_actionandtransferComposition outside values are evaluated at the destination's landing state with the information available to the decider. The PR also aligns tie-breaking, minus-infinity values, and starts whose only feasible choice is a composition action. See the changelog for the full migration and behavioral details.
Verification
The stage audits and regression tests cover landing steps, the economic clock, feasibility, and destination shocks. The retained test suite includes the independent staged-game and numerical oracles. The deletion review removed 1,112 collected cases across 37 affected test files, including temporary engine-migration cases and repeated parameter combinations. The CI workload manifest was regenerated for the retained tests.
Performance against
mainHistorical A100 float64 measurements used an empty compilation cache in both arms.
mainBoth models used the same block widths in the two arms. The French and Jones values and simulated panel matched bit for bit. Issue #678 tracks the cache asymmetry in the automated benchmark comment.
Follow-ups
The #679 fix covers shocks drawn by the later-stage destination. Supporting endogenous-grid destinations would require publishing per-state feasibility alongside values. The later-stage edge parameter validation and invariant-component metadata observations in #679 remain follow-up work.
The existing follow-ups remain open in #671, #672, #673, #674, #675, #676, #677, and #678.