1.1.1.1. PyRates.pyrates.backend.base

1.1.1.1.1. pyrates.backend.base module

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

1.1.1.1.2. 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: Optional[Dict[str, str]] = None, imports: Optional[List[str]] = 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: Union[ComputeVar, float], state_idx: str, **kwargs)[source]
add_var_update(lhs: ComputeVar, rhs: str, lhs_idx: Optional[str] = None, rhs_shape: Optional[tuple] = ())[source]
clear()[source]

Deletes all code lines from the memory of the generator.

create_index_str(idx: Union[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: Optional[list] = 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, outputs: dict, solver: str, **kwargs) dict[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(code_str)[source]

Add code line string to code.

add_indent()[source]

Add an indent to the code.

add_linebreak()[source]

Add a line-break to the code.

clear()[source]

Deletes all code lines from the memory of the generator.

generate()[source]

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

remove_indent()[source]

Remove an indent to the code.

1.1.1.1.3. pyrates.backend.base.base_funcs module

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

pyrates.backend.base.base_funcs.identity(x)[source]
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]