brian2 icon indicating copy to clipboard operation
brian2 copied to clipboard

Brian2 and Pycharm Debugger don't come along well

Open SvennoNito opened this issue 7 years ago • 11 comments

Hey, I'm working with brian2 in PyCharm 2017.3.2. So far everyhing worked fine until I wanted to track every step in my code using PyCharms debugger mode. Though my code runs through when I simply run my code, it throws an error when I use the debugging mode.

Error encountered with object named "neurongroup_stateupdater".
Object was created here (most recent call only, full details in debug log):
  File "C:/ownCloud/Masterarbeit/python/pycharm/machine_hh_model_v03.py", line 123, in brian_hh_model
    group   = NeuronGroup(1, eqs, method="exponential_euler")

Could you imagine why? Or is that a question for the PyCharm guys? I'm not sure whether the problem relies in the brian2 module or the PyCharm environment. I will also post my full code here:

# brian user guide
# http://brian2.readthedocs.io/en/2.0rc/user/index.html

from brian2 import *
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style()

def brian_hh_model(input_current, plotflag, stim_start, stim_duration, **parameter):

    # running the script multiple times in the same Python process. This won't work with
    # standalone mode in particular, and requires you to include the line
    start_scope()

    # C++ standalone mode
    # At the beginning of the script, i.e. after the import statements, add:
    # set_device('cpp_standalone', build_on_run=False)

    # ********
    # Handling units
    # You can generate a physical quantity by multiplying a scalar or vector value with its physical unit:
    # tau = 20*ms --> 20. ms
    # rates = [10, 20, 30] * Hz --> [ 10.  20.  30.] Hz

    # Most Brian functions will also complain about non-specified or incorrect units:
    # G = NeuronGroup(10, 'dv/dt = -v/tau: volt', dt=0.5) --> "dt" has wrong dimensions, dimensions were (1) (s)

    # Directly get the unitless value of a state variable by appending an underscore to the name
    # print(rates_) --> [ 10.  20.  30.]
    # ********


    # Default parameters
    # Set default parameters
    default = {"ENa": 65, "EK": -90, "El": -70, "ECa": 120,
               "gNa": 0.05, "gK": 0.005, "gL": 1e-4, "gCa": 1e-5, "gM": 8e-5}

    # Use default parameter, if not defined as an input parameter
    for key, val in default.items():
        if key not in parameter:
            parameter[key] = val


    # Parameters
    # Extract parameters that were given as an input (as a dictionary).

    d    = 96 * umetre                           # 79.8 umetre
    area = d*d*3.141
    Cm   = 1*ufarad*cm**-2 * area               # 1 ufarad

    ENa  = parameter["ENa"]*mV
    EK   = parameter["EK"]*mV
    El   = parameter["El"]*mV
    ECa  = parameter["ECa"]*mV

    g_na = parameter["gNa"]*siemens*cm**-2 * area         # 0.05 siemens
    g_kd = parameter["gK"]*siemens*cm**-2 * area          # 0.005 siemens
    gl   = parameter["gL"]*siemens*cm**-2 * area           # 1e-4 siemens
    gm   = parameter["gM"]*siemens*cm**-2 * area         # 8e-5 siemens
    gCa  = parameter["gCa"]*siemens*cm**-2 * area

    tauMax = 4000 * ms

    VT = -63*mV



    # Equations
    # Define both state variables and continuous-updates on these variables through differential equations. An Equation is
    # a set of single lines in a string:
    # 1. dx/dt = f : unit (differential equation)
    # 2.     x = f : unit (subexpression)
    # 3.         x : unit (parameter)
    # There are three special units, "1" -> floating point number, "boolean" and "integer"

    # Some special variables are defined: t, dt (time) and xi (white noise). Some other variable names (e.g. _pre) are
    # forbidden. Flags -- dx/dt = f : unit (constant), parameter will not be changed during a run.


    # The model
    eqs = Equations('''
    
    Im = gm * p * (v-EK) : amp
    Ica = gCa * q*q * r * (v-ECa) : amp
    
    dv/dt = (gl*(El-v) - g_na*(m*m*m)*h*(v-ENa) - g_kd*(n*n*n*n)*(v-EK) - Im - Ica + I)/Cm : volt
    
    
    dm/dt = 0.32*(mV**-1)*(13.*mV-v+VT)/
      (exp((13.*mV-v+VT)/(4.*mV))-1.)/ms*(1-m)-0.28*(mV**-1)*(v-VT-40.*mV)/
      (exp((v-VT-40.*mV)/(5.*mV))-1.)/ms*m : 1
    dn/dt = 0.032*(mV**-1)*(15.*mV-v+VT)/
      (exp((15.*mV-v+VT)/(5.*mV))-1.)/ms*(1.-n)-.5*exp((10.*mV-v+VT)/(40.*mV))/ms*n : 1
    dh/dt = 0.128*exp((17.*mV-v+VT)/(18.*mV))/ms*(1.-h)-4./(1+exp((40.*mV-v+VT)/(5.*mV)))/ms*h : 1
    
    # K+ current
    dp/dt = (1/(1+exp(-(v-VT+35.*mV)/(10.*mV))) - p) / (tauMax / (3.3 * exp((v - VT + 35.*mV)/(20.*mV) + exp(-(v - VT + 35.*mV)/(20.*mV))))) : 1
    
    # Ca2+ current
    dq/dt = 0.055*(mV**-1) * (-27.*mV - v) / (exp((-27.*mV - v) / (3.8*mV)) - 1.)/ms * (1.-q) - 0.94*exp((-75.*mV - v) / (17.*mV))/ms*q : 1
    dr/dt = 0.000457 * exp((-13.*mV - v) / (50.*mV))/ms * (1.-r) - 0.0065 / (1. + exp((-15.*mV - v) / (28.*mV)))/ms*r : 1
    
    I : amp
    ''')


    # NeuronGroup
    # The core of every simulation is a NeuronGroup, a group of neurons that share the same equations defining their
    # properties. Minimum inputs are "number of neurons" and "model description in the form of equations". Threshold and
    # refractoriness are only used for emiting spikes. To make a neuron non-excitable for a certain time period after a
    # spike, the refractory keyword can be used.
    # G = NeuronGroup(10, 'dv/dt = -v/tau : volt', threshold='v > -50*mV', reset='v = -70*mV', refractory=5*ms)

    # Dictionary
    # You can set multiple initial values at once using a dictionary and the Group.get_states() and Group.set_states()
    # methods.
    # initial_values = {'v': 1, 'tau': 10*ms}
    # group.set_states(initial_values)
    # group.v[:] --> 1)
    # states = group.get_states()
    # states['v'] --> 1)

    group   = NeuronGroup(1, eqs, method="exponential_euler")
    group.v = El
    group.I = 0*nA


    # Recording
    # Recording variables during a simulation is done with “monitor” objects. Specifically, spikes are recorded with
    # SpikeMonitor, the time evolution of variables with StateMonitor and the firing rate of a population of neurons with
    # PopulationRateMonitor. You can get all the stored values in a monitor with the Group.get_states().

    # In this example, we record two variables v and u, and record from indices 0, 10 and 100 --> three neurons.
    # G = NeuronGroup(...)
    # M = StateMonitor(G, ('v', 'u'), record=[0, 10, 100])
    # M.v[1] will return the values for the second recorded neuron which is the neuron with the index 10.

    M = StateMonitor(group, 'v', record=0)


    # Run the model
    # The command run(100*ms) runs the simulation for 100 ms.
    run(stim_start*ms)
    group.I[0] = input_current*nA  # current injection at one end
    run(stim_duration*ms)
    group.I = 0*nA
    run(stim_start*ms)

    # C++ standalone mode
    # After the last run() call, call device.build() explicitly:
    # device.build(directory='output', compile=True, run=True, debug=False)


    # Timing
    # profiling_summary(show=5) -- show the 5 objects that took the longest
    # profiling_summary(show=2)


    # Output
    time = M.t/ms
    voltage = M.v[0]/mV


    # plot output
    if plotflag:
        plt.plot(time, voltage)
        xlabel('Time [ms]')
        ylabel('Membrane potential [mV]')
        plt.show()

    # For multiple calls
    # device.reinit()
    # device.activate()

    return (voltage, time)

v, t = brian_hh_model(1, 1, 500, 1000, ENa=65, EK=-90, El=-70, ECa=120, gNa=0.05, gK=0.005, gL=1e-4, gM=8e-5, gCa=1e-5)
print(t)

SvennoNito avatar Jan 02 '18 11:01 SvennoNito

Hi, I'm using PyCharm myself and never ran into problems using its debugging mode. Could you post the full error message that you get?

mstimberg avatar Jan 02 '18 13:01 mstimberg

Hey, thanks for your quick reply! Sure thing, this is the full output:

C:\Anaconda3\python.exe "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 50801 --file C:/ownCloud/Masterarbeit/python/pycharm/machine_hh_model_v03.py
pydev debugger: process 4328 is connecting

Connected to pydev debugger (build 173.4127.16)
Backend Qt5Agg is interactive backend. Turning interactive mode on.
cl : Command line warning D9025 : overriding '/W3' with '/w'
cl : Command line warning D9025 : overriding '/W3' with '/w'
cl : Command line warning D9002 : ignoring unknown option '/arch:SSE2'
cl : Command line warning D9002 : ignoring unknown option '/arch:SSE2'
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Microsoft', object file assumed
cl : Command line warning D9024 : unrecognized source file type '(x86)\Microsoft', object file assumed
cl : Command line warning D9027 : source file '(x86)\Microsoft' ignored
cl : Command line warning D9027 : source file '(x86)\Microsoft' ignored
cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed
cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9024 : unrecognized source file type 'Studio', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Studio', object file assumed
cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9024 : unrecognized source file type '14.0\VC\BIN\x86_amd64\cl.exe', object file assumed
cl : Command line warning D9024 : unrecognized source file type '14.0\VC\BIN\x86_amd64\cl.exe', object file assumed
cl : Command line warning D9025 : overriding '/W3' with '/w'
cl : Command line warning D9027 : source file '14.0\VC\BIN\x86_amd64\cl.exe' ignored
cl : Command line warning D9025 : overriding '/W3' with '/w'
cl : Command line warning D9027 : source file '14.0\VC\BIN\x86_amd64\cl.exe' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9002 : ignoring unknown option '/arch:SSE2'
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9002 : ignoring unknown option '/arch:SSE2'
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9024 : unrecognized source file type '(x86)\Microsoft', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Microsoft', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9027 : source file '(x86)\Microsoft' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Microsoft', object file assumed
cl : Command line warning D9027 : source file '(x86)\Microsoft' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Microsoft', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed
cl : Command line warning D9027 : source file '(x86)\Microsoft' ignored
cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed
cl : Command line warning D9027 : source file '(x86)\Microsoft' ignored
cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed
cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Studio', object file assumed
cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9024 : unrecognized source file type 'Studio', object file assumed
cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9024 : unrecognized source file type 'Studio', object file assumed
cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9024 : unrecognized source file type 'Studio', object file assumed
cl : Command line warning D9024 : unrecognized source file type '14.0\VC\INCLUDE', object file assumed
cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9024 : unrecognized source file type '14.0\VC\INCLUDE', object file assumed
cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9027 : source file '14.0\VC\INCLUDE' ignored
cl : Command line warning D9024 : unrecognized source file type '14.0\VC\BIN\x86_amd64\cl.exe', object file assumed
cl : Command line warning D9027 : source file '14.0\VC\INCLUDE' ignored
cl : Command line warning D9024 : unrecognized source file type '14.0\VC\BIN\x86_amd64\cl.exe', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file '14.0\VC\BIN\x86_amd64\cl.exe' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file '14.0\VC\BIN\x86_amd64\cl.exe' ignored
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Microsoft', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Microsoft', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Kits\10\include\10.0.10240.0\ucrt', object file assumed
cl : Command line warning D9027 : source file '(x86)\Microsoft' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\10\include\10.0.10240.0\ucrt', object file assumed
cl : Command line warning D9027 : source file '(x86)\Microsoft' ignored
cl : Command line warning D9027 : source file 'Kits\10\include\10.0.10240.0\ucrt' ignored
cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed
cl : Command line warning D9027 : source file 'Kits\10\include\10.0.10240.0\ucrt' ignored
cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type 'Studio', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type 'Studio', object file assumed
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type '14.0\VC\INCLUDE', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type '14.0\VC\INCLUDE', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\shared', object file assumed
cl : Command line warning D9027 : source file '14.0\VC\INCLUDE' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\shared', object file assumed
cl : Command line warning D9027 : source file '14.0\VC\INCLUDE' ignored
cl : Command line warning D9027 : source file 'Kits\8.1\include\shared' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Kits\8.1\include\shared' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\10\include\10.0.10240.0\ucrt', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\10\include\10.0.10240.0\ucrt', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\um', object file assumed
cl : Command line warning D9027 : source file 'Kits\10\include\10.0.10240.0\ucrt' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\um', object file assumed
cl : Command line warning D9027 : source file 'Kits\10\include\10.0.10240.0\ucrt' ignored
cl : Command line warning D9027 : source file 'Kits\8.1\include\um' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Kits\8.1\include\um' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\shared', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\shared', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\winrt', object file assumed
cl : Command line warning D9027 : source file 'Kits\8.1\include\shared' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\winrt', object file assumed
cl : Command line warning D9027 : source file 'Kits\8.1\include\shared' ignored
cl : Command line warning D9027 : source file 'Kits\8.1\include\winrt' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Kits\8.1\include\winrt' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
_cython_magic_ab7ca7b3708fc509abe42201b0b90b51.cpp
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\um', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\um', object file assumed
cl : Command line warning D9027 : source file 'Kits\8.1\include\um' ignored
cl : Command line warning D9027 : source file 'Kits\8.1\include\um' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\winrt', object file assumed
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\winrt', object file assumed
cl : Command line warning D9027 : source file 'Kits\8.1\include\winrt' ignored
cl : Command line warning D9027 : source file 'Kits\8.1\include\winrt' ignored
c:\anaconda3\include\pyconfig.h(59): fatal error C1083: Cannot open include file: 'io.h': No such file or directory (compiling source file C:\Users\SvenLeach\.cython\brian_extensions\_cython_magic_ab7ca7b3708fc509abe42201b0b90b51.cpp)
cl : Command line warning D9025 : overriding '/W3' with '/w'
cl : Command line warning D9002 : ignoring unknown option '/arch:SSE2'
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Microsoft', object file assumed
cl : Command line warning D9027 : source file '(x86)\Microsoft' ignored
cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed
cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9024 : unrecognized source file type 'Studio', object file assumed
cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9024 : unrecognized source file type '14.0\VC\BIN\x86_amd64\cl.exe', object file assumed
cl : Command line warning D9027 : source file '14.0\VC\BIN\x86_amd64\cl.exe' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Microsoft', object file assumed
cl : Command line warning D9027 : source file '(x86)\Microsoft' ignored
cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed
cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9024 : unrecognized source file type 'Studio', object file assumed
cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9024 : unrecognized source file type '14.0\VC\INCLUDE', object file assumed
cl : Command line warning D9027 : source file '14.0\VC\INCLUDE' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\10\include\10.0.10240.0\ucrt', object file assumed
cl : Command line warning D9027 : source file 'Kits\10\include\10.0.10240.0\ucrt' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\shared', object file assumed
cl : Command line warning D9027 : source file 'Kits\8.1\include\shared' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\um', object file assumed
cl : Command line warning D9027 : source file 'Kits\8.1\include\um' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files', object file assumed
cl : Command line warning D9027 : source file 'Files' ignored
cl : Command line warning D9024 : unrecognized source file type '(x86)\Windows', object file assumed
cl : Command line warning D9027 : source file '(x86)\Windows' ignored
cl : Command line warning D9024 : unrecognized source file type 'Kits\8.1\include\winrt', object file assumed
cl : Command line warning D9027 : source file 'Kits\8.1\include\winrt' ignored
ERROR      Brian 2 encountered an unexpected error. If you think this is bug in Brian 2, please report this issue either to the mailing list at <http://groups.google.com/group/brian-development/>, or to the issue tracker at <https://github.com/brian-team/brian2/issues>. Please include this file with debug information in your report: C:\Users\SVENLE~1\AppData\Local\Temp\brian_debug_ox_eit53.log  Additionally, you can also include a copy of the script that was run, available at: C:\Users\SVENLE~1\AppData\Local\Temp\brian_script_oiiozj75.py You can also include a copy of the redirected std stream outputs, available at C:\Users\SVENLE~1\AppData\Local\Temp\brian_stdout_j6vy_wa3.log and C:\Users\SVENLE~1\AppData\Local\Temp\brian_stderr_1ghypk70.log Thanks! [brian2]
Traceback (most recent call last):
  File "C:\Anaconda3\lib\distutils\_msvccompiler.py", line 382, in compile
    self.spawn(args)
  File "C:\Anaconda3\lib\distutils\_msvccompiler.py", line 501, in spawn
    return super().spawn(cmd)
  File "C:\Anaconda3\lib\distutils\ccompiler.py", line 909, in spawn
    spawn(cmd, dry_run=self.dry_run)
  File "C:\Anaconda3\lib\distutils\spawn.py", line 38, in spawn
    _spawn_nt(cmd, search_path, dry_run=dry_run)
  File "C:\Anaconda3\lib\distutils\spawn.py", line 81, in _spawn_nt
    "command %r failed with exit status %d" % (cmd, rc))
distutils.errors.DistutilsExecError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\brian2\core\network.py", line 841, in before_run
    obj.before_run(run_namespace)
  File "C:\Anaconda3\lib\site-packages\brian2\groups\group.py", line 1101, in before_run
    codeobj_class=self.codeobj_class
  File "C:\Anaconda3\lib\site-packages\brian2\codegen\codeobject.py", line 310, in create_runner_codeobj
    override_conditional_write=override_conditional_write,
  File "C:\Anaconda3\lib\site-packages\brian2\devices\device.py", line 334, in code_object
    codeobj.compile()
  File "C:\Anaconda3\lib\site-packages\brian2\codegen\runtime\cython_rt\cython_rt.py", line 120, in compile
    owner_name=self.owner.name+'_'+self.template_name,
  File "C:\Anaconda3\lib\site-packages\brian2\codegen\runtime\cython_rt\extension_manager.py", line 120, in create_extension
    key=key)
  File "C:\Anaconda3\lib\site-packages\brian2\codegen\runtime\cython_rt\extension_manager.py", line 242, in _load_module
    build_extension.run()
  File "C:\Anaconda3\lib\distutils\command\build_ext.py", line 339, in run
    self.build_extensions()
  File "C:\Anaconda3\lib\distutils\command\build_ext.py", line 448, in build_extensions
    self._build_extensions_serial()
  File "C:\Anaconda3\lib\distutils\command\build_ext.py", line 473, in _build_extensions_serial
    self.build_extension(ext)
  File "C:\Anaconda3\lib\distutils\command\build_ext.py", line 533, in build_extension
    depends=ext.depends)
  File "C:\Anaconda3\lib\distutils\_msvccompiler.py", line 384, in compile
    raise CompileError(msg)
distutils.errors.CompileError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\pydevd.py", line 1668, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\pydevd.py", line 1662, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\pydevd.py", line 1072, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/ownCloud/Masterarbeit/python/pycharm/machine_hh_model_v03.py", line 177, in <module>
    v, t = brian_hh_model(1, 1, 500, 1000, ENa=65, EK=-90, El=-70, ECa=120, gNa=0.05, gK=0.005, gL=1e-4, gM=8e-5, gCa=1e-5)
  File "C:/ownCloud/Masterarbeit/python/pycharm/machine_hh_model_v03.py", line 143, in brian_hh_model
    run(stim_start*ms)
  File "C:\Anaconda3\lib\site-packages\brian2\units\fundamentalunits.py", line 2360, in new_f
    result = f(*args, **kwds)
  File "C:\Anaconda3\lib\site-packages\brian2\core\magic.py", line 371, in run
    namespace=namespace, profile=profile, level=2+level)
  File "C:\Anaconda3\lib\site-packages\brian2\core\magic.py", line 231, in run
    namespace=namespace, profile=profile, level=level+1)
  File "C:\Anaconda3\lib\site-packages\brian2\core\base.py", line 278, in device_override_decorated_function
    return func(*args, **kwds)
  File "C:\Anaconda3\lib\site-packages\brian2\units\fundamentalunits.py", line 2360, in new_f
    result = f(*args, **kwds)
  File "C:\Anaconda3\lib\site-packages\brian2\core\network.py", line 951, in run
    self.before_run(namespace)
  File "C:\Anaconda3\lib\site-packages\brian2\core\base.py", line 278, in device_override_decorated_function
    return func(*args, **kwds)
  File "C:\Anaconda3\lib\site-packages\brian2\core\network.py", line 843, in before_run
    raise brian_object_exception("An error occurred when preparing an object.", obj, ex)
brian2.core.base.BrianObjectException: Original error and traceback:
Traceback (most recent call last):
  File "C:\Anaconda3\lib\distutils\_msvccompiler.py", line 382, in compile
    self.spawn(args)
  File "C:\Anaconda3\lib\distutils\_msvccompiler.py", line 501, in spawn
    return super().spawn(cmd)
  File "C:\Anaconda3\lib\distutils\ccompiler.py", line 909, in spawn
    spawn(cmd, dry_run=self.dry_run)
  File "C:\Anaconda3\lib\distutils\spawn.py", line 38, in spawn
    _spawn_nt(cmd, search_path, dry_run=dry_run)
  File "C:\Anaconda3\lib\distutils\spawn.py", line 81, in _spawn_nt
    "command %r failed with exit status %d" % (cmd, rc))
distutils.errors.DistutilsExecError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\brian2\core\network.py", line 841, in before_run
    obj.before_run(run_namespace)
  File "C:\Anaconda3\lib\site-packages\brian2\groups\group.py", line 1101, in before_run
    codeobj_class=self.codeobj_class
  File "C:\Anaconda3\lib\site-packages\brian2\codegen\codeobject.py", line 310, in create_runner_codeobj
    override_conditional_write=override_conditional_write,
  File "C:\Anaconda3\lib\site-packages\brian2\devices\device.py", line 334, in code_object
    codeobj.compile()
  File "C:\Anaconda3\lib\site-packages\brian2\codegen\runtime\cython_rt\cython_rt.py", line 120, in compile
    owner_name=self.owner.name+'_'+self.template_name,
  File "C:\Anaconda3\lib\site-packages\brian2\codegen\runtime\cython_rt\extension_manager.py", line 120, in create_extension
    key=key)
  File "C:\Anaconda3\lib\site-packages\brian2\codegen\runtime\cython_rt\extension_manager.py", line 242, in _load_module
    build_extension.run()
  File "C:\Anaconda3\lib\distutils\command\build_ext.py", line 339, in run
    self.build_extensions()
  File "C:\Anaconda3\lib\distutils\command\build_ext.py", line 448, in build_extensions
    self._build_extensions_serial()
  File "C:\Anaconda3\lib\distutils\command\build_ext.py", line 473, in _build_extensions_serial
    self.build_extension(ext)
  File "C:\Anaconda3\lib\distutils\command\build_ext.py", line 533, in build_extension
    depends=ext.depends)
  File "C:\Anaconda3\lib\distutils\_msvccompiler.py", line 384, in compile
    raise CompileError(msg)
distutils.errors.CompileError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

Error encountered with object named "neurongroup_stateupdater".
Object was created here (most recent call only, full details in debug log):
  File "C:/ownCloud/Masterarbeit/python/pycharm/machine_hh_model_v03.py", line 123, in brian_hh_model
    group   = NeuronGroup(1, eqs, method="exponential_euler")

An error occurred when preparing an object. distutils.errors.CompileError: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
(See above for original error message and traceback.)

Process finished with exit code 1

SvennoNito avatar Jan 02 '18 15:01 SvennoNito

Thanks for the info, I can reproduce a similar error in a Windows virtual machine (it seems to be specific to Windows). It does not seem to be a Brian issue, but rather a problem with Cython & PyCharm: If you try the following code:

import cython
def f(a):
    return cython.inline("return a+b", b=3, force=True)

print(f(5))

You should get the same behaviour (i.e. works fine for a normal run, but fails in debug mode). The issue seems to be that PyCharm overwrites the spawn command used for launching external processes (I guess to enable debugging of multiprocess applications) and it somewhere along the way looses quotes around the arguments -- if you look at the warnings, you see that it tries to interpret stuff like Program Files (x86)\Microsoft Visual Studio 14.0 as "Program" "Files" "(x86)\Microsoft" ....

I did not find this issue in PyCharm's issue tracker, but I did not do a thorough search... It'd be curious if this had never been reported.

As a workaround, you could switch to the numpy code generation target for debugging (prefs.codegen.target = 'numpy').

mstimberg avatar Jan 02 '18 19:01 mstimberg

Hey @mstimberg thanks for your thoughts! When I use prefs.codegen.target = numpy I get the following error:

Connected to pydev debugger (build 173.4127.16)
ERROR      Brian 2 encountered an unexpected error. If you think this is bug in Brian 2, please report this issue either to the mailing list at <http://groups.google.com/group/brian-development/>, or to the issue tracker at <https://github.com/brian-team/brian2/issues>. Please include this file with debug information in your report: C:\Users\SVENLE~1\AppData\Local\Temp\brian_debug_itlodcjt.log  Additionally, you can also include a copy of the script that was run, available at: C:\Users\SVENLE~1\AppData\Local\Temp\brian_script_r6q9wrly.py Thanks! [brian2]
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\pydevd.py", line 1668, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\pydevd.py", line 1662, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\pydevd.py", line 1072, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/ownCloud/Masterarbeit/python/pycharm/test.py", line 19, in <module>
    print(f(5))
  File "C:/ownCloud/Masterarbeit/python/pycharm/test.py", line 16, in f
    prefs.codegen.target = 'numpy'
NameError: name 'prefs' is not defined

EDIT

Never mind, only in the minimal example you provided. With this line of code in my brian script I can finally debug the way I wanted, I'm so glad! Thank you! Though I don't really understand what happened, but as long as it works I'm happy haha. Thanks a ton!

Sven

SvennoNito avatar Jan 02 '18 19:01 SvennoNito

Sorry, that was not clear: prefs are the Brian preferences, i.e. this should go after the from brian2 import * in your original script, it will not work in the simple Cython example (see http://brian2.readthedocs.io/en/stable/user/computation.html#runtime-code-generation).

mstimberg avatar Jan 02 '18 19:01 mstimberg

I opened an issue in the PyCharm issue tracker, let's see what they reply: https://youtrack.jetbrains.com/issue/PY-27833

mstimberg avatar Jan 04 '18 17:01 mstimberg

Any update on this? I have the same problem on MAC. It's driving me crazy. I can't import brian2 in debug mode using: from brian2 import *

Vafa-Andalibi avatar Feb 20 '18 03:02 Vafa-Andalibi

I ran the pycharm as sudo and seems like at least I can use debug mode but it's really slow, it takes a lot to pass the import part

Vafa-Andalibi avatar Feb 20 '18 04:02 Vafa-Andalibi

Unfortunately the upstream bug does not seem to have any activity so far. The best workaround at the moment is to not use Cython but fall back to the numpy code generation interface. I.e., set:

prefs.codegen.target = 'numpy'

at the start of the script. This mode can also be helpful for issues that turn out to be bugs in Brian itself, because in numpy mode things like going beyond the end of an array will raise an error instead of silently doing something weird or leading to a segmentation fault.

mstimberg avatar Feb 23 '18 13:02 mstimberg

Another workaround: uncheck "Attach to subprocess automatically while debugging" in PyCharm's "Build, Execution, Deployment > Python Debugger" settings.

mstimberg avatar Nov 06 '18 10:11 mstimberg

Not sure whether this is still an issue, maybe someone on Windows can check?

mstimberg avatar Apr 18 '24 08:04 mstimberg