TheVirtualBrain:

TheDocumentationwebsite.

Table Of Contents

Previous topic

contrib Package

Next topic

from_articles Package

This Page

cosimulation Package

cosim_history

class tvb.contrib.cosimulation.cosim_history.CosimHistory(n_time, n_var, n_node, n_mode)[source]

Bases: tvb.simulator.history.BaseHistory

Class for cosimulation history implementation. It stores the whole TVB state for the co-simulation synchronization time. The synchronization time has to be shorter than the maximum delay (it usually is equal to the minimum delay of coupling between the co-simulators). It is a DenseHistory since the whole state has to be stored for all delays.

buffer

Data descriptor for a NumPy array, with type, mutability and shape checking.

cvars = None
delays = None
classmethod from_simulator(sim)[source]
initialize(history, voi, current_step=0)[source]

Initialize CosimHistory from the TVB history which is assumed already configured.

n_mode

Specialization of Final to int/long type.

n_node

Specialization of Final to int/long type.

n_time

Specialization of Final to int/long type.

n_var

Specialization of Final to int/long type.

nbytes[source]
query(step)[source]

This method returns the whole TVB current_state by querying the CosimHistory state buffer for a time step.

update(step, new_state)[source]

This method will update the CosimHistory state buffer with the whole TVB state for a specific time step.

update_state_from_cosim(steps, new_states, vois, proxy_inds)[source]

This method will update the CosimHistory state buffer from input from the other co-simulator, for - the state variables with indices vois, - the region nodes with indices proxy_inds, - and for the specified time steps.

weights = None

cosim_monitors

class tvb.contrib.cosimulation.cosim_monitors.CosimCoupling(**kwargs)[source]

Bases: tvb.simulator.monitors.AfferentCoupling, tvb.contrib.cosimulation.cosim_monitors.CosimMonitorFromCoupling

A monitor that records the future coupling of selected variables: It collects:

  • selected coupling values and all modes from class :Model:
  • all nodes of a region or surface based
  • all the integration time steps

variables_of_interest : tvb.simulator.monitors.AfferentCoupling.variables_of_interest = NArray(label=’Indices of coupling variables to record’, dtype=int64, default=None, dim_names=(), ndim=None, required=False)

period : tvb.simulator.monitors.Raw.period = Float(field_type=<class ‘float’>, default=0.0, required=True)

coupling : tvb.contrib.cosimulation.cosim_monitors.CosimMonitorFromCoupling.coupling = Attr(field_type=<class ‘tvb.simulator.coupling.Coupling’>, default=<tvb.simulator.coupling.Linear object at 0x7f008529ed90>, required=True)
The coupling function is applied to the activity propagated between regions by the Long-range connectivity before it enters the local dynamic equations of the Model. Its primary purpose is to ‘rescale’ the incoming activity to a level appropriate to Model.

gid : tvb.basic.neotraits._core.HasTraits.gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=True)

sample(current_step, start_step, n_steps, cosim_history, history)[source]

Return selected values of future coupling from (up to synchronization time) cosimulation history

class tvb.contrib.cosimulation.cosim_monitors.CosimMonitor(**kwargs)[source]

Bases: tvb.basic.neotraits._core.HasTraits

Abstract base class for cosimulation monitors implementations.

gid : tvb.basic.neotraits._core.HasTraits.gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=True)

sample(current_step, start_step, n_steps, cosim_history, history)[source]

This method provides monitor output, and should be overridden by subclasses. Use the original signature.

class tvb.contrib.cosimulation.cosim_monitors.CosimMonitorFromCoupling(**kwargs)[source]

Bases: tvb.contrib.cosimulation.cosim_monitors.CosimMonitor

Abstract base class for a monitor that records the future coupling values.
coupling : tvb.contrib.cosimulation.cosim_monitors.CosimMonitorFromCoupling.coupling = Attr(field_type=<class ‘tvb.simulator.coupling.Coupling’>, default=<tvb.simulator.coupling.Linear object at 0x7f008529ed90>, required=True)
The coupling function is applied to the activity propagated between regions by the Long-range connectivity before it enters the local dynamic equations of the Model. Its primary purpose is to ‘rescale’ the incoming activity to a level appropriate to Model.

gid : tvb.basic.neotraits._core.HasTraits.gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=True)

coupling

An Attr declares the following about the attribute it describes: * the type * a default value shared by all instances * if the value might be missing * documentation It will resolve to attributes on the instance.

synchronization_n_step = None
class tvb.contrib.cosimulation.cosim_monitors.RawCosim(**kwargs)[source]

Bases: tvb.simulator.monitors.Raw, tvb.contrib.cosimulation.cosim_monitors.CosimMonitor

A monitor that records the output raw data from the partial (up to synchronization time) cosimulation history of TVB simulation. It collects:

  • all state variables and modes from class :Model:
  • all nodes of a region or surface based
  • all the integration time steps

period : tvb.simulator.monitors.Raw.period = Float(field_type=<class ‘float’>, default=0.0, required=True)

variables_of_interest : tvb.simulator.monitors.Raw.variables_of_interest = NArray(label=’Raw Monitor sees all!!! Resistance is futile...’, dtype=int64, default=None, dim_names=(), ndim=None, required=False)

gid : tvb.basic.neotraits._core.HasTraits.gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=True)

sample(current_step, start_step, n_steps, cosim_history, history)[source]

Return all the states of the partial (up to synchronization time) cosimulation history

class tvb.contrib.cosimulation.cosim_monitors.RawDelayed(**kwargs)[source]

Bases: tvb.simulator.monitors.Raw, tvb.contrib.cosimulation.cosim_monitors.CosimMonitor

A monitor that records the output raw data of all coupling variables from the full history of a TVB simulation. It collects:

  • all coupling state variables and modes from class :Model:
  • all nodes of a region or surface based
  • all the integration time steps

period : tvb.simulator.monitors.Raw.period = Float(field_type=<class ‘float’>, default=0.0, required=True)

variables_of_interest : tvb.simulator.monitors.Raw.variables_of_interest = NArray(label=’Raw Monitor sees all!!! Resistance is futile...’, dtype=int64, default=None, dim_names=(), ndim=None, required=False)

gid : tvb.basic.neotraits._core.HasTraits.gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=True)

sample(current_step, start_step, n_steps, cosim_history, history)[source]

Return all the states of the delayed (by synchronization time) TVB history

class tvb.contrib.cosimulation.cosim_monitors.RawVoiCosim(**kwargs)[source]

Bases: tvb.simulator.monitors.RawVoi, tvb.contrib.cosimulation.cosim_monitors.CosimMonitor

A monitor that records the output raw data of selected variables from the partial (up to synchronization time) history of TVB simulation. It collects:

  • voi state variables and all modes from class :Model:
  • all nodes of a region or surface based
  • all the integration time steps

period : tvb.simulator.monitors.Raw.period = Float(field_type=<class ‘float’>, default=0.0, required=True)

variables_of_interest : tvb.simulator.monitors.Raw.variables_of_interest = NArray(label=’Raw Monitor sees all!!! Resistance is futile...’, dtype=int64, default=None, dim_names=(), ndim=None, required=False)

gid : tvb.basic.neotraits._core.HasTraits.gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=True)

sample(current_step, start_step, n_steps, cosim_history, history)[source]

Return all the states of the partial (up to synchronization time) cosimulation history

class tvb.contrib.cosimulation.cosim_monitors.RawVoiDelayed(**kwargs)[source]

Bases: tvb.simulator.monitors.RawVoi, tvb.contrib.cosimulation.cosim_monitors.CosimMonitor

A monitor that records the output raw data of selected coupling variables from the full history of a TVB simulation. It collects:

  • selected coupling state variables and all modes from class :Model:
  • all nodes of a region or surface based
  • all the integration time steps

period : tvb.simulator.monitors.Raw.period = Float(field_type=<class ‘float’>, default=0.0, required=True)

variables_of_interest : tvb.simulator.monitors.Raw.variables_of_interest = NArray(label=’Raw Monitor sees all!!! Resistance is futile...’, dtype=int64, default=None, dim_names=(), ndim=None, required=False)

gid : tvb.basic.neotraits._core.HasTraits.gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=True)

sample(current_step, start_step, n_steps, cosim_history, history)[source]

Return selected states of the delayed (by synchronization time) TVB history

cosimulator

This is the module responsible for co-simulation of TVB with spiking simulators. It inherits the Simulator class. .. moduleauthor:: Lionel Kusch <lkusch@thevirtualbrain.org> .. moduleauthor:: Dionysios Perdikis <dionperd@gmail.com>

class tvb.contrib.cosimulation.cosimulator.CoSimulator(**kwargs)[source]

Bases: tvb.simulator.simulator.Simulator

exclusive : tvb.contrib.cosimulation.cosimulator.CoSimulator.exclusive = Attr(field_type=<class ‘bool’>, default=False, required=False)
1, when the proxy nodes substitute TVB nodes and their mutual connections should be removed.
voi : tvb.contrib.cosimulation.cosimulator.CoSimulator.voi = NArray(label=”Cosimulation model state variables’ indices”, dtype=int64, default=array([], dtype=int64), dim_names=(), ndim=None, required=True)
Indices of model’s variables of interest (VOI) thatshould be updated (i.e., overwriten) during cosimulation.

proxy_inds : tvb.contrib.cosimulation.cosimulator.CoSimulator.proxy_inds = NArray(label=’Indices of TVB proxy nodes’, dtype=int64, default=array([], dtype=int64), dim_names=(), ndim=None, required=True)

cosim_monitors : tvb.contrib.cosimulation.cosimulator.CoSimulator.cosim_monitors = List(of=<class ‘tvb.contrib.cosimulation.cosim_monitors.CosimMonitor’>, default=(), required=True)

synchronization_time : tvb.contrib.cosimulation.cosimulator.CoSimulator.synchronization_time = Float(field_type=<class ‘float’>, default=0.0, required=True)
Cosimulation synchronization time for exchanging data in milliseconds, must be an integral multiple of integration-step size. It defaults to simulator.integrator.dt
connectivity : tvb.simulator.simulator.Simulator.connectivity = Attr(field_type=<class ‘tvb.datatypes.connectivity.Connectivity’>, default=None, required=True)
A tvb.datatypes.Connectivity object which contains the structural long-range connectivity data (i.e., white-matter tracts). In combination with the Long-range coupling function it defines the inter-regional connections. These couplings undergo a time delay via signal propagation with a propagation speed of Conduction Speed
conduction_speed : tvb.simulator.simulator.Simulator.conduction_speed = Float(field_type=<class ‘float’>, default=3.0, required=False)
Conduction speed for Long-range connectivity (mm/ms)
coupling : tvb.simulator.simulator.Simulator.coupling = Attr(field_type=<class ‘tvb.simulator.coupling.Coupling’>, default=<tvb.simulator.coupling.Linear object at 0x7f008f3a54d0>, required=True)
The coupling function is applied to the activity propagated between regions by the Long-range connectivity before it enters the local dynamic equations of the Model. Its primary purpose is to ‘rescale’ the incoming activity to a level appropriate to Model.
surface : tvb.simulator.simulator.Simulator.surface = Attr(field_type=<class ‘tvb.datatypes.cortex.Cortex’>, default=None, required=False)
By default, a Cortex object which represents the cortical surface defined by points in the 3D physical space and their neighborhood relationship. In the current TVB version, when setting up a surface-based simulation, the option to configure the spatial spread of the Local Connectivity is available.
stimulus : tvb.simulator.simulator.Simulator.stimulus = Attr(field_type=<class ‘tvb.datatypes.patterns.SpatioTemporalPattern’>, default=None, required=False)
A Spatiotemporal stimulus can be defined at the region or surface level. It’s composed of spatial and temporal components. For region defined stimuli the spatial component is just the strength with which the temporal component is applied to each region. For surface defined stimuli, a (spatial) function, with finite-support, is used to define the strength of the stimuli on the surface centred around one or more focal points. In the current version of TVB, stimuli are applied to the first state variable of the Local dynamic model.
model : tvb.simulator.simulator.Simulator.model = Attr(field_type=<class ‘tvb.simulator.models.base.Model’>, default=<tvb.simulator.models.oscillator.Generic2dOscillator object at 0x7f008f3cb110>, required=True)
A tvb.simulator.Model object which describe the local dynamic equations, their parameters, and, to some extent, where connectivity (local and long-range) enters and which state-variables the Monitors monitor. By default the ‘Generic2dOscillator’ model is used. Read the Scientific documentation to learn more about this model.
integrator : tvb.simulator.simulator.Simulator.integrator = Attr(field_type=<class ‘tvb.simulator.integrators.Integrator’>, default=<tvb.simulator.integrators.HeunDeterministic object at 0x7f008f7a5c10>, required=True)
A tvb.simulator.Integrator object which is an integration scheme with supporting attributes such as integration step size and noise specification for stochastic methods. It is used to compute the time courses of the model state variables.
initial_conditions : tvb.simulator.simulator.Simulator.initial_conditions = NArray(label=’Initial Conditions’, dtype=float64, default=None, dim_names=(), ndim=None, required=False)
Initial conditions from which the simulation will begin. By default, random initial conditions are provided. Needs to be the same shape as simulator ‘history’, ie, initial history function which defines the minimal initial state of the network with time delays before time t=0. If the number of time points in the provided array is insufficient the array will be padded with random values based on the ‘state_variables_range’ attribute.
monitors : tvb.simulator.simulator.Simulator.monitors = List(of=<class ‘tvb.simulator.monitors.Monitor’>, default=(<tvb.simulator.monitors.TemporalAverage object at 0x7f008f8c1c90>,), required=True)
A tvb.simulator.Monitor or a list of tvb.simulator.Monitor objects that ‘know’ how to record relevant data from the simulation. Two main types exist: 1) simple, spatial and temporal, reductions (subsets or averages); 2) physiological measurements, such as EEG, MEG and fMRI. By default the Model’s specified variables_of_interest are returned, temporally downsampled from the raw integration rate to a sample rate of 1024Hz.
simulation_length : tvb.simulator.simulator.Simulator.simulation_length = Float(field_type=<class ‘float’>, default=1000.0, required=True)
The length of a simulation (default in milliseconds).

gid : tvb.basic.neotraits._core.HasTraits.gid = Attr(field_type=<class ‘uuid.UUID’>, default=None, required=True)

configure(full_configure=True)[source]

Configure simulator and its components.

The first step of configuration is to run the configure methods of all the Simulator’s components, ie its traited attributes.

Configuration of a Simulator primarily consists of calculating the attributes, etc, which depend on the combinations of the Simulator’s traited attributes (keyword args).

Converts delays from physical time units into integration steps and updates attributes that depend on combinations of the 6 inputs.

sim: Simulator
The configured Simulator instance.
cosim_history = None
cosim_monitors

The attribute is a list of values. Choices and type are reinterpreted as applying not to the list but to the elements of it

exclusive

An Attr declares the following about the attribute it describes: * the type * a default value shared by all instances * if the value might be missing * documentation It will resolve to attributes on the instance.

good_cosim_update_values_shape = (0, 0, 0, 0)
loop_cosim_monitor_output(n_steps=None, relative_start_step=0)[source]

return the value of the cosimulator monitors :param n_steps=None: the number of steps, it defaults to CoSimulator.synchronization_n_step :param relative_start_step=0: the first step of the values,

the default value 0 corresponds to start_step = CoSimulator.current_step - CoSimulator.synchronization_n_step + 1 for non-coupling CosimMonitor, and to start_step = CoSimulator.current_step + 1 for coupling CosimMonitor, instances
Returns:list of monitor outputs
number_of_cosim_monitors = 0
proxy_inds

Declares a numpy array. dtype enforces the dtype. The default dtype is float32. An optional symbolic shape can be given, as a tuple of Dim attributes from the owning class. The shape will be enforced, but no broadcasting will be done. domain declares what values are allowed in this array. It can be any object that can be checked for membership Defaults are checked if they are in the declared domain. For performance reasons this does not happen on every attribute set.

synchronization_n_step = 0
synchronization_time

Declares a float. This is different from Attr(field_type=float). The former enforces float subtypes. This allows any type that can be safely cast to the declared float type according to numpy rules.

Reading and writing this attribute is slower than a plain python attribute. In performance sensitive code you might want to use plain python attributes or even better local variables.

voi

Declares a numpy array. dtype enforces the dtype. The default dtype is float32. An optional symbolic shape can be given, as a tuple of Dim attributes from the owning class. The shape will be enforced, but no broadcasting will be done. domain declares what values are allowed in this array. It can be any object that can be checked for membership Defaults are checked if they are in the declared domain. For performance reasons this does not happen on every attribute set.

exception

This is special exception for the cosimulation .. moduleauthor:: Lionel Kusch <lkusch@thevirtualbrain.org> .. moduleauthor:: Dionysios Perdikis <dionperd@gmail.com>

exception tvb.contrib.cosimulation.exception.NumericalInstability[source]

Bases: builtins.ValueError

Exception to be thrown when there are problems during the update of the history with the cosimhistory