pyperfectforesight.process_model#
- pyperfectforesight.process_model(equations, vars_dyn, vars_exo=None, vars_aux=None, aux_method='auto', eliminate_static_vars=True, compiler='lambdify')[source]#
Process model equations and compile to numeric functions
Parameters:#
- equationslist
List of model equations
- vars_dynlist
List of endogenous (dynamic) variable names
- vars_exolist, optional
List of exogenous variable names (default: None)
- vars_auxlist, optional
List of auxiliary variable names - static variables to be determined from dynamic and exogenous variables (default: None).
- aux_methodstr, optional
Method for handling auxiliary variables (default:
'auto'):'auto': Try analytical first; if SymPy can’t solve, treat as dynamic. Best default — fast when possible, robust when needed. (Similar to Dynare: eliminate if possible, else keep in system.)'analytical': Force analytical method only. Faster but will fail if SymPy cannot solve the auxiliary equations symbolically.'nested': Force post-solve numerical solving of auxiliary equations. After the main solver converges, auxiliary variables are solved period-by-period usingscipy.optimize.rootwith warm starting. Requires a square auxiliary system and auxiliary variables appearing only in auxiliary equations; raisesValueErrorotherwise. Use when analytical solve fails and these structural conditions hold; otherwise prefer'dynamic'.'dynamic': Treat auxiliary variables as dynamic. Auxiliary equations included in main system. Single optimization, higher dimension.
- eliminate_static_varsbool
Whether to eliminate non-auxiliary static variables (default: True)
- compilerstr
Compilation method: ‘lambdify’ (default), or other backends
Returns:#
- dictDictionary containing:
‘dynamic_eqs’: Processed dynamic equations
‘blocks’: Symbolic Jacobian blocks
‘all_syms’: Sorted list of all symbols
‘block_funcs’: Compiled Jacobian block functions (lag → matrix lambda)
‘block_elem_funcs’: Per-element scalar lambdas for each Jacobian block (lag → neq×n list of scalar-valued lambdas); broadcast correctly over numpy array inputs, unlike the matrix lambda in block_funcs
‘residual_funcs’: Compiled residual functions
‘incidence’: Lead/lag incidence information
‘vars_dyn’: List of dynamic variable names
‘vars_exo’: List of exogenous variable names
‘vars_aux’: List of auxiliary variable names
‘aux_method’: Method used for auxiliary variables
‘aux_eqs’: Symbolic auxiliary equations
‘aux_eqs_funcs’: Compiled residual functions for auxiliary equations (nested method)
‘aux_eqs_syms’: Sorted list of all free symbols appearing in auxiliary equations (nested method)
‘aux_sols’: Analytical solutions for auxiliary variables (analytical method)
‘aux_funcs’: Compiled evaluation functions (analytical method)
Notes:#
Recommended usage:
'auto'(default): Best for most cases — tries analytical, falls back to dynamic. Like Dynare: eliminate if possible, else keep in system.'analytical': When equations are simple (e.g.i = y - c - g) and guaranteed fast performance with no fallback is desired.'nested': When nested post-solve optimization is explicitly preferred (rare).'dynamic': To skip the analytical attempt and treat aux vars as dynamic.
The analytical method solves equations symbolically then evaluates (fastest). The dynamic method includes auxiliary equations in main system (Dynare-style). The nested method solves auxiliary variables post-solve, period-by-period.