pyperfectforesight.compile_steady_state_funcs#

pyperfectforesight.compile_steady_state_funcs(equations, vars_dyn, vars_exo=None)[source]#

Compile steady-state residual functions once for repeated use with different parameters.

Separates the symbolic work (SymPy substitutions and lambdification) from the numerical solving so that parameter sweeps pay the symbolic cost only once.

Exogenous variables are treated as free parameters in the compiled functions so that solve_steady_state can evaluate the steady state at any given exogenous level — not just at zero. Pass the desired exogenous values via the exog_ss argument of solve_steady_state; omitting it defaults to zero (the standard assumption for deviation-from-steady-state models).

Parameters:
  • equations (list) – List of model equations (same as passed to process_model).

  • vars_dyn (list) – List of endogenous variable names.

  • vars_exo (list, optional) – List of exogenous variable names (default: None). Each exogenous variable is represented by a steady-state symbol {var}_exo_ss in the compiled functions. Their numerical values are supplied at solve time via solve_steady_state(..., exog_ss=...).

Returns:

Compiled steady-state bundle to be passed to solve_steady_state():

  • 'funcs': list of lambdified residual functions. Each function signature is f(*ss_vals, *param_vals, *exo_ss_vals) in the variable orders given by ss_syms, param_syms, and exo_ss_syms respectively.

  • 'ss_syms': list of SymPy symbols for steady-state endogenous values (one per variable in vars_dyn, in the same order).

  • 'param_syms': sorted list of SymPy parameter symbols detected in the equations after time-indexed variables are collapsed.

  • 'exo_ss_syms': list of SymPy symbols for the exogenous steady-state values (one per variable in vars_exo, in order). Empty list when vars_exo is None or empty.

  • 'vars_dyn': copy of the vars_dyn list.

  • 'vars_exo': copy of the vars_exo list (empty list if None).

Return type:

dict

Examples

Compile once, then sweep over parameter values (exogenous variables at zero):

>>> compiled_ss = compile_steady_state_funcs(equations, vars_dyn)
>>> for params in param_grid:
...     ss = solve_steady_state(compiled_ss, params)
...     result = solve_perfect_foresight(T, params, ss, model_funcs, vars_dyn)

Compile once, then solve the steady state at a non-zero exogenous level (e.g. after a permanent technology shock where z settles at 1.05):

>>> compiled_ss = compile_steady_state_funcs(equations, vars_dyn, vars_exo)
>>> ss_terminal = solve_steady_state(compiled_ss, params, exog_ss=np.array([1.05]))