Skip to content

Commit

Permalink
Merge pull request #102 from lbl-srg/issue101_setOptOptions
Browse files Browse the repository at this point in the history
Issue101 set opt options
  • Loading branch information
dhblum authored Dec 18, 2017
2 parents 33993d2 + a3d58b7 commit 1df4d00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion mpcpy/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ def _set_optimization_options(self, opt_options, init = False):
if opt_options[key] != self.opt_options[key]:
self._step_from_meas = False;
# Set options
self.opt_options = opt_options;
self.opt_options = copy.deepcopy(opt_options);

def _get_optimization_statistics(self):
'''Get the JModelica optimization result statistics.
Expand Down
18 changes: 7 additions & 11 deletions unittests/test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,13 @@ def test_set_options_error(self):
optimization.JModelica, \
'q_flow', \
constraint_data = self.constraints.data);
# Get initial options
opt_options = opt_problem.get_optimization_options();
# Set new options
opt_options['n_e'] = 2;
self.assertRaises(KeyError, opt_problem.set_optimization_options(opt_options));
opt_options['external_data'] = 2;
self.assertRaises(KeyError, opt_problem.set_optimization_options(opt_options));
opt_options['init_traj'] = 2;
self.assertRaises(KeyError, opt_problem.set_optimization_options(opt_options));
opt_options['nominal_traj'] = 2;
self.assertRaises(KeyError, opt_problem.set_optimization_options(opt_options));
for key in ['external_data', 'init_traj', 'nominal_traj']:
# Get initial options
opt_options = opt_problem.get_optimization_options();
# Set new options and check KeyError raised
with self.assertRaises(KeyError):
opt_options[key] = 2;
opt_problem.set_optimization_options(opt_options);

def test_get_statistics(self):
'''Test the getting of optimization result statistics.
Expand Down

0 comments on commit 1df4d00

Please sign in to comment.