CPPStandaloneDevice class

(Shortest import: from brian2.devices.cpp_standalone.device import CPPStandaloneDevice)

class brian2.devices.cpp_standalone.device.CPPStandaloneDevice[source]

Bases: brian2.devices.device.Device

The Device used for C++ standalone simulations.

Attributes

arange_arrays Dictionary of all arrays to be filled with numbers (mapping
arrays Dictionary mapping ArrayVariable objects to their globally
dynamic_arrays List of all dynamic arrays
dynamic_arrays_2d Dictionary mapping DynamicArrayVariable objects with 2 dimensions
has_been_run Whether the simulation has been run
static_arrays Dict of all static saved arrays
zero_arrays List of all arrays to be filled with zeros

Methods

add_array(var)
build([directory, compile, run, debug, ...]) Build the project
check_openmp_compatible(nb_threads)
code_object(owner, name, abstract_code, ...)
code_object_class([codeobj_class])
compile_source(directory, compiler, debug, ...)
copy_source_files(writer, directory)
fill_with_array(var, arr)
find_synapses()
generate_codeobj_source(writer)
generate_main_source(writer)
generate_makefile(writer, compiler, native, ...)
generate_network_source(writer, compiler)
generate_objects_source(writer, ...)
generate_run_source(writer)
generate_synapses_classes_source(writer)
get_array_filename(var[, basedir]) Return a file name for a variable.
get_array_name(var[, access_data]) Return a globally unique name for var().
get_value(var[, access_data])
init_with_arange(var, start)
init_with_array(var, arr)
init_with_zeros(var)
insert_code(slot, code) Insert code directly into main.cpp
network_get_profiling_info(net)
network_restore(net[, name])
network_run(net, duration[, report, ...])
network_store(net[, name])
reinit()
resize(var, new_size)
run(directory, with_output, run_args)
run_function(name[, include_in_parent]) Context manager to divert code into a function
static_array(name, arr)
variableview_get_subexpression_with_index_array(...)
variableview_get_with_expression(...[, ...])
variableview_set_with_index_array(...)
write_static_arrays(directory)

Details

arange_arrays

Dictionary of all arrays to be filled with numbers (mapping ArrayVariable objects to start value)

arrays

Dictionary mapping ArrayVariable objects to their globally unique name

dynamic_arrays

List of all dynamic arrays Dictionary mapping DynamicArrayVariable objects with 1 dimension to their globally unique name

dynamic_arrays_2d

Dictionary mapping DynamicArrayVariable objects with 2 dimensions to their globally unique name

has_been_run

Whether the simulation has been run

static_arrays

Dict of all static saved arrays

zero_arrays

List of all arrays to be filled with zeros

add_array(var)[source]
build(directory='output', compile=True, run=True, debug=False, clean=True, with_output=True, native=True, additional_source_files=None, run_args=None, **kwds)[source]

Build the project

TODO: more details

Parameters:

directory : str

The output directory to write the project to, any existing files will be overwritten.

compile : bool

Whether or not to attempt to compile the project

run : bool

Whether or not to attempt to run the built project if it successfully builds.

debug : bool

Whether to compile in debug mode.

with_output : bool

Whether or not to show the stdout of the built program when run.

native : bool

Whether or not to compile for the current machine’s architecture (best for speed, but not portable)

clean : bool

Whether or not to clean the project before building

additional_source_files : list of str

A list of additional .cpp files to include in the build.

check_openmp_compatible(nb_threads)[source]
code_object(owner, name, abstract_code, variables, template_name, variable_indices, codeobj_class=None, template_kwds=None, override_conditional_write=None)[source]
code_object_class(codeobj_class=None)[source]
compile_source(directory, compiler, debug, clean, native)[source]
copy_source_files(writer, directory)[source]
fill_with_array(var, arr)[source]
find_synapses()[source]
generate_codeobj_source(writer)[source]
generate_main_source(writer)[source]
generate_makefile(writer, compiler, native, compiler_flags, linker_flags, nb_threads)[source]
generate_network_source(writer, compiler)[source]
generate_objects_source(writer, arange_arrays, synapses, static_array_specs, networks)[source]
generate_run_source(writer)[source]
generate_synapses_classes_source(writer)[source]
get_array_filename(var, basedir='results')[source]

Return a file name for a variable.

Parameters:

var : ArrayVariable

The variable to get a filename for.

basedir : str

The base directory for the filename, defaults to 'results'.

Returns :

——- :

filename : str

A filename of the form 'results/'+varname+'_'+str(hash(varname)), where varname is the name returned by get_array_name.

Notes

The reason that the filename is not simply 'results/' + varname is that this could lead to file names that are not unique in file systems that are not case sensitive (e.g. on Windows).

get_array_name(var, access_data=True)[source]

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).

get_value(var, access_data=True)[source]
init_with_arange(var, start)[source]
init_with_array(var, arr)[source]
init_with_zeros(var)[source]
insert_code(slot, code)[source]

Insert code directly into main.cpp

network_get_profiling_info(net)[source]
network_restore(net, name='default')[source]
network_run(net, duration, report=None, report_period=10. * second, namespace=None, profile=True, level=0, **kwds)[source]
network_store(net, name='default')[source]
reinit()[source]
resize(var, new_size)[source]
run(directory, with_output, run_args)[source]
run_function(name, include_in_parent=True)[source]

Context manager to divert code into a function

Code that happens within the scope of this context manager will go into the named function.

Parameters:

name : str

The name of the function to divert code into.

include_in_parent : bool

Whether or not to include a call to the newly defined function in the parent context.

static_array(name, arr)[source]
variableview_get_subexpression_with_index_array(variableview, item, level=0, run_namespace=None)[source]
variableview_get_with_expression(variableview, code, level=0, run_namespace=None)[source]
variableview_set_with_index_array(variableview, item, value, check_units)[source]
write_static_arrays(directory)[source]