Brian Object Exception error

107 views
Skip to first unread message

Dominic Burrows

unread,
Sep 10, 2020, 11:15:37 AM9/10/20
to Brian
Hi there,

I keep on coming across the same error - weirdly I can run the below code for 2-3 times in my jupyter notebook without any error. And then the error appears. Also the specific object in my code that the error refers to seems to change arbitrarily when the code is identical - i.e. sometimes it is Poisson input, sometime state updater, sometime spike monitor.

My code (A and W refer to my own objects which I am using to generate network types):

N_extern=1000 #number of presynaptic excitatory poisson neurons - if None, computed as N_Excit*connection prob
w0= 0.1 * b2.mV #synaptic strength J
g= 4 #relative importance of inhibition
synaptic_delay= 1.5 * b2.ms #delay between presynaptic spike and postsynaptic increase
poisson_input_rate= 10. * b2.Hz #poisson rate of external population
w_external=0.1 * b2.mV #synaptic weight of excitatory external possion neurons onto all neurons - if None w_external set to w_0
v_rest=0. * b2.mV #Resting potential
v_reset= 10. * b2.mV #Reset potential
firing_threshold= +20. * b2.mV #Spike threshold
membrane_time_scale= 20. * b2.ms #tau
abs_refractory_period= 2.0 * b2.ms #absolute refractory period
monitored_subet_size=100 #n neurons for which a VOltageMonitor is recording Vm
random_vm_init=False #if true, membrane voltage of each neuron is random at start (uniform)
sim_time=100 #simulation time

s = 1
k = 5
A = netfn.ba_netsim(dist).adjmat_generate(s, k, divisor, soften).A
W = adjmat_generate(A, s, k, divisor, soften)


# record 
b2.start_scope()

J_excit = w0

# define dynamics for each cell
lif_dynamics = """
dv/dt = -(v-v_rest) / membrane_time_scale : volt (unless refractory)"""


#Build neuron group
N = nodes.shape[0]

network = b2.NeuronGroup(
    N, model=lif_dynamics,
    threshold="v>firing_threshold", reset="v=v_reset", refractory=abs_refractory_period,
    method="linear")

network.v = v_rest

#Build synapses
S = b2.Synapses(network, network, 'w:1', on_pre="v += J_excit", delay=synaptic_delay)
rows, cols = np.nonzero(A)
S.connect(i = rows, j = cols)

#Add weights
S.w = W[rows, cols]
external_poisson_input = b2.PoissonInput(target=network, target_var="v", N=N_extern,
                                          rate=poisson_input_rate, weight=w_external)

spike_monitor = b2.SpikeMonitor(network)
b2.run(sim_time*b2.ms)

Dominic Burrows

unread,
Sep 10, 2020, 11:16:32 AM9/10/20
to Brian
Error message:

libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: Couldn't close file
---------------------------------------------------------------------------
DistutilsExecError                        Traceback (most recent call last)
~/Applications/anaconda3/lib/python3.7/distutils/unixccompiler.py in link(self, target_desc, objects, output_filename, output_dir, libraries, library_dirs, runtime_library_dirs, export_symbols, debug, extra_preargs, extra_postargs, build_temp, target_lang)
    204 
--> 205                 self.spawn(linker + ld_args)
    206             except DistutilsExecError as msg:

~/Applications/anaconda3/lib/python3.7/distutils/ccompiler.py in spawn(self, cmd)
    908     def spawn(self, cmd):
--> 909         spawn(cmd, dry_run=self.dry_run)
    910 

~/Applications/anaconda3/lib/python3.7/distutils/spawn.py in spawn(cmd, search_path, verbose, dry_run)
     35     if os.name == 'posix':
---> 36         _spawn_posix(cmd, search_path, dry_run=dry_run)
     37     elif os.name == 'nt':

~/Applications/anaconda3/lib/python3.7/distutils/spawn.py in _spawn_posix(cmd, search_path, verbose, dry_run)
    148                       "command %r terminated by signal %d"
--> 149                       % (cmd, os.WTERMSIG(status)))
    150             elif os.WIFEXITED(status):

DistutilsExecError: command 'g++' terminated by signal 6

During handling of the above exception, another exception occurred:

LinkError                                 Traceback (most recent call last)
~/Applications/anaconda3/lib/python3.7/site-packages/brian2/core/network.py in before_run(self, run_namespace)
    896                 try:
--> 897                     obj.before_run(run_namespace)
    898                 except Exception as ex:

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/input/poissoninput.py in before_run(self, run_namespace)
    114                                       'created.' % self.group.name)
--> 115         CodeRunner.before_run(self, run_namespace=run_namespace)

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/groups/group.py in before_run(self, run_namespace)
   1141     def before_run(self, run_namespace):
-> 1142         self.create_code_objects(run_namespace)
   1143         super(CodeRunner, self).before_run(run_namespace)

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/groups/group.py in create_code_objects(self, run_namespace)
   1134         # Overwrite this function to use more than one.
-> 1135         code_object = self.create_default_code_object(run_namespace)
   1136         if code_object:

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/groups/group.py in create_default_code_object(self, run_namespace)
   1127                                                  override_conditional_write=self.override_conditional_write,
-> 1128                                                  codeobj_class=self.codeobj_class
   1129                                                  )

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/codegen/codeobject.py in create_runner_codeobj(group, code, template_name, run_namespace, user_code, variable_indices, name, check_units, needed_variables, additional_variables, template_kwds, override_conditional_write, codeobj_class)
    449                               override_conditional_write=override_conditional_write,
--> 450                               compiler_kwds=compiler_kwds
    451                               )

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/devices/device.py in code_object(self, owner, name, abstract_code, variables, template_name, variable_indices, codeobj_class, template_kwds, override_conditional_write, compiler_kwds)
    326                                 name=name, compiler_kwds=compiler_kwds)
--> 327         codeobj.compile()
    328         return codeobj

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/codegen/codeobject.py in compile(self)
    100         for block in ['before_run', 'run', 'after_run']:
--> 101             self.compiled_code[block] = self.compile_block(block)
    102 

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/codegen/runtime/cython_rt/cython_rt.py in compile_block(self, block)
    152             owner_name=self.owner.name+'_'+self.template_name,
--> 153             sources=self.sources
    154             )

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/codegen/runtime/cython_rt/extension_manager.py in create_extension(self, code, force, name, define_macros, include_dirs, library_dirs, runtime_library_dirs, extra_compile_args, extra_link_args, libraries, compiler, sources, owner_name)
    125                                            key=key,
--> 126                                            sources=sources)
    127             return module

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/codegen/runtime/cython_rt/extension_manager.py in _load_module(self, module_path, define_macros, include_dirs, library_dirs, extra_compile_args, extra_link_args, libraries, code, lib_dir, module_name, runtime_library_dirs, compiler, key, sources)
    261                     build_extension.build_lib = lib_dir
--> 262                     build_extension.run()
    263                     if prefs['codegen.runtime.cython.delete_source_files']:

~/Applications/anaconda3/lib/python3.7/distutils/command/build_ext.py in run(self)
    339         # Now actually compile and link everything.
--> 340         self.build_extensions()
    341 

~/Applications/anaconda3/lib/python3.7/distutils/command/build_ext.py in build_extensions(self)
    448         else:
--> 449             self._build_extensions_serial()
    450 

~/Applications/anaconda3/lib/python3.7/distutils/command/build_ext.py in _build_extensions_serial(self)
    473             with self._filter_build_errors(ext):
--> 474                 self.build_extension(ext)
    475 

~/Applications/anaconda3/lib/python3.7/distutils/command/build_ext.py in build_extension(self, ext)
    558             build_temp=self.build_temp,
--> 559             target_lang=language)
    560 

~/Applications/anaconda3/lib/python3.7/distutils/ccompiler.py in link_shared_object(self, objects, output_filename, output_dir, libraries, library_dirs, runtime_library_dirs, export_symbols, debug, extra_preargs, extra_postargs, build_temp, target_lang)
    716                   export_symbols, debug,
--> 717                   extra_preargs, extra_postargs, build_temp, target_lang)
    718 

~/Applications/anaconda3/lib/python3.7/distutils/unixccompiler.py in link(self, target_desc, objects, output_filename, output_dir, libraries, library_dirs, runtime_library_dirs, export_symbols, debug, extra_preargs, extra_postargs, build_temp, target_lang)
    206             except DistutilsExecError as msg:
--> 207                 raise LinkError(msg)
    208         else:

LinkError: command 'g++' terminated by signal 6

The above exception was the direct cause of the following exception:

BrianObjectException                      Traceback (most recent call last)
<ipython-input-10-d4bffc186c09> in <module>
     36 
     37 spike_monitor = b2.SpikeMonitor(network)
---> 38 b2.run(sim_time*b2.ms)
     39 
     40 

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/units/fundamentalunits.py in new_f(*args, **kwds)
   2383                                                      get_dimensions(newkeyset[k]))
   2384 
-> 2385             result = f(*args, **kwds)
   2386             if 'result' in au:
   2387                 if au['result'] == bool:

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/core/magic.py in run(duration, report, report_period, namespace, profile, level)
    372     '''
    373     return magic_network.run(duration, report=report, report_period=report_period,
--> 374                              namespace=namespace, profile=profile, level=2+level)
    375 run.__module__ = __name__
    376 

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/core/magic.py in run(self, duration, report, report_period, namespace, profile, level)
    230         self._update_magic_objects(level=level+1)
    231         Network.run(self, duration, report=report, report_period=report_period,
--> 232                     namespace=namespace, profile=profile, level=level+1)
    233 
    234     def store(self, name='default', filename=None, level=0):

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/core/base.py in device_override_decorated_function(*args, **kwds)
    276                 return getattr(curdev, name)(*args, **kwds)
    277             else:
--> 278                 return func(*args, **kwds)
    279 
    280         device_override_decorated_function.__doc__ = func.__doc__

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/units/fundamentalunits.py in new_f(*args, **kwds)
   2383                                                      get_dimensions(newkeyset[k]))
   2384 
-> 2385             result = f(*args, **kwds)
   2386             if 'result' in au:
   2387                 if au['result'] == bool:

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/core/network.py in run(self, duration, report, report_period, namespace, profile, level)
   1006             namespace = get_local_namespace(level=level+3)
   1007 
-> 1008         self.before_run(namespace)
   1009 
   1010         if len(all_objects) == 0:

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/core/base.py in device_override_decorated_function(*args, **kwds)
    276                 return getattr(curdev, name)(*args, **kwds)
    277             else:
--> 278                 return func(*args, **kwds)
    279 
    280         device_override_decorated_function.__doc__ = func.__doc__

~/Applications/anaconda3/lib/python3.7/site-packages/brian2/core/network.py in before_run(self, run_namespace)
    897                     obj.before_run(run_namespace)
    898                 except Exception as ex:
--> 899                     raise BrianObjectException("An error occurred when preparing an object.", obj) from ex
    900 
    901         # Check that no object has been run as part of another network before

BrianObjectException: Error encountered with object named "poissoninput".
Object was created here (most recent call only, full details in debug log):
  File "<ipython-input-10-d4bffc186c09>", line 35, in <module>
    rate=poisson_input_rate, weight=w_external)

An error occurred when preparing an object. (See above for original error message and traceback.)
Reply all
Reply to author
Forward
0 new messages