Skip to content

Python

Common Python problems

Mysterious failues with cython code (when using Brian2)

Sometimes Python code using brian2 runs fine on the desktop computer but will fail on one of our servers. Unfortunately, no error message is given to the user (there is however a ‘invalid opcode’ message in the admin log).

The reason behind this is that brian2 uses the same cache directory for all cython-compiled functions, which is inside your home folder. However, the servers may not use the same CPU instructions (opodes) and therefore, if such a cached function is being reused, the code is going to fail.

A solution could be to either clear out the ~/.cython folder regularly, or to create a file ~/.brian/user_preferences containing:

codegen.runtime.cython.cache_dir='/tmp/$USER/cython_cache'

Please replace $USER with your actual user name in order to avoid conflicts with other users.

This will then put the cython cache on the /tmp folder, which is local to each computer.