TheVirtualBrain:

TheDocumentationwebsite.

Table Of Contents

This Page

backend Package

base

Simulator backends provide pluggable numerical implementations, allowing for different implementations or strategies.

  • Follows roughly the DAO pattern which isolates the service layer from database API - current simulator+datatypes is the compute “service” - backends back the compute service - service layer passes traited types into backend - backend handles the translation to a particular compute api (numpy, tf)
  • Isolates array creation, tracing, assist switching in float32
  • ‘Service’ layer receives closures or generator
  • Backend specifies preferred types and array creation routines
  • Components can then be associated with a component, e.g. - nest component uses nest backend - field componetn uses shtns backend
  • Isolates array creation, tracing, assist switching in float32
  • ‘Service’ layer receives closures or generator
  • Backend specifies preferred types and array creation routines
  • Components can then be associated with a component, e.g. - nest component uses nest backend - field componetn uses shtns backend
  • Multibackend-multicomponents need conversions done
class tvb.simulator.backend.base.BaseBackend[source]

Bases: builtins.object

Type tag for backends.

static default()[source]

Get default backend.

ref

This module provides a reference backend implemented with NumPy.

class tvb.simulator.backend.ref.RefBase[source]

Bases: builtins.object

Base methods for reference NumPy backend

static add_at()

at(a, indices, b=None)

Performs unbuffered in place operation on operand ‘a’ for elements specified by ‘indices’. For addition ufunc, this method is equivalent to a[indices] += b, except that results are accumulated for elements that are indexed more than once. For example, a[[0,0]] += 1 will only increment the first element once because of buffering, whereas add.at(a, [0,0], 1) will increment the first element twice.

New in version 1.8.0.

a : array_like
The array to perform in place operation on.
indices : array_like or tuple
Array like index object or slice object for indexing into first operand. If first operand has multiple dimensions, indices can be a tuple of array like index objects or slice objects.
b : array_like
Second operand for ufuncs requiring two operands. Operand must be broadcastable over first operand after indexing or slicing.

Set items 0 and 1 to their negative values:

>>> a = np.array([1, 2, 3, 4])
>>> np.negative.at(a, [0, 1])
>>> a
array([-1, -2,  3,  4])

Increment items 0 and 1, and increment item 2 twice:

>>> a = np.array([1, 2, 3, 4])
>>> np.add.at(a, [0, 1, 2, 2], 1)
>>> a
array([2, 3, 5, 4])

Add items 0 and 1 in first array to second array, and store results in first array:

>>> a = np.array([1, 2, 3, 4])
>>> b = np.array([1, 2])
>>> np.add.at(a, [0, 1], b)
>>> a
array([2, 4, 3, 4])
static evaluate(ex, local_dict=None, global_dict=None, out=None, order='K', casting='safe', **kwargs)[source]

Evaluate a simple array expression element-wise, using the new iterator.

ex is a string forming an expression, like “2*a+3*b”. The values for “a” and “b” will by default be taken from the calling function’s frame (through use of sys._getframe()). Alternatively, they can be specifed using the ‘local_dict’ or ‘global_dict’ arguments.

local_dict : dictionary, optional
A dictionary that replaces the local operands in current frame.
global_dict : dictionary, optional
A dictionary that replaces the global operands in current frame.
out : NumPy array, optional
An existing array where the outcome is going to be stored. Care is required so that this array has the same shape and type than the actual outcome of the computation. Useful for avoiding unnecessary new array allocations.
order : {‘C’, ‘F’, ‘A’, or ‘K’}, optional
Controls the iteration order for operands. ‘C’ means C order, ‘F’ means Fortran order, ‘A’ means ‘F’ order if all the arrays are Fortran contiguous, ‘C’ order otherwise, and ‘K’ means as close to the order the array elements appear in memory as possible. For efficient computations, typically ‘K’eep order (the default) is desired.
casting : {‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional

Controls what kind of data casting may occur when making a copy or buffering. Setting this to ‘unsafe’ is not recommended, as it can adversely affect accumulations.

  • ‘no’ means the data types should not be cast at all.
  • ‘equiv’ means only byte-order changes are allowed.
  • ‘safe’ means only casts which can preserve values are allowed.
  • ‘same_kind’ means only safe casts or casts within a kind, like float64 to float32, are allowed.
  • ‘unsafe’ means any data conversions may be done.
static heaviside(array)[source]

heaviside() returns 1 if argument > 0, 0 otherwise.

The copy operation here is necessary to ensure that the array passed in is not modified.

static iround(number) → integer[source]

Trying to get a stable and portable result when rounding a number to the nearest integer.

NOTE: I’m introducing this because of the unstability we found when using int(round()). Should use always the same rounding strategy.

Try : >>> int(4.999999999999999) 4 >>> int(4.99999999999999999999) 5

static linear_interp1d(start_time, end_time, start_value, end_value, interp_point)[source]

performs a one dimensional linear interpolation using two timepoints (start_time, end_time) for two floating point (possibly NumPy arrays) states (start_value, end_value) to return state at timepoint start_time < interp_point < end_time.

numexpr = <module 'numexpr' from '/opt/conda/envs/tvb-run/lib/python3.7/site-packages/numexpr/__init__.py'>
class tvb.simulator.backend.ref.RefSurface[source]

Bases: tvb.simulator.backend.ref.RefBase

Surface/field-related methods.

static full_region_map(surf, conn)[source]

Generate a full region mapping vector.

static surface_state_to_rois(_regmap, n_reg, state)[source]
class tvb.simulator.backend.ref.ReferenceBackend[source]

Bases: tvb.simulator.backend.base.BaseBackend, tvb.simulator.backend.ref.RefSurface

Base reference backend, implemented in readable NumPy.