@@ -571,6 +571,7 @@ def set_integrator(self,name,nsteps=10**6,interpolate=True,**integrator_params):
571571 * `"dopri5"` – Dormand’s and Prince’s explicit fifth-order method via `ode`
572572 * `"RK45"` – Dormand’s and Prince’s explicit fifth-order method via `solve_ivp`
573573 * `"dop853"` – DoP853 (explicit) via `ode`
574+ * `"DOP853"` – DoP853 (explicit) via `solve_ivp`
574575 * `"RK23"` – Bogacki’s and Shampine’s explicit third-order method via `solve_ivp`
575576 * `"BDF"` – Implicit backward-differentiation formula via `solve_ivp`
576577 * `"lsoda"` – LSODA (implicit) via `ode`
@@ -598,6 +599,7 @@ def set_integrator(self,name,nsteps=10**6,interpolate=True,**integrator_params):
598599 self .generate_functions ()
599600
600601 if info ["backend" ] == "ode" :
602+ self .initialise ()
601603 self .integrator = ODE_wrapper (self .f ,self .jac )
602604 self .integrator .set_integrator (
603605 name ,
@@ -611,26 +613,33 @@ def set_integrator(self,name,nsteps=10**6,interpolate=True,**integrator_params):
611613 self .integrator = IVP (
612614 name ,
613615 self .f ,
614- self .jac ,
616+ initialiser = lambda : self .initialise (force = True ),
617+ jac = self .jac ,
615618 ** integrator_params
616619 )
617620
618- # Restore state and params , if applicable:
621+ # Restore state and time , if applicable:
619622 try :
620- self .set_initial_value (old_integrator ._y ,old_integrator .t )
623+ old_y = old_integrator ._y
624+ old_t = old_integrator .t
621625 except (AttributeError ,RuntimeError ):
622626 pass
627+ else :
628+ self .set_initial_value (old_y ,old_t )
623629
624- def initialise (self ):
630+ def initialise (self , force = False ):
625631 if self ._initialise is not None :
626- self ._initialise (
632+ if len (self .control_par_values )== len (self .control_pars ):
633+ self ._initialise (
627634 * self .control_par_values ,
628635 * [callback for _ ,callback ,_ in self .callback_functions ]
629636 )
637+ elif force :
638+ raise RuntimeError ("Something needs parameters to be set. Try calling `set_parameters` earlier." )
630639
631640 def set_parameters (self ,* args ):
632641 """
633- Same as `set_f_params` and `set_jac_params` for SciPy’s ODE (both sets of parameters are set simultaneuosly, because they should be the same anyway).
642+ Same as `set_f_params` and `set_jac_params` for SciPy’s ODE (both sets of parameters are set simultaneuosly, because they should be the same anyway).
634643
635644 The parameters can be passed as different arguments or as a list or other sequence.
636645 """
@@ -642,6 +651,9 @@ def set_parameters(self,*args):
642651 if len (args )> 1 :
643652 raise TypeError ("Argument must either be a single sequence or multiple numbers." )
644653
654+ if len (self .control_par_values )!= len (self .control_pars ):
655+ raise ValueError ("Number of values does not match number of control parameters." )
656+
645657 self .initialise ()
646658
647659 def set_f_params (self , * args ):
0 commit comments