The "exprel" function needs C99 compiler support while running COBAHH example

Description of problem

While trying to run the COBAHH example getting the above stated error.

Minimal code to reproduce problem

https://brian2.readthedocs.io/en/stable/examples/COBAHH.html

What you have already tried

Tried this solution : ZeroDivisionError when changing synaptic weights of large network with HH neurons

My OS: Windows
**Brian2 version: ** brian2 2.4.2 py39h2e07f2f_1
**gcc version: ** gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

Actual output (if relevant)

If adding :-

import brian2.codegen.cpp_prefs
brian2.codegen.cpp_prefs._compiler_supports_c99 = True

Getting the output.

Full traceback of error (if relevant)

ERROR Brian 2 encountered an unexpected error. If you think this is a bug in Brian 2, please report this issue either to the discourse forum at , or to the issue tracker at . Please include this file with debug information in your report: C:\Users\sudes\AppData\Local\Temp\brian_debug_cno58ko1.log Additionally, you can also include a copy of the script that was run, available at: C:\Users\sudes\AppData\Local\Temp\brian_script_gooe7wzq.py Thanks! [brian2]
Traceback (most recent call last):
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\core\network.py”, line 897, in before_run
obj.before_run(run_namespace)
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\groups\group.py”, line 1143, in before_run
self.create_code_objects(run_namespace)
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\groups\group.py”, line 1136, in create_code_objects
code_object = self.create_default_code_object(run_namespace)
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\groups\group.py”, line 1118, in create_default_code_object
self.codeobj = create_runner_codeobj(group=self.group,
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\codegen\codeobject.py”, line 441, in create_runner_codeobj
return device.code_object(owner=group,
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\devices\device.py”, line 297, in code_object
scalar_code, vector_code, kwds = generator.translate(abstract_code,
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\codegen\generators\base.py”, line 262, in translate
translated = self.translate_statement_sequence(scalar_statements,
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\codegen\generators\cython_generator.py”, line 208, in translate_statement_sequence
kwds = self.determine_keywords()
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\codegen\generators\cython_generator.py”, line 364, in determine_keywords
user_func = self._add_user_function(varname, var, added)
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\codegen\generators\cython_generator.py”, line 220, in _add_user_function
func_code = impl.get_code(self.owner)
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\core\functions.py”, line 280, in get_code
self.availability_check()
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\codegen\cpp_prefs.py”, line 278, in call
raise NotImplementedError('The “{}” function needs C99 compiler ’
NotImplementedError: The “exprel” function needs C99 compiler support

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

Traceback (most recent call last):
File “E:\Documents\Sprekeler\cobahh.py”, line 57, in
run(1 * second, report=‘text’)
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\units\fundamentalunits.py”, line 2434, in new_f
result = f(*args, **kwds)
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\core\magic.py”, line 373, in run
return magic_network.run(duration, report=report, report_period=report_period,
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\core\magic.py”, line 231, in run
Network.run(self, duration, report=report, report_period=report_period,
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\core\base.py”, line 278, in device_override_decorated_function
return func(*args, **kwds)
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\units\fundamentalunits.py”, line 2434, in new_f
result = f(args, **kwds)
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\core\network.py”, line 1008, in run
self.before_run(namespace)
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\core\base.py”, line 278, in device_override_decorated_function
return func(args, **kwds)
File “E:\Programs\Anaconda\envs\venv\lib\site-packages\brian2\core\network.py”, line 899, in before_run
raise BrianObjectException(“An error occurred when preparing an object.”, obj) from ex
brian2.core.base.BrianObjectException: Error encountered with object named “neurongroup_stateupdater”.
Object was created here (most recent call only, full details in debug log):
File “E:\Documents\Sprekeler\cobahh.py”, line 41, in
P = NeuronGroup(4000, model=eqs, threshold='v>-20
mV’, refractory=3
ms,

An error occurred when preparing an object. (See above for original error message and traceback.)

Doubt (if relevant)

I am not sure if my anaconda is linking to my gcc compiler path.

Hi Sudeshna. Just to be clear I understand correctly: if you apply the workaround where you set _compilter_supports_c99 = True, it works correctly?

Under Windows, we do not directly support gcc, because our code is generated as a C extension for Python, and these have to use the same compiler as the one that was used for building Python itself, which is Microsoft Visual Studio. So the compilation and the C99 check will try to find out which MSVC you have installed and use that. Could you add

print(brian2.codegen.cpp_prefs.get_msvc_env())

to figure out what that does for you?

But the C99 check should then only fail for very old MSVC versions (< 2013).

Oh, wait, I completely forgot that there was actually a bug in the C99 detection on Windows :man_facepalming:

See Fix C99 Windows check by kjohnsen · Pull Request #1257 · brian-team/brian2 · GitHub

For now the workaround setting _compiler_supports_c99 manually should work, but you could also try using the latest Brian 2 version from git (we did not make a new release yet), e.g. with:

pip install git+https://github.com/brian-team/brian.git