def test_baseline_run(): from pandemic.models.SEIRDS import SEIRDS, states, params, s_params, ns, t_duration_bounds, t_initial_bounds # test baseline model p, phase0, traj = generate_phase(SEIRDS, ns, states, params, s_params, t_initial_bounds, t_duration_bounds, fix_initial=True) p.driver = om.pyOptSparseDriver() p.driver.options['optimizer'] = 'IPOPT' p.driver.options['print_results'] = False p.driver.opt_settings['hessian_approximation'] = 'limited-memory' # p.driver.opt_settings['mu_init'] = 1.0E-2 p.driver.opt_settings['nlp_scaling_method'] = 'gradient-based' p.driver.opt_settings['print_level'] = 5 p.driver.opt_settings['linear_solver'] = 'mumps' p.driver.opt_settings['max_iter'] = 500 phase0.add_boundary_constraint('I', loc='final', upper=0.01, scaler=1.0) phase0.add_objective('time', loc='final', scaler=1.0) phase0.add_timeseries_output('theta') setup_and_run_phase(states, p, phase0, traj, t_duration_bounds[0]) max_I = np.max(states['I']['result']) final_R = states['R']['result'][-1] final_S = states['S']['result'][-1] final_D = states['D']['result'][-1] print("max_I", max_I) print("final_R", final_R) print("final_S", final_S) print("final_D", final_D) mI_actual = 0.26364939220443845 fR_actual = 0.66815968 fS_actual = 0.26927833 fD_actual = 0.05378587 tol = 1e-2 assert (abs(max_I - mI_actual) / mI_actual) < tol assert (abs(final_R - fR_actual) / fR_actual) < tol assert (abs(final_S - fS_actual) / fS_actual) < tol assert (abs(final_D - fD_actual) / fD_actual) < tol return states, params
def test_baseline_run(): ns = 35 t_initial_bounds = [0.0, 1.0] t_duration_bounds = [200.0, 301.00] from pandemic.models.SIR import SIR, states, params, s_params p, phase0, traj = generate_phase(SIR, ns, states, params, s_params, t_initial_bounds, t_duration_bounds, fix_initial=True) p.driver = om.pyOptSparseDriver() p.driver.options['optimizer'] = 'IPOPT' p.driver.options['print_results'] = False p.driver.opt_settings['hessian_approximation'] = 'limited-memory' # p.driver.opt_settings['mu_init'] = 1.0E-2 p.driver.opt_settings['nlp_scaling_method'] = 'gradient-based' p.driver.opt_settings['print_level'] = 5 p.driver.opt_settings['linear_solver'] = 'mumps' p.driver.opt_settings['max_iter'] = 500 phase0.add_boundary_constraint('I', loc='final', upper=0.05, scaler=1.0) phase0.add_objective('time', loc='final', scaler=1.0) phase0.add_timeseries_output('theta') setup_and_run_phase(states, p, phase0, traj, t_duration_bounds[0]) max_I = np.max(states['I']['result']) final_S = states['S']['result'][-1] print("max_I", max_I) print("final_S", final_S) err = abs(max_I - 0.3592) / 0.3592 assert (err < 1e4) return states, params
# set up model states for state in states: states[state]['ds'] = ds params['beta']['val'] = beta params['alpha']['val'] = alpha params['gamma']['val'] = gamma params['epsilon']['val'] = epsilon params['mu']['val'] = mu t_initial_bounds = [0.0, 1.0] t_duration_bounds = [200.0, 301.00] p, phase0, traj = generate_phase(SEIRDS, ns, states, params, s_params, t_initial_bounds, t_duration_bounds, fix_initial=True, fix_duration=True) p.driver = om.pyOptSparseDriver() p.driver.options['optimizer'] = 'IPOPT' p.driver.options['print_results'] = False p.driver.opt_settings['hessian_approximation'] = 'limited-memory' # p.driver.opt_settings['mu_init'] = 1.0E-2 p.driver.opt_settings['nlp_scaling_method'] = 'gradient-based' p.driver.opt_settings['print_level'] = 5 p.driver.opt_settings['linear_solver'] = 'mumps' p.driver.opt_settings['max_iter'] = 500 phase0.add_boundary_constraint('I', loc='final', upper=0.01, scaler=1.0)