An error with running the "lfp" example on PyCharm

Description of problem

Hello!
I copied the code of the “lfp” example from Brian’s documentation, and it throws an error (the exact message below). I was surprised to see that the this example do work on the binder notebook on web, so I guess it’s might be related with my settings of the project (I use python version 3.9), but I can’t guess why.

Minimal code to reproduce problem

the code exists here: Example: lfp — Brian 2 2.4.2 documentation

What you have aready tried

Expected output (if relevant)

Actual output (if relevant)

Full traceback of error (if relevant)

WARNING The expression “1 / 20” divides two integer values. In previous versions of Brian, this would have used either an integer (“flooring”) or a floating point division, depending on the Python version and the code generation target. In the current version, it always uses a floating point division. Explicitly ask for an integer division ("//"), or turn one of the operands into a floating point value (e.g. replace “1/2” by “1.0/2”) to no longer receive this warning. [brian2.parsing.bast.floating_point_division]
WARNING The expression “5 / 2” divides two integer values. In previous versions of Brian, this would have used either an integer (“flooring”) or a floating point division, depending on the Python version and the code generation target. In the current version, it always uses a floating point division. Explicitly ask for an integer division ("//"), or turn one of the operands into a floating point value (e.g. replace “1/2” by “1.0/2”) to no longer receive this warning. [brian2.parsing.bast.floating_point_division]
WARNING The expression “1 / 18” divides two integer values. In previous versions of Brian, this would have used either an integer (“flooring”) or a floating point division, depending on the Python version and the code generation target. In the current version, it always uses a floating point division. Explicitly ask for an integer division ("//"), or turn one of the operands into a floating point value (e.g. replace “1/2” by “1.0/2”) to no longer receive this warning. [brian2.parsing.bast.floating_point_division]
WARNING The expression “1 / 80” divides two integer values. In previous versions of Brian, this would have used either an integer (“flooring”) or a floating point division, depending on the Python version and the code generation target. In the current version, it always uses a floating point division. Explicitly ask for an integer division ("//"), or turn one of the operands into a floating point value (e.g. replace “1/2” by “1.0/2”) to no longer receive this warning. [brian2.parsing.bast.floating_point_division]
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\owner\AppData\Local\Temp\brian_debug_ah0st350.log Additionally, you can also include a copy of the script that was run, available at: C:\Users\owner\AppData\Local\Temp\brian_script_xm7jx727.py You can also include a copy of the redirected std stream outputs, available at C:\Users\owner\AppData\Local\Temp\brian_stdout_ok5eo3nn.log and C:\Users\owner\AppData\Local\Temp\brian_stderr_1sgeqleo.log Thanks! [brian2]
Traceback (most recent call last):
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\core\network.py”, line 897, in before_run
obj.before_run(run_namespace)
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\groups\group.py”, line 1143, in before_run
self.create_code_objects(run_namespace)
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\groups\group.py”, line 1136, in create_code_objects
code_object = self.create_default_code_object(run_namespace)
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\groups\group.py”, line 1118, in create_default_code_object
self.codeobj = create_runner_codeobj(group=self.group,
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\codegen\codeobject.py”, line 441, in create_runner_codeobj
return device.code_object(owner=group,
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\devices\device.py”, line 297, in code_object
scalar_code, vector_code, kwds = generator.translate(abstract_code,
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\codegen\generators\base.py”, line 262, in translate
translated = self.translate_statement_sequence(scalar_statements,
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\codegen\generators\cython_generator.py”, line 208, in translate_statement_sequence
kwds = self.determine_keywords()
File “C:\Users\owner\PycharmProjects\spikeSorting\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 “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\codegen\generators\cython_generator.py”, line 220, in _add_user_function
func_code = impl.get_code(self.owner)
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\core\functions.py”, line 280, in get_code
self.availability_check()
File “C:\Users\owner\PycharmProjects\spikeSorting\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 “C:\Users\owner\PycharmProjects\spikeSorting\Simulator.py”, line 90, in
run(50*ms, report=‘text’)
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\units\fundamentalunits.py”, line 2434, in new_f
result = f(*args, **kwds)
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\core\magic.py”, line 373, in run
return magic_network.run(duration, report=report, report_period=report_period,
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\core\magic.py”, line 231, in run
Network.run(self, duration, report=report, report_period=report_period,
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\core\base.py”, line 278, in device_override_decorated_function
return func(*args, **kwds)
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\units\fundamentalunits.py”, line 2434, in new_f
result = f(*args, kwds)
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\core\network.py”, line 1008, in run
self.before_run(namespace)
File “C:\Users\owner\PycharmProjects\spikeSorting\venv\lib\site-packages\brian2\core\base.py”, line 278, in device_override_decorated_function
return func(args, **kwds)
File “C:\Users\owner\PycharmProjects\spikeSorting\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 “spatialneuron_stateupdater”.
Object was created here (most recent call only, full details in debug log):
File “C:\Users\owner\PycharmProjects\spikeSorting\Simulator.py”, line 65, in
neuron = SpatialNeuron(morphology=morpho, model=eqs, Cm=1
uF/cm
2,

Hi nettashaf,
looks like this was an issue that got solved in Brian version 2.2:

1.3.7 Brian 2.2
This releases fixes a number of important bugs and comes with a number of performance improvements. It also makes
sure that simulation no longer give platform-dependent results for certain corner cases that involve the division of
integers. These changes can break backwards-compatiblity in certain cases, see below. We recommend all users of Brian 2 to upgrade.

So the fix should be as simple as upgrading to the latest version of Brian (i think 2.4.2)

if you’re using conda

conda update brian2

might work, otherwise, try the install instructions here:
https://brian2.readthedocs.io/en/2.4.2/introduction/install.html#

Hi Adam, Thanks for the quick answer. Unfortunately I have the latest version of Brian, 2.4.2, and the code doesn’t run.
Is there a chance that you have another idea for why it doesn’t work for me?
Netta

Hi Netta,
Could you try conda list brian2 in the command line just to triple check the version of brian that’s being used in your virtual environment? In the meantime i’ll try running the script on my machine (python v3.8 and brian v2.3.0.2)

Okay, I was able to get it to run, but I got a lot of Cython-related errors:

20 errors generated.
WARNING    Cannot use Cython, a test compilation failed: command 'x86_64-apple-darwin13.4.0-clang' failed with exit status 1 (CompileError) [brian2.codegen.runtime.cython_rt.cython_rt.failed_compile_test]
INFO       Cannot use compiled code, falling back to the numpy code generation target. Note that this will likely be slower than using compiled code. Set the code generation to numpy manually to avoid this message:
prefs.codegen.target = "numpy" [brian2.devices.device.codegen_fallback]

I think this is a problem on my end with pointing brian to the right location for a C++ compiler that’s unrelated to the error messages you’re getting. In the end Brian used the numpy codegen target for me instead and successfully reproduced the figures.

As another note, I was mostly looking at the division warnings in your error message but the later errors

raise NotImplementedError('The “{}” function needs C99 compiler ’
NotImplementedError: The “exprel” function needs C99 compiler support

show up in this other brian forum post:
The “exprel” function needs C99 compiler support while running COBAHH example

and in a couple of discussions / pull requests on github:

gcc not working on Windows
Fix C99 Windows check
[MRG] Add support for new functions, and check C99 support

Those might be good places to look, and my impression is that this is something to do with Windows and C++ compilers

Hi @nettashaf, as @adam suggested, this is a bug in the compiler handling on Windows. We have fixed this issue already on github, but the version isn’t released yet. You can install it from GitHub or the PyPi test server via pip install --upgrade --pre -i https://test.pypi.org/simple/ brian2 – let us know if that works for you!

Best
Marcel