utils
templates.rateml.utils
Usage in templates
<% from tvbo.templates.rateml.utils import cuda_code, python_code %> ${cuda_code(sv.equation.rhs)}
Classes
| Name | Description |
|---|---|
| CUDACodePrinter | CUDA code printer extending SymPy’s C99 printer. |
| NumbaPrinter | Python printer compatible with Numba’s nopython mode. |
CUDACodePrinter
templates.rateml.utils.CUDACodePrinter(settings=None)CUDA code printer extending SymPy’s C99 printer.
Handles: - powf instead of pow for floats - CUDA math functions (expf, sinf, etc.) - PI/INF macros
NumbaPrinter
templates.rateml.utils.NumbaPrinter()Python printer compatible with Numba’s nopython mode.
Uses numpy functions but avoids constructs Numba doesn’t support.
Functions
| Name | Description |
|---|---|
| cuda_code | Convert expression to CUDA code string. |
| get_boundary_str | Get boundaries as ‘lo, hi’ string for state variable clipping. |
| get_domain_str | Get domain as ‘lo, hi’ string for state variable initialization. |
| get_initial_value | Get initial value for state variable, with sensible default. |
| get_range_str | Get parameter range as ‘lo=x, hi=y, step=z’ string for NArray domain. |
| has_boundaries | Check if any state variable has boundaries defined. |
| python_code | Convert expression to Python/Numba code string. |
cuda_code
templates.rateml.utils.cuda_code(expr, local_dict=None)Convert expression to CUDA code string.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| expr | Any | SymPy expression, Equation object, or string | required |
| local_dict | Optional[Dict[str, Any]] | Optional dict of symbols for parsing strings | None |
Returns
| Name | Type | Description |
|---|---|---|
| str | CUDA code string |
get_boundary_str
templates.rateml.utils.get_boundary_str(sv)Get boundaries as ‘lo, hi’ string for state variable clipping.
get_domain_str
templates.rateml.utils.get_domain_str(obj)Get domain as ‘lo, hi’ string for state variable initialization.
get_initial_value
templates.rateml.utils.get_initial_value(sv)Get initial value for state variable, with sensible default.
get_range_str
templates.rateml.utils.get_range_str(param)Get parameter range as ‘lo=x, hi=y, step=z’ string for NArray domain.
has_boundaries
templates.rateml.utils.has_boundaries(model)Check if any state variable has boundaries defined.
python_code
templates.rateml.utils.python_code(expr, local_dict=None)Convert expression to Python/Numba code string.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| expr | Any | SymPy expression, Equation object, or string | required |
| local_dict | Optional[Dict[str, Any]] | Optional dict of symbols for parsing strings | None |
Returns
| Name | Type | Description |
|---|---|---|
| str | Python code string |