def test_control_solution_variations(): """Test different variations of control solutions.""" m = load_example_standard_model('VDP_pack_VDP_Opt', 'VDP.mo', 'VDP_pack.VDP_Opt') m.reset() grid = [(0, 0.1), (0.1, 0.2), (0.2, 0.3), (0.3, 0.4), (0.4, 0.5), (0.5, 0.6), (0.6, 0.7), (0.7, 0.8), (0.8, 0.9), (0.9, 1.0),] start_time = m.opt_interval_get_start_time() final_time = m.opt_interval_get_final_time() grid = N.array(grid) * (final_time - start_time) + start_time for u in [-0.5, -0.25, 0, 0.25, 0.5]: print "u:", u us = [ -1.86750972e+00, -1.19613740e+00, 3.21955502e+01, 1.15871750e+00, -9.56876370e-01, 7.82651050e+01, -3.35655693e-01, 1.95491165e+00, 1.47923425e+02, -2.32963068e+00, -1.65371763e-01, 1.94340923e+02, 6.82953492e-01, -1.57360749e+00, 2.66717232e+02, 1.46549806e+00, 1.74702679e+00, 3.29995167e+02, -1.19712096e+00, 9.57726717e-01, 3.80947471e+02, 3.54379487e-01, -1.95842811e+00, 4.52105868e+02, 2.34170339e+00, 1.77754406e-01, 4.98700011e+02] + [u] * 10 us = N.array(us) plot_control_solutions(m, grid, us, doshow=False)
def test_plot_control_solutions(): """Testing plot_control_solutions(...).""" m = load_example_standard_model('VDP_pack_VDP_Opt', 'VDP.mo', 'VDP_pack.VDP_Opt') m.reset() grid = [(0, 0.1), (0.1, 0.2), (0.2, 0.3), (0.3, 0.4), (0.4, 0.5), (0.5, 0.6), (0.6, 0.7), (0.7, 0.8), (0.8, 0.9), (0.9, 1.0),] grid = N.array(grid) * (m.opt_interval_get_final_time() - m.opt_interval_get_start_time()) + \ m.opt_interval_get_start_time() # Used to be: N.array([1, 1, 1, 1]*len(grid)) us = [ -1.86750972e+00, -1.19613740e+00, 3.21955502e+01, 1.15871750e+00, -9.56876370e-01, 7.82651050e+01, -3.35655693e-01, 1.95491165e+00, 1.47923425e+02, -2.32963068e+00, -1.65371763e-01, 1.94340923e+02, 6.82953492e-01, -1.57360749e+00, 2.66717232e+02, 1.46549806e+00, 1.74702679e+00, 3.29995167e+02, -1.19712096e+00, 9.57726717e-01, 3.80947471e+02, 3.54379487e-01, -1.95842811e+00, 4.52105868e+02, 2.34170339e+00, 1.77754406e-01, 4.98700011e+02, 2.50000000e-01, 2.50000000e-01, 2.50000000e-01, 2.50000000e-01, 2.50000000e-01, 1.36333570e-01, 2.50000000e-01, 2.50000000e-01, 2.50000000e-01, 2.50000000e-01] us = N.array(us) plot_control_solutions(m, grid, us, doshow=False)
def setUp(self): DLLFILE = 'VDP_pack_VDP_Opt' MODELICA_FILE = 'VDP.mo' MODEL_PACKAGE = 'VDP_pack.VDP_Opt' model = load_example_standard_model(DLLFILE, MODELICA_FILE, MODEL_PACKAGE) self._model = model
def test_set_get_model(self): """Test the model setter/getter.""" simulator = self.simulator assert simulator.get_model() == self.m another_model = load_example_standard_model('VDP_pack_VDP_Opt', 'VDP.mo', 'VDP_pack.VDP_Opt') simulator.set_model(another_model) assert simulator.get_model() == another_model nose.tools.assert_raises(sundials.SundialsSimulationException, simulator.set_model, None) another_model = load_example_standard_model('VDP_pack_VDP_Opt', 'VDP.mo', 'VDP_pack.VDP_Opt') simulator.model = another_model # testing property assert another_model == simulator.get_model()
def setUp(self): DLLFILE = 'VDP_pack_VDP_Opt' MODELICA_FILE = 'VDP.mo' MODEL_PACKAGE = 'VDP_pack.VDP_Opt' model = load_example_standard_model(DLLFILE, MODELICA_FILE, MODEL_PACKAGE) GRIDSIZE = 10 shooter = _lazy_init_shooter(model, GRIDSIZE) p0 = shooter.get_p0() self._shooter = shooter self._p0 = p0
def test_f_gradient_elements(certainindex=None): """Basic testing of gradients (disabled by default). This tests takes slightly less than an hour to run on my computer unless certainindex is defined (whereas only the element of index certainindex will be tested). Therefor it is turned off by default. Set run_huge_test variable to True to run this test by default. Also note that this test is not really supposed to test functionality per se. It is rather a test that can be used to visually verify that gradients behave the way they are expected to. """ run_huge_test = False if run_huge_test is False and certainindex is None: return m = load_example_standard_model('VDP_pack_VDP_Opt', 'VDP.mo', 'VDP_pack.VDP_Opt') grid = [(0, 0.1), (0.1, 0.2), (0.2, 0.3), (0.3, 0.4), (0.4, 0.5), (0.5, 0.6), (0.6, 0.7), (0.7, 0.8), (0.8, 0.9), (0.9, 1.0),] initial_u = [0.25] * len(grid) shooter = MultipleShooter(m, initial_u, grid) p0 = shooter.get_p0() if certainindex is not None: indices = [certainindex] else: indices = range(len(p0)) for index in indices: fig = p.figure() evaluator = _PartialEvaluator(shooter.f, shooter.df, p0, index) p.suptitle('Partial derivative test (of gradient elements, index=%s)' % index) _verify_gradient(evaluator.f, evaluator.df, -10, 10) fig.savefig('test_f_gradient_elements_%s.png' % index) fig.savefig('test_f_gradient_elements_%s.eps' % index)
def setUp(self): """Load the test model.""" self.m = load_example_standard_model('VDP_pack_VDP_Opt', 'VDP.mo', 'VDP_pack.VDP_Opt') self.simulator = SundialsOdeSimulator(self.m)
def setUp(self): """Test setUp. Load the test model.""" self.m = load_example_standard_model('VDP_pack_VDP_Opt', 'VDP.mo', 'VDP_pack.VDP_Opt')