def test_wrong_diffusion_raises_error(ivp): """Methods that are not in the list raise errors.""" f = ivp.f t0, tmax = ivp.t0, ivp.tmax y0 = ivp.y0 with pytest.raises(ValueError): probsolve_ivp(f, t0, tmax, y0, diffusion_model="something_wrong")
def peakmem_solve(self, method, precond, prior): precond_step = self.stepsize if precond == "with" else 1.0 probsolve_ivp( self.ivp, method=method, which_prior=prior, step=self.stepsize, precond_step=precond_step, )
def test_non_adaptive_mode(ivp): """When run in non-adaptive mode and without specifying a time-step, an explicit ValueError should be raised.""" f = ivp.f t0, tmax = ivp.t0, ivp.tmax y0 = ivp.y0 with pytest.raises(ValueError): probsolve_ivp(f, t0, tmax, y0, adaptive=False)
def test_wrong_method_raises_error(ivp): """Methods that are not in the list raise errors.""" f = ivp.f t0, tmax = ivp.t0, ivp.tmax y0 = ivp.y0 # UK1 does not exist anymore with pytest.raises(ValueError): probsolve_ivp(f, t0, tmax, y0, method="UK")
def peakmem_solve(self, method, precond, prior): # pylint: disable=missing-function-docstring precond_step = self.stepsize if precond == "with" else 1.0 probsolve_ivp( self.ivp, method=method, which_prior=prior, step=self.stepsize, precond_step=precond_step, )
def peakmem_solve(self, method, algo_order): probsolve_ivp( f=self.ivp.f, t0=self.ivp.t0, tmax=self.ivp.tmax, y0=self.ivp.y0, df=self.ivp.df, method=method, dense_output=True, algo_order=algo_order, step=self.stepsize, adaptive=False, )
def test_no_step_or_tol_info_raises_error(ivp): """Providing neither a step-size nor a tolerance raises an error.""" f = ivp.f t0, tmax = ivp.t0, ivp.tmax y0 = ivp.y0 with pytest.raises(ValueError): probsolve_ivp(f, t0, tmax, y0, step=None, adaptive=True, atol=None, rtol=None)
def test_convergence_error(ivp, algo_order): """Assert that by halfing the step-size, the error of the small step is roughly the error of the large step multiplied with (small / large)**(nu)""" # Set up two different step-sizes step_large = 0.2 step_small = 0.5 * step_large expected_decay = (step_small / step_large)**algo_order # Solve IVP with both step-sizes f = ivp.f t0, tmax = ivp.t0, ivp.tmax y0 = ivp.y0 sol_small_step = diffeq.probsolve_ivp( f, t0, tmax, y0, step=step_small, algo_order=algo_order, adaptive=False, diffusion_model="dynamic", ) sol_large_step = diffeq.probsolve_ivp( f, t0, tmax, y0, step=step_large, algo_order=algo_order, adaptive=False, diffusion_model="dynamic", ) # Check that the final point is identical (sanity check) np.testing.assert_allclose(sol_small_step.locations[-1], sol_large_step.locations[-1]) # Compute both errors ref_sol = ivp.solution(sol_small_step.locations[-1]) err_small_step = np.linalg.norm(ref_sol - sol_small_step.states[-1].mean) err_large_step = np.linalg.norm(ref_sol - sol_large_step.states[-1].mean) # Non-strict rtol, bc this test is flaky by construction # As long as rtol < 1., this test seems meaningful. np.testing.assert_allclose(err_small_step, expected_decay * err_large_step, rtol=0.95)
def setUp(self): initrv = Normal(20 * np.ones(2), 0.1 * np.eye(2), cov_cholesky=np.sqrt(0.1) * np.eye(2)) self.ivp = lotkavolterra([0.0, 0.5], initrv) step = 0.1 self.solution = probsolve_ivp(self.ivp, step=step)
def peakmem_solve(self, method, algo_order): f = self.ivp.rhs df = self.ivp.jacobian t0, tmax = self.ivp.timespan y0 = self.ivp.initrv.mean probsolve_ivp( f, t0, tmax, y0, df=df, method=method, algo_order=algo_order, step=self.stepsize, adaptive=False, )
def posterior(stepsize, timespan): """Kalman smoothing posterior.""" initrv = randvars.Constant(20 * np.ones(2)) ivp = diffeq.ode.lotkavolterra(timespan, initrv) f = ivp.rhs t0, tmax = ivp.timespan y0 = ivp.initrv.mean return diffeq.probsolve_ivp(f, t0, tmax, y0, step=stepsize, adaptive=False)
def posterior(stepsize, timespan): """Kalman smoothing posterior.""" t0, tmax = timespan y0 = 20 * np.ones(2) ivp = diffeq_zoo.lotkavolterra(t0=t0, tmax=tmax, y0=y0) f = ivp.f t0, tmax = ivp.t0, ivp.tmax return diffeq.probsolve_ivp(f, t0, tmax, y0, step=stepsize, adaptive=False)
def setUp(self): initrv = Constant(20 * np.ones(2)) self.ivp = lotkavolterra([0.0, 0.5], initrv) step = 0.1 f = self.ivp.rhs t0, tmax = self.ivp.timespan y0 = self.ivp.initrv.mean self.solution = probsolve_ivp(f, t0, tmax, y0, step=step, adaptive=False)
def setUp(self): super().setUp() f = self.ivp.rhs t0, tmax = self.ivp.timespan y0 = self.ivp.initrv.mean self.solution = probsolve_ivp(f, t0, tmax, y0, algo_order=2, atol=0.1, rtol=0.1)
def setUp(self): initrv = Constant(0.1 * np.ones(1)) self.ivp = logistic([0.0, 1.5], initrv) step = 0.1 f = self.ivp.rhs t0, tmax = self.ivp.timespan y0 = self.ivp.initrv.mean self.solution = probsolve_ivp(f, t0, tmax, y0, algo_order=3, step=step, adaptive=False)
def setUp(self): initrv = Normal(20 * np.ones(2), 0.1 * np.eye(2), cov_cholesky=np.sqrt(0.1) * np.eye(2)) self.ivp = lotkavolterra([0.0, 0.5], initrv) step = 0.1 f = self.ivp.rhs t0, tmax = self.ivp.timespan y0 = self.ivp.initrv.mean self.solution = probsolve_ivp(f, t0, tmax, y0, step=step, adaptive=False)
def sol(ivp, step): f = ivp.f t0, tmax = ivp.t0, ivp.tmax y0 = ivp.y0 return diffeq.probsolve_ivp( f, t0, tmax, y0, method="ek0", algo_order=1, adaptive=False, step=step, diffusion_model="constant", dense_output=False, )
def test_adaptive_solver_successful( ivp, method, algo_order, dense_output, step, diffusion_model, tolerance, time_stops, ): """The solver terminates successfully for all sorts of parametrizations.""" f = ivp.f df = ivp.df t0, tmax = ivp.t0, ivp.tmax y0 = ivp.y0 sol = probsolve_ivp( f, t0, tmax, y0, df=df, adaptive=True, atol=tolerance, rtol=tolerance, algo_order=algo_order, method=method, dense_output=dense_output, step=step, time_stops=time_stops, ) # Successful return value as documented assert isinstance(sol, ODEFilterSolution) # Adaptive steps are not evenly distributed step_diff = np.diff(sol.locations) step_ratio = np.amin(step_diff) / np.amax(step_diff) assert step_ratio < 0.5 if time_stops is not None: for t in time_stops: assert t in sol.locations
def setUp(self): initrv = Constant(20 * np.ones(2)) self.ivp = lotkavolterra([0.0, 0.5], initrv) step = 0.1 self.solution = probsolve_ivp(self.ivp, which_prior="ibm3", step=step)
def setUp(self): initrv = Dirac(20 * np.ones(2)) self.ivp = lotkavolterra([0.0, 0.5], initrv) step = 0.1 self.solution = probsolve_ivp(self.ivp, step=step)
def setUp(self): super().setUp() self.solution = probsolve_ivp(self.ivp, which_prior="ibm2", atol=0.1, rtol=0.1)
def setUp(self): initrv = Constant(0.1 * np.ones(1)) self.ivp = logistic([0.0, 1.5], initrv) step = 0.1 self.solution = probsolve_ivp(self.ivp, which_prior="ibm3", step=step)