neurolib-dev/neurolib

wc.run(continue_run=True) breaks

ronja-roevardotter opened this issue · 4 comments

by calling

for i, val in enumerate(inputs):
  if i==0:
    wc.run()
  else:
    wc.run(continue_run=True)

the following error is returned as i=2:

Traceback (most recent call last):
  File "/mnt/antares_raid/home/ronjastroms/anaconda3/envs/trial/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/mnt/antares_raid/home/ronjastroms/anaconda3/envs/trial/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "/mnt/antares_raid/home/ronjastroms/Bifurcation.py", line 139, in continuedRun_wc
    self.model.run(continue_run=True)
  File "/mnt/antares_raid/home/ronjastroms/anaconda3/envs/trial/lib/python3.7/site-packages/neurolib/models/model.py", line 227, in run
    self.integrate(append_outputs=append, simulate_bold=bold)
  File "/mnt/antares_raid/home/ronjastroms/anaconda3/envs/trial/lib/python3.7/site-packages/neurolib/models/model.py", line 267, in integrate
    t, *variables = self.integration(self.params)
  File "/mnt/antares_raid/home/ronjastroms/anaconda3/envs/trial/lib/python3.7/site-packages/neurolib/models/wc/timeIntegration.py", line 164, in timeIntegration
    tau_adap,
  File "/mnt/antares_raid/home/ronjastroms/anaconda3/envs/trial/lib/python3.7/site-packages/numba/dispatcher.py", line 401, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/mnt/antares_raid/home/ronjastroms/anaconda3/envs/trial/lib/python3.7/site-packages/numba/dispatcher.py", line 344, in error_rewrite
    reraise(type(e), e, None)
  File "/mnt/antares_raid/home/ronjastroms/anaconda3/envs/trial/lib/python3.7/site-packages/numba/six.py", line 668, in reraise
    raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<built-in function setitem>) with argument(s) of type(s): (array(float64, 2d, C), UniTuple(int64 x 2), array(float64, 1d, C))
 * parameterized
In definition 0:
    All templates rejected with literals.
In definition 1:
    All templates rejected without literals.
In definition 2:
    All templates rejected with literals.
In definition 3:
    All templates rejected without literals.
In definition 4:
    All templates rejected with literals.
In definition 5:
    All templates rejected without literals.
In definition 6:
    All templates rejected with literals.
In definition 7:
    All templates rejected without literals.
In definition 8:
    All templates rejected with literals.
In definition 9:
    All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: typing of setitem at /mnt/antares_raid/home/ronjastroms/anaconda3/envs/trial/lib/python3.7/site-packages/neurolib/models/wc/timeIntegration.py (270)

File "anaconda3/envs/trial/lib/python3.7/site-packages/neurolib/models/wc/timeIntegration.py", line 270:
    def S_I(x):
        <source elided>
            # Euler integration
            excs[no, i] = excs[no, i - 1] + dt * exc_rhs
            ^

hey @Ronjaa95,

it seems that inputs have weird shape and neurolib is not happy about that:)
can you please do something like:

for i, val in enumerate(inputs):
    print(inputs.shape)
    if i==0:
        wc.run()
    else:
        wc.run(continue_run=True)

now I see you do not pass the inputs to the run, is that intended?
when I simply do:

wc.run()
# any number of times
wc.run(continue_run=True)
wc.run(continue_run=True)
wc.run(continue_run=True)

it works for me...

I'm sorry, I forgot to insert that into the code, the loop does change the input:


for i, val in enumerate(inputs):
  if i==0:
    wc.params['exc_ext']=val
    wc.run()
  else:
    wc.params['exc_ext']=val
    wc.run(continue_run=True)

I'll check for the shape.

Mhh it's a weird error, it looks like the arguments of the functions are changing. For sure, will need to use python mode to debug this, but I can look into this! Could you please post the entire code that reproduces the error? It would make it a lot easier to find the bug.

Thanks for creating the Issue!

Sure, the inputs are initialized by

inputs = np.arange(bound_low, bound_up, stepsize)

The function is called via

modelUp = copy.deepcopy(wc) # deepcopy model to avoid interference
p1 = multiprocessing.Process(target=self.continuedRun_wc, 
                                         args=(modelUp, 'up', inputs, return_dict, wiggle))
p1.start()

into the function

 def continuedRun_wc(self, model, typ, steps, returndict):
        
        numSteps = len(steps)
        max_exc = np.ndarray( numSteps )
        min_exc = np.ndarray( numSteps )
        max_inh = np.ndarray( numSteps )
        min_inh = np.ndarray( numSteps )

            
        for i, cvalue in tqdm(enumerate(steps), total=numSteps):
            wc.params[self.continueParam] = cvalue
            if i == 0:
                self.model.run()
            else:                
                self.model.run(continue_run=True)

           # get max and min of last n seconds (defined by self.analysisDur)
            end = snalysisDur*1000 /mwcparams.dt

            max_exc[i] = np.max(wc['exc'][0, -int(end):])
            min_exc[i] = np.min(wc['exc'][0, -int(end):])
            max_inh[i] = np.max(wc['inh'][0, -int(end):])
            min_inh[i] = np.min(wc['inh'][0, -int(end):])

    
        returndict[typ] = [max_exc, min_exc, max_inh, min_inh]