Repository navigation
Description
Problem
A regime that the solve values but the simulation never visits refuses parameters that only its simulate-phase functions read. get_params_template() omits them, and supplying them raises InvalidParamsError: Unknown keys.
This bites the Phased pre/post pattern: the "pre" regime after the switch is valued (agents believe they stay) but never visited. A paper that builds one params dict for all regimes sharing a function then has to strip the simulate-only keys for that regime by hand.
Minimal reproduction (pylcm c5d382aad)
import jax.numpy as jnp
from lcm import AgeGrid, LinSpacedGrid, Model, Phased, categorical
from lcm import Regime as UserRegime
from lcm.typing import ScalarInt
@categorical(ordered=False)
class RegimeId:
work: ScalarInt
retired: ScalarInt
dead_belief: ScalarInt
dead: ScalarInt
def u_belief(wealth, scale_belief):
return scale_belief * wealth
def u_actual(wealth, scale_actual):
return scale_actual * wealth
grid = LinSpacedGrid(start=0.0, stop=1.0, n_points=2)
model = Model(
regimes={
"work": UserRegime(
states={"wealth": grid},
state_transitions={"wealth": lambda wealth: wealth},
functions={"utility": lambda wealth: 0.0 * wealth},
),
"retired": UserRegime(
states={"wealth": grid},
state_transitions={"wealth": lambda wealth: wealth},
functions={"utility": lambda wealth: 0.0 * wealth},
),
"dead_belief": UserRegime(
states={"wealth": grid},
functions={"utility": Phased(solve=u_belief, simulate=u_actual)},
),
"dead": UserRegime(
states={"wealth": grid}, functions={"utility": lambda wealth: wealth}
),
},
ages=AgeGrid(start=0, inclusive_stop=2, step="Y"),
regime_id_class=RegimeId,
initial_nodes={0: "work"},
edges=Phased(
solve={"work": {"dead_belief": (0, 1)}, "retired": {"dead": (0, 1)}},
simulate={"work": {"retired": (0, 1)}, "retired": {"dead": (0, 1)}},
),
)
params = {
"discount_factor": 1.0,
"dead_belief": {"utility": {"scale_belief": 2.0, "scale_actual": 3.0}},
}
model.simulate(
params=params,
initial_conditions={
"age": jnp.array([0.0]),
"wealth": jnp.array([1.0]),
"regime_id": jnp.array([RegimeId.work]),
},
seed=0,
log_level="off",
)
# InvalidParamsError: Unknown keys: ['dead_belief__utility__scale_actual']Dropping scale_actual runs. get_params_template()["dead_belief"] lists only scale_belief.
Question
Should params read only by a phase that never runs for a regime be accepted (and ignored), or should the template keep listing them so a shared params dict validates? Either way, the current behavior forces per-regime stripping in user code.
Activity
hmgaudecker commentedon Oct 26, 2026
Closing with the explicit parameter policy: a phase that cannot run contributes no required parameters. Its unused keys stay out of get_params_template() and are rejected rather than silently ignored. Shared parameter dictionaries should be assembled from the actual model template. This behavior is recorded by the value-only and promoted-regime regressions in #604:
pylcm/tests/test_required_operation_contexts.py
Line 300 in 465cf78