Syntax error: Value is not constant

Description of problem
Hello, I am trying a new plasticity mechanism that depends on the activity of the presynaptic neuron (rho_PF) and postsynaptic neuron (rho_PC). The change in weights depends on a sliding threshold based on the postsynaptic neuron’s activity. However, the equation I’m trying to use to keep my weight changes bounded does not work. I get an error that says Syntax error: Value thresh_M is not constant.

Minimal code to reproduce problem

eqs_Copy = '''
                I : amp  # copy of the noise current
                rho_PF : Hz 
                rho_PC : Hz
                weight : 1 (constant)
                new_weight = weight + delta_weight_CS: 1 
                ddelta_weight_BCM/dt = ((rho_PC*(rho_PC-thresh_M)*e**(-((thresh_M-500*Hz)/(250*(thresh_M-250*Hz)))*rho_PC))/thresh_M)*rho_PF*msecond : 1 
                phi = (rho_PC*(rho_PC-thresh_M)*e**(-((thresh_M-500*Hz)/(250*(thresh_M-250*Hz)))*rho_PC))/thresh_M : Hz    
                dthresh_M/dt = rho_PC**2 - thresh_M/tau_thresh_M : Hz 
        '''
        conn_N_PC = NeuronGroup(N_Copy, eqs_Copy, method='euler',dt=dt)
        conn_N_PC.weight = Noise_PC_Synapse_Weights
        mon_N_PC = StateMonitor(conn_N_PC , ['rho_PF','rho_PC','phi','thresh_M','delta_weight_CS','new_weight','delta_weight_BCM'], record=conn_N_PC_record, dt=dt_rec) 

What you have aready tried
I understand the problem comes from the (250-theta) part as theta could reach 250 and make it go to zero. However, I don’t understand what the error truly means.

Expected output (if relevant)

Actual output (if relevant)

Full traceback of error (if relevant)

Hi @eliasmateo95. This is less obvious than what it should be, but first the reason for the error: in this equation

e**(-((thresh_M-500*Hz)/(250*(thresh_M-250*Hz)))*rho_PC)

the exponent of e is wrong, you probably wanted to close the parentheses before multiplying it with rho_PC (or divide rho_PC by thresh_M as part of the argument)? As it is written now, the exponent has dimensions of 1/time, and you cannot take e to the power of a value that is not dimensionless.

You’d actually get a better error message if you used exp(...) instead of e**(...):

Argument number 1 for function exp does not have the correct units. Expression '(- ((thresh_M - (500 * Hz)) / (250 * (thresh_M - (250 * Hz))))) * rho_PC' has units (s^-1), but should be (1).

The reason you are getting this “value is not constant” error is that the code is going through the general pathway for x^y, trying to figure out the value of y (since e.g. something like v**c would have a different dimensionality depending on the value of the constant c). In your case, y is not a fixed value, since it refers to the variables thresh_M and rho_PC. This is why it complains about a value that isn’t constant. If y is dimensionless (as it should be), then it shouldn’t matter – we should change the error handling here so that it doesn’t hide the real issue.

Hope that makes things clear!