gEconpy.model.compile.sympy_to_pytensor#
- gEconpy.model.compile.sympy_to_pytensor(inputs, outputs, cache=None, cse=True)#
Convert sympy expressions to pytensor graph nodes.
This is the sympytensor bridge: it takes sympy symbols and expressions and returns the corresponding pytensor input and output nodes, along with the updated cache that maintains the mapping between sympy and pytensor symbols.
When
cse=True(default), runssp.cseon the output expressions first and binds the extracted intermediates as named pytensor nodes before converting the reduced outputs. This produces a graph with explicit subgraph sharing, which keepspt.gradfrom materializing the same backward subgraph hundreds of times. For DSGE-scale workloads the speedup on gradient compile is two orders of magnitude.- Parameters:
- inputs
listofsympySymbol Sympy input symbols.
- outputs
listofsympyexpression, orsympyMutableDenseMatrix Sympy output expressions.
- cache
dict, optional Dictionary mapping sympytensor cache keys to pytensor variables. Used to maintain a consistent namespace across multiple conversions. Default is an empty dictionary.
- csebool, optional
If True, run sympy’s common subexpression elimination on
outputsbefore converting to pytensor. Set False to bypass when outputs are guaranteed atomic (e.g., a single Symbol passthrough). Default True.
- inputs
- Returns: