Device class¶
(Shortest import: from brian2.devices import Device)
-
class
brian2.devices.device.Device[source]¶ Bases:
objectBase Device object.
Attributes
network_scheduleThe network schedule that this device supports. Methods
activate([build_on_run])Called when this device is set as the current device. add_array(var)Add an array to this device. build(**kwds)For standalone projects, called when the project is ready to be built. code_object(owner, name, abstract_code, …)code_object_class([codeobj_class, fallback_pref])Return CodeObjectclass according to input/default settingsfill_with_array(var, arr)Fill an array with the values given in another array. get_array_name(var[, access_data])Return a globally unique name for var().get_len(array)Return the length of the array. init_with_arange(var, start, dtype)Initialize an array with an integer range. init_with_zeros(var, dtype)Initialize an array with zeros. insert_code(slot, code)Insert code directly into a given slot in the device. insert_device_code(slot, code)reinit()Reinitialize the device. resize(var, new_size)Resize a DynamicArrayVariable.resize_along_first(var, new_size)seed([seed])Set the seed for the random number generator. spike_queue(source_start, source_end)Create and return a new SpikeQueuefor thisDevice.Details
-
network_schedule¶ The network schedule that this device supports. If the device only supports a specific, fixed schedule, it has to set this attribute to the respective schedule (see
Network.schedulefor details). If it supports arbitrary schedules, it should be set toNone(the default).
-
activate(build_on_run=True, **kwargs)[source]¶ Called when this device is set as the current device.
-
add_array(var)[source]¶ Add an array to this device.
Parameters: var :
ArrayVariableThe array to add.
-
build(**kwds)[source]¶ For standalone projects, called when the project is ready to be built. Does nothing for runtime mode.
-
code_object(owner, name, abstract_code, variables, template_name, variable_indices, codeobj_class=None, template_kwds=None, override_conditional_write=None, compiler_kwds=None)[source]¶
-
code_object_class(codeobj_class=None, fallback_pref='codegen.target')[source]¶ Return
CodeObjectclass according to input/default settingsParameters: codeobj_class : a
CodeObjectclass, optionalIf this is keyword is set to None or no arguments are given, this method will return the default.
fallback_pref : str, optional
String describing which attribute of prefs to access to retrieve the ‘default’ target. Usually this is codegen.target, but in some cases we want to use object-specific targets such as codegen.string_expression_target.
Returns: codeobj_class : class
The
CodeObjectclass that should be used
-
fill_with_array(var, arr)[source]¶ Fill an array with the values given in another array.
Parameters: var :
ArrayVariableThe array to fill.
arr :
ndarrayThe array values that should be copied to
var().
-
get_array_name(var, access_data=True)[source]¶ Return a globally unique name for
var().Parameters: access_data : bool, optional
For
DynamicArrayVariableobjects, specifyingTruehere means the name for the underlying data is returned. If specifyingFalse, the name of object itself is returned (e.g. to allow resizing).Returns: name : str
The name for
var().
-
get_len(array)[source]¶ Return the length of the array.
Parameters: array :
ArrayVariableThe array for which the length is requested.
Returns: l : int
The length of the array.
-
init_with_arange(var, start, dtype)[source]¶ Initialize an array with an integer range.
Parameters: var :
ArrayVariableThe array to fill with the integer range.
start : int
The start value for the integer range
dtype :
dtypeThe data type to use for the array.
-
init_with_zeros(var, dtype)[source]¶ Initialize an array with zeros.
Parameters: var :
ArrayVariableThe array to initialize with zeros.
dtype :
dtypeThe data type to use for the array.
-
insert_code(slot, code)[source]¶ Insert code directly into a given slot in the device. By default does nothing.
-
reinit()[source]¶ Reinitialize the device. For standalone devices, clears all the internal state of the device.
-
resize(var, new_size)[source]¶ Resize a
DynamicArrayVariable.Parameters: var :
DynamicArrayVariableThe variable that should be resized.
new_size : int
The new size of the variable
-