在 t_span 中使用 np.arange() 时出错,在 Scipy 1.8.0 中使用 solve_ivp 错误,但在 1.5.0 中则不会

Error using np.arange() in t_span with solve_ivp error in Scipy 1.8.0 but not 1.5.0

对于以下输入

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 失败,Scipy 版本 1.8.0 的以下输出带有回溯:

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)

但在 Scipy 版本 1.5.0(我的基本解释器)中它运行没有问题。查看 ivp.py 中回溯中突出显示的行: Scipy 1.8.0:t0, tf = map(float, t_span) 对比 Scipy 1.5.0:t0, tf = float(t_span[0]), float(t_span[1])

不确定这是否与失败的原因有关,但奇怪的是 Scipy 1.8.0 不接受相同的输入。我想使用 np.arange(start, finish, interval) 进行我的集成,是否有任何失败的原因?

根据文档

t_span
2-tuple of floats
Interval of integration (t0, tf). The solver starts with t=t0 and 
   integrates until it reaches t=tf.

对于 2 元素元组,这些是相同的:

t0, tf = map(float, t_span)
t0, tf = float(t_span[0]), float(t_span[1])

但是当 t_span 长于 2 时,第一个会引发此错误。第二个只是忽略附加值。 t0,tf=... 解包强制执行 2 元素要求。

也许您想给 t_eval 更长的 arange,而 t_span 只是终点。