# Device class

(Shortest import: `from brian2.devices import Device)`

class brian2.devices.device.Device

  Bases: `object`

  Base Device object.

  Attributes

  `network_schedule` | The 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 `CodeObject` class according to input/default settings
  `delete`([data, code, directory, force]) | Delete code and/or data generated/stored by the device.
  `fill_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.
  `get_random_state`() | Return a (pickable) representation of the current random number generator state.
  `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.
  `set_random_state`(state) | Reset the random number generator state to a previously stored state (see `Device.get_random_state`).
  `spike_queue`(source_start, source_end) | Create and return a new `SpikeQueue` for this `Device`.

  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.schedule` for details). If it supports arbitrary schedules, it should be set to `None` (the default).

  activate(build_on_run=True, **kwargs)

    Called when this device is set as the current device.

  add_array(var)

    Add an array to this device.

    Parameters:

      var : `ArrayVariable`

      > The array to add.

  build(**kwds)

    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)
  code_object_class(codeobj_class=None, fallback_pref='codegen.target')

    Return `CodeObject` class according to input/default settings

    Parameters:

      codeobj_class : a `CodeObject` class, optional

      > If 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 `CodeObject` class that should be used

  delete(data=True, code=True, directory=True, force=False)

    Delete code and/or data generated/stored by the device.

    Parameters:

      data : bool, optional

      > Whether to delete the data generated by the simulation (final values of state variables, data stored in monitors, etc.). Defaults to `True`.

      code : bool, optional

      > Whether to delete the code generated by the simulation. Includes the numerical values used for initialization of state variables in assignments not using strings. Defaults to `True`.

      directory : bool, optional

      > Whether to delete the project directory generated by the simulation. Will not delete directories that contain files not created by Brian unless the `force` option is specfied. Defaults to `True`.

      force : bool, optional

      > Whether to delete the project directory with all its content, even if it contains files that were not created by Brian. Useful only when the `directory` option is set to `True` as well. Defaults to `False`.

  fill_with_array(var, arr)

    Fill an array with the values given in another array.

    Parameters:

      var : `ArrayVariable`

      > The array to fill.

      arr : `ndarray`

      > The array values that should be copied to `var`.

  get_array_name(var, access_data=True)

    Return a globally unique name for `var`.

    Parameters:

      access_data : bool, optional

      > For `DynamicArrayVariable` objects, specifying `True` here means the name for the underlying data is returned. If specifying `False`, the name of object itself is returned (e.g. to allow resizing).

    Returns:

      name : str

      > The name for `var`.

  get_len(array)

    Return the length of the array.

    Parameters:

      array : `ArrayVariable`

      > The array for which the length is requested.

    Returns:

      l : int

      > The length of the array.

  get_random_state()

    Return a (pickable) representation of the current random number generator state. Providing the returned object (e.g. a dict) to `Device.set_random_state` should restore the random number generator state.

    Returns:

      state :

      > The state of the random number generator in a representation that can be passed as an argument to `Device.set_random_state`.

  init_with_arange(var, start, dtype)

    Initialize an array with an integer range.

    Parameters:

      var : `ArrayVariable`

      > The array to fill with the integer range.

      start : int

      > The start value for the integer range

      dtype : `dtype`

      > The data type to use for the array.

  init_with_zeros(var, dtype)

    Initialize an array with zeros.

    Parameters:

      var : `ArrayVariable`

      > The array to initialize with zeros.

      dtype : `dtype`

      > The data type to use for the array.

  insert_code(slot, code)

    Insert code directly into a given slot in the device. By default does nothing.

  insert_device_code(slot, code)
  reinit()

    Reinitialize the device. For standalone devices, clears all the internal state of the device.

  resize(var, new_size)

    Resize a `DynamicArrayVariable`.

    Parameters:

      var : `DynamicArrayVariable`

      > The variable that should be resized.

      new_size : int

      > The new size of the variable

  resize_along_first(var, new_size)
  seed(seed=None)

    Set the seed for the random number generator.

    Parameters:

      seed : int, optional

      > The seed value for the random number generator, or `None` (the default) to set a random seed.

  set_random_state(state)

    Reset the random number generator state to a previously stored state (see `Device.get_random_state`).

    Parameters:

      state :

      > A random number generator state as provided by `Device.get_random_state`.

  spike_queue(source_start, source_end)

    Create and return a new `SpikeQueue` for this `Device`.

    Parameters:

      source_start : int

      > The start index of the source group (necessary for subgroups)

      source_end : int

      > The end index of the source group (necessary for subgroups)