Skip to content

Commit

Permalink
setter for max_iter
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Zanelli committed Jun 13, 2024
1 parent d7d91dc commit 599d9d2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion interfaces/acados_template/acados_template/acados_ocp_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ def __init__(self, acados_ocp: Union[AcadosOcp, AcadosMultiphaseOcp], json_file=
self.time_solution_sens_solve = 0.0
self.time_solution_sens_lin = 0.0

# store nlp_solver_max_iter value
# (needed to raise a warning whenever max_iter is set to a higher value,
# since that could cause memory violations when writing to stats)
self.__nlp_solver_max_iter = self.solver_options['nlp_solver_max_iter']

# gettable fields
self.__qp_dynamics_fields = ['A', 'B', 'b']
self.__qp_cost_fields = ['Q', 'R', 'S', 'q', 'r']
Expand Down Expand Up @@ -1426,7 +1431,7 @@ def options_set(self, field_, value_):
- warm_start_first_qp: indicates if first QP in SQP is warm_started
"""
int_fields = ['print_level', 'rti_phase', 'initialize_t_slacks', 'qp_warm_start',
'line_search_use_sufficient_descent', 'full_step_dual', 'globalization_use_SOC', 'warm_start_first_qp', "as_rti_level"]
'line_search_use_sufficient_descent', 'full_step_dual', 'globalization_use_SOC', 'warm_start_first_qp', "as_rti_level", "max_iter"]
double_fields = ['step_length', 'tol_eq', 'tol_stat', 'tol_ineq', 'tol_comp', 'alpha_min', 'alpha_reduction',
'eps_sufficient_descent', 'qp_tol_stat', 'qp_tol_eq', 'qp_tol_ineq', 'qp_tol_comp', 'qp_tau_min', 'qp_mu0']
string_fields = ['globalization']
Expand Down Expand Up @@ -1455,6 +1460,11 @@ def options_set(self, field_, value_):
f' Possible values are {fields}.')


if field_ == 'max_iter' and value_ > self.__nlp_solver_max_iter:
print('Warning: AcadosOcpSolver.options_set() cannot increase nlp_solver_max_iter' \
f' above initial value {self.__nlp_solver_max_iter} (you have {value_})')
return

if field_ == 'rti_phase':
if value_ < 0 or value_ > 2:
raise Exception('AcadosOcpSolver.options_set(): argument \'rti_phase\' can '
Expand Down

0 comments on commit 599d9d2

Please sign in to comment.