對于以下輸入
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
對于 Scipy 版本 1.8.0,solve_ivp 失敗,輸出如下:
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)vs Scipy 1.5.0:t0, tf = float(t_span[0]), float(t_span[1])
不確定這是否與失敗的原因有關,但奇怪的是 Scipy 1.8.0 不接受相同的輸入。我想使用 np.arange(start, finish, interval) 進行集成,是否有任何原因導致失敗?
uj5u.com熱心網友回復:
根據檔案
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只是結束點。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/449885.html
