Issue
For the following input
neuron_dict = {'param_set': sb.morris_lecar_defaults(V_3 = 11.96), 'time_range': (0, 10000, 0.0001), 'initial_cond': (-3.06560496e+01, 7.33832272e-03, 8.35251563e-01), 'stretch': 4.2, 'track_event': sb.voltage_passes_threshold ,'location': np.array([20,0,100])}
sb.ivp_solver(sb.morris_lecar, time_range = neuron_dict['time_range'], initial_cond = neuron_dict['initial_cond'], params = neuron_dict['param_set'], track_event = neuron_dict['track_event'])
def ivp_solver(system_of_equations: callable, time_range: tuple, initial_cond: tuple,params: callable = morris_lecar_defaults(), track_event: callable = voltage_passes_threshold, numerical_method = 'BDF', rtol = 1e-8) -> object:
track_event.direction = 1
sol = solve_ivp(system_of_equations, time_range, initial_cond, args=(params,), events= track_event, t_eval= np.arange(time_range[0], time_range[1], time_range[2]), method = numerical_method, rtol = rtol)
return sol
solve_ivp fails with the following output for Scipy version 1.8.0 with traceback:
Traceback (most recent call last):
File "...MEA_foward_model.py", line 438, in <module>
main()
File "...MEA_foward_model.py", line 430, in main
near_synchronous_dual_bursting_example()
File "...MEA_foward_model.py", line 377, in near_synchronous_dual_bursting_example
ts, voltages, currents, time_events, y_events = integrate_neurons(neurons_list)
File "...MEA_foward_model.py", line 185, in integrate_neurons
sol = sb.ivp_solver(sb.morris_lecar, time_range = neuron_dict['time_range'], initial_cond = neuron_dict['initial_cond'], params = neuron_dict['param_set'], track_event = neuron_dict['track_event'])
File "...\Square_bursting_oscillations.py", line 106, in ivp_solver
sol = solve_ivp(system_of_equations, time_range, initial_cond, args=(params,), events= track_event, t_eval= np.arange(time_range[0], time_range[1], time_range[2]), method = numerical_method, rtol = rtol)
File "C:\Anaconda\envs\test\lib\site-packages\scipy\integrate\_ivp\ivp.py", line 512, in solve_ivp
t0, tf = map(float, t_span)
ValueError: too many values to unpack (expected 2)
but in Scipy version 1.5.0 (my base interpreter) it runs without issue. Looking at the line highlighted in the traceback in ivp.py
:
Scipy 1.8.0: t0, tf = map(float, t_span)
vs Scipy 1.5.0: t0, tf = float(t_span[0]), float(t_span[1])
not sure if this has any bearing on the reason why it failed but it is odd that Scipy 1.8.0 doesn't accept the same input. I would like to use np.arange(start, finish, interval) for my integration, is there any reason why this is failing?
Solution
According to the docs
t_span
2-tuple of floats
Interval of integration (t0, tf). The solver starts with t=t0 and
integrates until it reaches t=tf.
For a 2 element tuple, these are the same:
t0, tf = map(float, t_span)
t0, tf = float(t_span[0]), float(t_span[1])
But the first raises this error when t_span
is longer than 2. The second just ignores the additional values. It's the t0,tf=...
unpacking that enforces the 2-element requirement.
Maybe you want to give t_eval
the longer arange
, and t_span
just the end points.
Answered By - hpaulj
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.