modelx.set_recursion#
- set_recursion(maxdepth=1000)[source]#
Set the maximum recursion depth for formula calculations.
Controls how deeply formulas can call other formulas before raising a recursion error. This is separate from Python’s recursion limit and applies specifically to modelx formula execution.
The default value of 1000 is suitable for most models. Increase it for models with very deep call chains, or decrease it to catch infinite recursion errors earlier.
- Parameters:
maxdepth (int) – Maximum depth of the modelx call stack. Must be a positive integer. Defaults to 1000.
Example
>>> import modelx as mx >>> mx.set_recursion(2000) # Allow deeper recursion >>> >>> @mx.defcells ... def factorial(n): ... return n * factorial(n-1) if n > 1 else 1 >>> >>> factorial(1500) # Would fail with default limit
Warning
Setting this too high may cause Python to run out of stack space before modelx detects the recursion limit.
See also
get_recursion(): Get current recursion limit