About the problems of brian2.test in the test process (FAILURES: test_spatialneuron_timearray)

Description of problem

FAILURES: test_spatialneuron_timearray
short test summary info:
FAILED ../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/tests/test_spatialneuron.py::test_spatialneuron_timedarray
1 failed, 271 passed, 7 skipped, 429 deselected in 244.24s (0:04:04)
ERROR: 1/3 test suite(s) did not complete successfully (see above).

Please help me find out where the problem is. I’m not sure where to solve it.

Minimal code to reproduce problem

/home/lzr/anaconda3/envs/brian2/bin/python /home/lzr/PycharmProjects/brian2-test/main.py 
Running tests in /home/lzr/anaconda3/envs/brian2/lib/python3.8/site-packages/brian2 for targets numpy (excluding long tests)
Running Brian version 2.5.1.post0.dev93 from '/home/lzr/anaconda3/envs/brian2/lib/python3.8/site-packages/brian2'
Testing codegen-independent code
Resetting to default preferences

Running doctests
..........................................                               [100%]
42 passed, 3 skipped in 5.06s
Running tests that do not use code generation
........................................................................ [ 19%]
........................................................................ [ 38%]
......................................................ss................ [ 57%]
........................................................................ [ 76%]
........................................................................ [ 95%]
................                                                         [100%]
374 passed, 2 skipped, 332 deselected in 74.66s (0:01:14)
Running tests for target numpy:
.....s...............................ssssss............................. [ 25%]
........................................................................ [ 51%]
.......F................................................................ [ 77%]
...............................................................          [100%]
=================================== FAILURES ===================================
________________________ test_spatialneuron_timedarray _________________________

self = <brian2.codegen.runtime.numpy_rt.numpy_rt.NumpyCodeObject object at 0x7fc3eeb45a30>
block = 'run'

    def run_block(self, block):
        compiled_code = self.compiled_code[block]
        if not compiled_code:
            return
        try:
>           exec(compiled_code, self.namespace)

../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/codegen/runtime/numpy_rt/numpy_rt.py:279: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   IndexError: index 1 is out of bounds for axis 0 with size 1

(string):35: IndexError

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

    @pytest.mark.standalone_compatible
    def test_spatialneuron_timedarray():
        # See GitHub issue 1427
        ta = TimedArray([0, 1] * nA, dt=1 * ms)
        morpho = Soma(diameter=10 * um)
        neuron = SpatialNeuron(morpho, "Im = ta(t)/area : amp/meter**2", method="euler")
        mon = StateMonitor(neuron, "v", record=0, when="after_groups")
>       run(2 * ms)

../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/tests/test_spatialneuron.py:943: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/units/fundamentalunits.py:2776: in new_f
    result = f(*args, **kwds)
../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/core/magic.py:407: in run
    return magic_network.run(
../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/core/magic.py:248: in run
    Network.run(
../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/core/base.py:335: in device_override_decorated_function
    return func(*args, **kwds)
../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/units/fundamentalunits.py:2776: in new_f
    result = f(*args, **kwds)
../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/core/network.py:1207: in run
    obj.run()
../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/core/base.py:225: in run
    codeobj()
../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/codegen/codeobject.py:118: in __call__
    return self.run()
../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/codegen/codeobject.py:146: in run
    return self.run_block("run")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <brian2.codegen.runtime.numpy_rt.numpy_rt.NumpyCodeObject object at 0x7fc3eeb45a30>
block = 'run'

    def run_block(self, block):
        compiled_code = self.compiled_code[block]
        if not compiled_code:
            return
        try:
            exec(compiled_code, self.namespace)
        except Exception as exc:
            code = getattr(self.code, block)
            message = (
                "An exception occured during the execution of the "
                f"'{block}' block of code object {self.name}.\n"
            )
            lines = code.split("\n")
            message += "The error was raised in the following line:\n"
            _, _, tb = sys.exc_info()
            tb = tb.tb_next  # Line in the code object's code
            message += f"{lines[tb.tb_lineno - 1]}\n"
>           raise BrianObjectException(message, self.owner) from exc
E           brian2.core.base.BrianObjectException: Error encountered with object named 'spatialneuron'.
E           Object was created here (most recent call only, full details in debug log):
E             File '/home/lzr/anaconda3/envs/brian2/lib/python3.8/site-packages/_pytest/python.py', line 195, in pytest_pyfunc_call
E               result = testfunction(**testargs)
E           
E           An exception occured during the execution of the 'run' block of code object spatialneuron_spatialstateupdater_codeobject.
E           The error was raised in the following line:
E           _array_spatialneuron__c[0] = _array_spatialneuron__ab_star0[1] / _bi[0]
E            (See above for original error message and traceback.)

../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/codegen/runtime/numpy_rt/numpy_rt.py:291: BrianObjectException
=========================== short test summary info ============================
FAILED ../../anaconda3/envs/brian2/lib/python3.8/site-packages/brian2/tests/test_spatialneuron.py::test_spatialneuron_timedarray
1 failed, 271 passed, 7 skipped, 429 deselected in 244.24s (0:04:04)
ERROR: 1/3 test suite(s) did not complete successfully (see above).

Hi @LeoZRain, thanks for the report. The code that raises the error is only used in very specific instances (cython compilation not available and no scipy package installed), which explains why the automatic test suite did not catch this. I will look into it, but for now the easiest fix should be to install scipy into your conda environment. Let us know whether this fixes it for you.

1 Like

Thank you very much for your answer ! By your suggestion I have solved the problem after installing scipy package

1 Like