PyRates.pyrates.backend.base pyrates.backend.base module

default PyRates backend. Contains all pyrates-internal function definitions and links to numpy functions. pyrates.backend.base.base_backend module

Contains wrapper classes for different backends that are needed by the parser module.

A new backend needs to implement the following methods: - __init__ - run - add_var - add_op - add_layer

Currently supported backends: - Numpy: BaseBackend. - Tensorflow: TensorflowBackend. - Fortran: FortranBackend (experimental).

class pyrates.backend.base.base_backend.BaseBackend(ops: Dict[str, str] | None = None, imports: List[str] | None = None, **kwargs)[source]

Bases: CodeGen

Default backend class. Transforms all network equations into their numpy equivalents. Based on a Python code generator.

add_import(line: str)[source]
add_var_hist(lhs: str, delay: ComputeVar | float, state_idx: str, **kwargs)[source]
add_var_update(lhs: ComputeVar, rhs: str, lhs_idx: str | None = None, rhs_shape: tuple | None = ())[source]

Deletes all code lines from the memory of the generator.

create_index_str(idx: str | int | tuple, separator: str = ',', apply: bool = True, **kwargs) Tuple[str, dict][source]
static expr_to_str(expr: str, args: tuple)[source]
static finalize_idx_str(var: ComputeVar, idx: str)[source]
generate_func(func_name: str, to_file: bool = True, **kwargs)[source]
generate_func_head(func_name: str, state_var: str = 'y', return_var: str = 'dy', func_args: list | None = None, add_hist_func: bool = False)[source]
generate_func_tail(rhs_var: str = 'dy')[source]
get_fname(f: str) tuple[source]
static get_hist_func(y: ndarray)[source]
get_op(name: str, **kwargs) dict[source]
get_var(v: ComputeVar)[source]
static register_vars(variables: list)[source]
run(func: Callable, func_args: tuple, T: float, dt: float, dts: float, solver: str, **kwargs) tuple[source]
static to_file(fn: str, **kwargs)[source]
class pyrates.backend.base.base_backend.CodeGen[source]

Bases: object

Generates python code. Can add code lines, line-breaks, indents and remove indents.


Add code line string to code.


Add an indent to the code.


Add a line-break to the code.


Deletes all code lines from the memory of the generator.


Generates a single code string from its history of code additions.


Remove an indent to the code. pyrates.backend.base.base_funcs module

Contains function definitions that may be used for PyRates model equations.

pyrates.backend.base.base_funcs.index_1d(x, idx)[source]
pyrates.backend.base.base_funcs.index_2d(x, idx1, idx2)[source]
pyrates.backend.base.base_funcs.index_axis(x, idx=None, axis=0)[source]
pyrates.backend.base.base_funcs.index_range(x, idx1, idx2)[source]
pyrates.backend.base.base_funcs.past(x, tau)[source]