Skip to content

Choose transition rules for supplied AR1 nodes - #626

Merged
hmgaudecker merged 1584 commits into
mainfrom
codex/on-nodes-transition-rules
Nov 5, 2026
Merged

hmgaudecker merged 1584 commits into
mainfrom
codex/on-nodes-transition-rules

Conversation

@hmgaudecker

@hmgaudecker hmgaudecker commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Models using supplied AR(1) state nodes can choose how transition probabilities are computed through TauchenAR1Process.on_nodes:

  • Midpoint bins preserve the existing default.
  • Innovation quadrature maps normal innovations linearly onto the supplied nodes.
  • Normalized node densities weight the supplied nodes by their conditional normal density.

Quadrature accepts a Gauss–Hermite node count or explicit standardized nodes and weights. Targets outside the state grid are clipped to its endpoints. Parameters and innovation scales can vary at runtime or with the current state.

Node-based simulation uses the selected transition matrix. Continuous simulation keeps its conditional normal draws.

The implementation also stabilizes density calculations and quadrature allocation over extreme numerical ranges. Targeted CPU and A100 tests cover transition probabilities, derivatives, Bellman expectations and simulation.

Density-rule derivatives use normalized scaled arithmetic. The stronger finite-row accuracy certificate is retained in private _lcm as a deliberately invoked developer/test oracle. It is documented with its input scope and success-or-rejection guarantee; it does not run during routine differentiation, solving or simulation at either runtime_checks setting. Routine derivatives do not carry that certificate's componentwise accuracy guarantee. The usual probability and finiteness checks remain controlled by runtime_checks.

Density stabilization adds compilation and memory cost in the measured small-model workload; this is not a performance estimate for every model.

Stacked on #625. Closes #586.

Validation: CPU CI · GPU CI.

@read-the-docs-community

read-the-docs-community Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

@hmgaudecker
hmgaudecker changed the base branch from codex/607-engine-redesign to codex/553-declared-target-validation October 25, 2026 16:29
@hmgaudecker
hmgaudecker requested review from mj023 and timmens October 26, 2026 14:33

@mj023 mj023 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, no big errors that would have any impact on model execution etc. But I found some minor things that should be fixed and some cleanups that could be done before merging.

1. DensityDerivativeAccuracyError docstring promises a guard that doesn't run (src/lcm/exceptions.py:225)
The docstring says an out-of-budget derivative is rejected and that "under JIT the runtime callback reports this error". Routine AD never runs the certificate. For the row your own rejection test uses (family="central", rho), _certify_density_derivative_row raises, but jax.jit(jax.jacfwd(...)) returns 0 for the middle component instead of the reference -1.85e239, without any error. The case is extreme, but a public docstring shouldn't promise error control that doesn't exist. Could it be reworded to match the user guide, so it says the error comes only from the explicit developer certificate?

2. Test-only certificate is shipped and imported with the library (src/_lcm/processes/ar1.py:35)
density_derivative_admission.py (about 630 lines) is loaded on every import lcm, but only the private _certify_density_derivative_row oracle uses it. Since it doesn't run in solve, simulate or AD, could it live under tests/ next to test_density_derivative_accuracy.py, or at least be imported lazily inside the certify function? Then the public exception could move with it.

3. Unrelated CI change (.github/workflows/benchmark-pr.yml)
cancel-in-progress: false means a new push no longer cancels a running GPU benchmark for an outdated commit. That isn't mentioned in the description and seems unrelated to on_nodes. Was it intentional?

Cleanup

  • _checked_density_coefficients still carries the io_callback exemption and docstring, but nothing registers it as a callback; calling _certify_density_coefficients directly would remove the wrapper.
  • The user guide tells readers to call the private _lcm.processes.ar1._certify_density_derivative_row; that part could go in developer docs or just point at the test file.
  • _get_conditioned_weights_func reads fixed["rho"] in the new branch, though rho_fixed is already bound a few lines above.
  • The "Unknown on_nodes transition_rule" check can't fire, because beartype rejects a wrong Literal first, and a single TransitionRule alias would replace the four copies of that Literal.

@hmgaudecker

Copy link
Copy Markdown
Member Author

Thanks, all addressed:

  1. DensityDerivativeAccuracyError docstring. Agreed — it overstated the guard. It now says the error comes only from a deliberate call to the certificate, and that solve, simulation and routine AD return an out-of-budget row without raising (1a56a1e). Since the certificate moved to the tests (see 2), the exception moved with it.

  2. Certificate shipped with the library. Moved. density_derivative_admission.py now lives in tests/test_models/ next to the other oracles, together with the row entry point and DensityDerivativeAccuracyError, so import lcm no longer loads it and the public exception is gone (b4b86ea).

  3. cancel-in-progress: false in benchmark-pr.yml. Agreed, that doesn't belong here. Reverted (ff2783f); false stays only in benchmark-main.yml.

Cleanups:

  • io_callback wrapper: removed; the entry point calls _certify_density_coefficients directly (b4b86ea).
  • User guide: it now points at the test file and the pytest command instead of the private function (b4b86ea).
  • rho_fixed: kept fixed["rho"] on purpose. rho_fixed is fixed.get("rho"), which is optional because the IID path has no rho, and ty rejects passing it to compute_transition_row. The subscript narrows the type and fails loudly if rho were ever absent.
  • Literal copies / dead check: one TransitionRule alias now, the unreachable check is deleted, and a test pins that an unknown rule is refused with GridInitializationError (6e6db8b).

hmgaudecker and others added 22 commits October 29, 2026 22:44
read_nbegm_resources_bank refused any resources outside the range the
solve's wealth grid times quadrature nodes spans. Fresh period-0 draws
beyond the nodes landed there, and simulate refused with "unresolved row
integrity" although the Euler row extrapolates to the exact solution.
The support bound was a domain check, not a semantic one; the finite,
positivity and savings-bound checks stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
close_prepared_case_r_parent_demands re-traced the whole native kernel
only to confirm that attaching parent demands left the frozen output
schema unchanged. Lowering already asserts the output roles on every
compiled core, so the second trace was a redundant audit: 2.5-4 s of
params validation on the Case-R toy, outputs unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
GridSearch now admits literal and callable floors with shocks=, the
bound evaluated per node against the realized draw as on the node-state
route; DCEGM/NBEGM admit the literal floor at the savings-grid origin,
which is aca's only EGM constraint. Callable floors under EGM and query
reconstruction stay refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
Arrival queries evaluated a landing process state at its node position
instead of its value (23.34 vs 5.077 on the collective toy; 11 vs 10 on
a Tauchen AR(1)), which also crashed z_code reads. Arrivals now price a
target's value-dependent constraint from the transported same-period
values, root their predicates and projections against pruning, get the
gated-edge projection-coverage check, clip or raise on off-grid
fallbacks, refuse off-node process codes, and validate read keys as
parameter-path segments. Runtime-parameterised process landings in an
arrival target are refused at build instead of silently mispriced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
Certificate conflicts were digest-only; kept HEAD, then re-anchored with
repin_corridors.py and check_seals.py --fix. Registered the two new test
files in ci-workloads.json on top of HEAD's manifest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
Strip the three deleted gate test files from ci-workloads.json and
re-derive the shards; drop the two of them that the collective surface
census listed as engine-level modules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
The ledger described the removed inverse-marginal-utility scope gate in
_redecide_branch_and_read_policy; the read is gone, so the row goes.
FUES now enables the policy read, so the solve compiles the replay
program in place of main; the compiler-option test asserts that layout
and that the option reaches the program actually compiled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
Step 1 published a simulation policy for every plain DCEGM regime, and
lookup_policy refused any regime with one. It now calls simulate's own
policy-first read and falls back to the grid decision only for rejected
rows. The reader is one jitted program with the period traced, so
periods sharing a kernel share a compile: Iskhakov 10k cold simulate
6.0 s -> 5.1 s, warm 0.19 s, means unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
Also folds in the s12fix follow-ups, since only merge commits are made here:

- s12g2-xfail-flips.patch: the six arrival strict xfails become plain tests;
  the `dissolution_fallbacks` xfail stays.
- migration-fixups.patch: s12fix's arrival migrations of the pruning-roots,
  projection-coverage, simulate-guards, produced-values and route-scheduling
  tests replace the g1 versions where they overlap, dropping the state-only
  Gate stand-ins the arrival path now supports.
- test_process_code_binding: an arrival landing in a runtime-parameterised
  process is refused at build; a state-only Gate that does not read the
  process keeps it supported, pinning the scope of the Gate's refusal.
- Strip the deleted test_dissolution_flag_retention.py from ci-workloads.json,
  drop a helper whose only user was deleted, and remove the two modules that
  now reach `Model` from the collective surface census's engine-level set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
Their oracles are the parent's argmax over the declared consumption
grid, which put the child on its corner. Since step 1 the plain DCEGM
parent simulates policy-first and picks the continuous optimum (value
1.524 vs 0.832 for the grid choice), so the tests now opt into the
existing replay="grid" route to keep their oracle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
Nested EGM replay emits the read's winner and scores canonical Q once on
it instead of rescoring the whole bank against a grid baseline; finite
NNBEGM ranks the bank by published value, keeps the semantic
feasibility mask over the bank, and loses the dropped-candidate audit
and its host sync; Case-R/U status is one device-side code read once
per regime-period. Finite NNBEGM toy cold simulate 4.5 s -> 1.6 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
The lookup lane moved canonical-Q evaluation into the compiled reader,
which reaches `_evaluate_canonical_Q_at_actions` through the regime's
`Q_and_F` slot; the stub test patched the old outer seam and its stub
regime lacked the slot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K77bhreFhbLuuKA6zCbv8t
hmgaudecker and others added 19 commits November 3, 2026 01:07
…hort

The module fixture simulated four periods from a cohort of singles, which
compiles the exit and participation-entry simulation programs for two
landings. Cold, that fixture alone took about nine minutes and 7.8 GB on
CPU, past the 600 s per-test timeout under xdist. Starting half the cohort
married lets three periods carry a marriage and a dissolution in one
landing, and the dissolution test now names the period and both single
regimes it lands in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hs8mfXPYyEa24KaAp6BwCW
…et-validation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hs8mfXPYyEa24KaAp6BwCW
JAX 0.12.0.1 and NumPy 2.5.4 change dependency-bound model identities and
compiled workspace reservations. Re-pin all seven models at both precisions.
Fresh probes confirm that execution-policy changes leave those identities
unchanged.

Use the measured 33,884-byte bracket: the period-1 width-2 pair needs 33,820
bytes, the period-0 width-2 pair needs 33,948, and width 1 needs 27,212.
The existing paired-admission checks retain their fit/refuse behavior.

Adopt the two dependency witnesses from 0bb9b170c and 5d826116c after
independent checks against the numerical-repair source e56d64f.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hs8mfXPYyEa24KaAp6BwCW
Use the approved one-ULP bound for broadcast, fixed-component and FUES
floating outputs compiled with different execution shapes. Keep array
metadata, nonfinite patterns, integer counts and simulated discrete
outcomes exact. Engine arithmetic and other numerical gates are unchanged.

Both CPU precisions execute all 159 selected cases without failure.
Positive and negative controls exercise the bound and exactness checks.
The replay worker dies 600 seconds after starting in the shared CPU CI
shard. The unchanged covered case passes in a fresh process. Deselect it
from the parallel shard and run it alone afterward, retaining its full
fixture, exact frame comparison and 600-second timeout. Append its
coverage to the owning shard report and mark it fresh for the policy
launcher.

Record both precision invocations in the workload manifest. All 775 CI
contract cases pass. Real collection proves disjoint unions of 1040+1 and
640+1 cases, matching the original CI inventories without losses. A real
coverage check confirms append preserves prior coverage and its negative
control loses it. Actual GitHub CI remains required after push.
A correctness update must not discard the benchmark measurements already
running for review. Match the main benchmark policy: finish the active
run and queue the latest revision in the existing concurrency group.
Runners, GPU locking, measurement commands and timeouts are unchanged.

The regression reproduces the cancelling PR policy against the existing
non-cancelling main policy. All 777 CI-contract cases and all-file Prek
pass. Verify actual old-run preservation and the new queue after push.
Keep benchmark-pr cancel-in-progress true within its existing branch
group, and keep benchmark-main false. Correct the regression contract to
check the two intended policies instead of requiring both to retain runs.

The published false PR policy fails the corrected contract. The local
correction passes all 777 CI-contract cases and all-file Prek. Hold this
commit locally for the next fixes batch, as requested.
Keep the 1,000-subject measurements active and skip all four 100,000-subject measurements before setup. Track the deferred performance repair in #638.
…codex/cascade-pr625-20261103

# Conflicts:
#	tests/candidate_certificate/direct_flow.py
#	tests/candidate_certificate/sources.json
…20261103

# Conflicts:
#	tests/candidate_certificate/direct_flow.py
#	tests/candidate_certificate/sources.json
#	tests/ci/ci-workloads.json
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Benchmark comparison (main → HEAD)

Comparing c8430c80 (main) → 7b7d2980 (HEAD)

Benchmark Statistic before after Ratio Alert
ACA (reduced) warm solve + simulate (reuses compiled code) 43.816 s 102.016 s 2.33 ❌
cold solve + simulate (first run, includes compilation) 791.91 s 813.76 s 1.03
peak CPU mem 7.54 GB 6.82 GB 0.90
Mahler-Yum warm solve + simulate (reuses compiled code) 5.853 s 6.080 s 1.04
cold solve + simulate (first run, includes compilation) 18.37 s 19.22 s 1.05
peak CPU mem 1.69 GB 1.66 GB 0.98
peak GPU mem: automatic solve + simulate 1.61 GB 1.61 GB 1.00
peak GPU mem: load saved solution + simulate 1.89 GB 1.89 GB 1.00
peak GPU mem: solve + save all persistable artifacts 571 MB 571 MB 1.00
Precautionary Savings - Solve execution time 259.9 ms 84.6 ms 0.33
first call (including compilation) 1.55 s 1.30 s 0.84
peak CPU mem 1.44 GB 1.44 GB 1.00
Precautionary Savings - Simulate execution time 900.0 ms 943.3 ms 1.05
peak GPU mem 324 MB 324 MB 1.00
first call (including compilation) 2.91 s 3.40 s 1.17 ❌
peak CPU mem 1.59 GB 1.57 GB 0.99
Precautionary Savings - Solve & Simulate execution time 866.3 ms 684.3 ms 0.79
peak GPU mem 1.50 GB 1.51 GB 1.00
first call (including compilation) 4.07 s 4.29 s 1.05
peak CPU mem 1.54 GB 1.53 GB 0.99
Precautionary Savings - Solve & Simulate (irreg) execution time 997.5 ms 812.8 ms 0.81
peak GPU mem 2.20 GB 2.21 GB 1.00
first call (including compilation) 4.20 s 4.46 s 1.06
peak CPU mem 1.54 GB 1.53 GB 0.99
Iskhakov et al. (2017) - GridSearch Solve execution time 363.4 ms 182.5 ms 0.50
peak GPU mem 120 MB 120 MB 1.00
first call (including compilation) 2.81 s 2.35 s 0.83
peak CPU mem 1.57 GB 1.63 GB 1.04
Iskhakov et al. (2017) - DC-EGM Solve execution time 651.1 ms 841.9 ms 1.29 ❌
first call (including compilation) 6.13 s 6.67 s 1.09
peak CPU mem 1.85 GB 1.97 GB 1.06
Iskhakov et al. (2017) - GridSearch Simulate execution time 1.011 s 946.8 ms 0.94
peak GPU mem 892 MB 891 MB 1.00
first call (including compilation) 6.54 s 6.93 s 1.06
peak CPU mem 1.70 GB 1.77 GB 1.04
Iskhakov et al. (2017) - DC-EGM Simulate execution time 1.115 s 1.281 s 1.15 ❌
peak GPU mem 891 MB 891 MB 1.00
first call (including compilation) 6.84 s 9.13 s 1.33 ❌
peak CPU mem 1.92 GB 2.08 GB 1.08
Collective Household - Construct execution time 735.8 ms 1.508 s 2.05 ❌
peak CPU mem 1.40 GB 1.43 GB 1.02
Collective Household - Solve execution time 481.2 ms 5.278 s 10.97 ❌
first call (including compilation) 2.88 s 56.02 s 19.44 ❌
peak CPU mem 1.46 GB 4.60 GB 3.15 ❌
Collective Household - Simulate (1000) execution time 1.189 s 32.898 s 27.67 ❌
first call (including compilation) 14.59 s 512.56 s 35.13 ❌
peak CPU mem 1.48 GB 23.66 GB 15.98 ❌
Collective Household - Simulate (100000) execution time 1.220 s nan µs nan
peak GPU mem 189 MB nan MB nan
first call (including compilation) 15.33 s nan s nan
peak CPU mem 1.56 GB nan MB nan
Reference Chain - Solve (1) execution time 217.7 ms 37.7 ms 0.17
first call (including compilation) 1.76 s 1.53 s 0.87
peak CPU mem 1.12 GB 1.16 GB 1.04
Reference Chain - Solve (8) execution time 492.7 ms 249.8 ms 0.51
first call (including compilation) 5.80 s 5.37 s 0.93
peak CPU mem 1.23 GB 1.28 GB 1.05
SimulationDispatch ('dissolution', 'off') warm simulation time per period and regime (ms) 45.77 ms 80.61 ms 1.76 ❌
backend compile requests on second simulation call 0
SimulationDispatch ('dissolution', 'progress') warm simulation time per period and regime (ms) 44.76 ms 82.30 ms 1.84 ❌
backend compile requests on second simulation call 0
SimulationDispatch ('multi_regime', 'off') warm simulation time per period and regime (ms) 49.92 ms 54.25 ms 1.09
backend compile requests on second simulation call 0
SimulationDispatch ('multi_regime', 'progress') warm simulation time per period and regime (ms) 48.43 ms 53.04 ms 1.10
backend compile requests on second simulation call 0

Publish original current shocks separately from the final actor realization, including participation fallback observations. Keep simulation inputs and draws unchanged, retain discrete report codes, and report the stored coordinates for missing values.
hmgaudecker added a commit that referenced this pull request Nov 4, 2026
Base automatically changed from codex/553-declared-target-validation to main November 5, 2026 07:32
@hmgaudecker
hmgaudecker merged commit 0fb5567 into main Nov 5, 2026
63 of 66 checks passed
@hmgaudecker
hmgaudecker deleted the codex/on-nodes-transition-rules branch November 5, 2026 07:33
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.

TauchenAR1Process.on_nodes: let the caller choose the transition rule

2 participants