8000 Python verbosity by FreyJo · Pull Request #1501 · acados/acados · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Python verbosity #1501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def set_phase(self, ocp: AcadosOcp, phase_idx: int) -> None:

return

def make_consistent(self) -> None:
def make_consistent(self, verbose: bool = True) -> None:

self.N_horizon = sum(self.N_list)
self.solver_options.N_horizon = self.N_horizon # NOTE: to not change options when making ocp consistent
Expand Down Expand Up @@ -330,7 +330,7 @@ def make_consistent(self) -> None:
print(f"Phase {i} contains non-default initial fields: {nondefault_fields}, which will be ignored.")

print(f"Calling make_consistent for phase {i}.")
ocp.make_consistent(is_mocp_phase=True)
ocp.make_consistent(is_mocp_phase=True, verbose=verbose)

self.dummy_ocp_list.append(ocp)

Expand Down
37 changes: 19 additions & 18 deletions interfaces/acados_template/acados_template/acados_ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ def _make_consistent_simulation(self):
raise ValueError("Wrong value for sim_method_jac_reuse. Should be either int or array of ints of shape (N,).")


def make_consistent(self, is_mocp_phase=False) -> None:
def make_consistent(self, is_mocp_phase: bool=False, verbose: bool=True) -> None:
"""
Detect dimensions, perform sanity checks
"""
Expand Down Expand Up @@ -941,23 +941,24 @@ def make_consistent(self, is_mocp_phase=False) -> None:
self._make_consistent_cost_terminal()

# GN check
gn_warning_0 = (opts.N_horizon > 0 and cost.cost_type_0 == 'EXTERNAL' and opts.hessian_approx == 'GAUSS_NEWTON' and opts.ext_cost_num_hess == 0 and is_empty(model.cost_expr_ext_cost_custom_hess_0))
gn_warning_path = (opts.N_horizon > 0 and cost.cost_type == 'EXTERNAL' and opts.hessian_approx == 'GAUSS_NEWTON' and opts.ext_cost_num_hess == 0 and is_empty(model.cost_expr_ext_cost_custom_hess))
gn_warning_terminal = (cost.cost_type_e == 'EXTERNAL' and opts.hessian_approx == 'GAUSS_NEWTON' and opts.ext_cost_num_hess == 0 and is_empty(model.cost_expr_ext_cost_custom_hess_e))
if any([gn_warning_0, gn_warning_path, gn_warning_terminal]):
external_cost_types = []
if gn_warning_0:
external_cost_types.append('cost_type_0')
if gn_warning_path:
external_cost_types.append('cost_type')
if gn_warning_terminal:
external_cost_types.append('cost_type_e')
print("\nWARNING: Gauss-Newton Hessian approximation with EXTERNAL cost type not well defined!\n"
f"got cost_type EXTERNAL for {', '.join(external_cost_types)}, hessian_approx: 'GAUSS_NEWTON'.\n"
"With this setting, acados will proceed computing the exact Hessian for the cost term and no Hessian contribution from constraints and dynamics.\n"
"If the external cost is a linear least squares cost, this coincides with the Gauss-Newton Hessian.\n"
"Note: There is also the option to use the external cost module with a numerical Hessian approximation (see `ext_cost_num_hess`).\n"
"OR the option to provide a symbolic custom Hessian approximation (see `cost_expr_ext_cost_custom_hess`).\n")
if verbose:
gn_warning_0 = (opts.N_horizon > 0 and cost.cost_type_0 == 'EXTERNAL' and opts.hessian_approx == 'GAUSS_NEWTON' and opts.ext_cost_num_hess == 0 and is_empty(model.cost_expr_ext_cost_custom_hess_0))
gn_warning_path = (opts.N_horizon > 0 and cost.cost_type == 'EXTERNAL' and opts.hessian_approx == 'GAUSS_NEWTON' and opts.ext_cost_num_hess == 0 and is_empty(model.cost_expr_ext_cost_custom_hess))
gn_warning_terminal = (cost.cost_type_e == 'EXTERNAL' and opts.hessian_approx == 'GAUSS_NEWTON' and opts.ext_cost_num_hess == 0 and is_empty(model.cost_expr_ext_cost_custom_hess_e))
if any([gn_warning_0, gn_warning_path, gn_warning_terminal]):
external_cost_types = []
if gn_warning_0:
external_cost_types.append('cost_type_0')
if gn_warning_path:
external_cost_types.append('cost_type')
if gn_warning_terminal:
external_cost_types.append('cost_type_e')
print("\nWARNING: Gauss-Newton Hessian approximation with EXTERNAL cost type not well defined!\n"
f"got cost_type EXTERNAL for {', '.join(external_cost_types)}, hessian_approx: 'GAUSS_NEWTON'.\n"
"With this setting, acados will proceed computing the exact Hessian for the cost term and no Hessian contribution from constraints and dynamics.\n"
"If the external cost is a linear least squares cost, this coincides with the Gauss-Newton Hessian.\n"
"Note: There is also the option to use the external cost module with a numerical Hessian approximation (see `ext_cost_num_hess`).\n"
"OR the option to provide a symbolic custom Hessian approximation (see `cost_expr_ext_cost_custom_hess`).\n")

# cost integration
if opts.N_horizon > 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def __init__(self, ocp: AcadosOcp, N_batch_max: int,
json_file=json_file,
build=n==0 if build else False,
generate=n==0 if generate else False,
verbose=verbose)
verbose=verbose if n==0 else False,
)
for n in range(self.N_batch_max)]

self.__shared_lib = self.ocp_solvers[0].shared_lib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def shared_lib(self,):
return self.__shared_lib

@classmethod
def generate(cls, acados_ocp: Union[AcadosOcp, AcadosMultiphaseOcp], json_file: str, simulink_opts=None, cmake_builder: CMakeBuilder = None):
def generate(cls, acados_ocp: Union[AcadosOcp, AcadosMultiphaseOcp], json_file: str, simulink_opts=None, cmake_builder: CMakeBuilder = None, verbose=True):
"""
Generates the code for an acados OCP solver, given the description in acados_ocp.
:param acados_ocp: type Union[AcadosOcp, AcadosMultiphaseOcp] - description of the OCP for acados
Expand All @@ -100,6 +100,7 @@ def generate(cls, acados_ocp: Union[AcadosOcp, AcadosMultiphaseOcp], json_file:
:param cmake_builder: type :py:class:`~acados_template.builders.CMakeBuilder` generate a `CMakeLists.txt` and use
the `CMake` pipeline instead of a `Makefile` (`CMake` seems to be the better option in conjunction with
`MS Visual Studio`); default: `None`
:param verbose: indicating if warnings are printed
"""
acados_ocp.code_export_directory = os.path.abspath(acados_ocp.code_export_directory)

Expand All @@ -112,7 +113,7 @@ def generate(cls, acados_ocp: Union[AcadosOcp, AcadosMultiphaseOcp], json_file:
acados_ocp.simulink_opts = simulink_opts

# make consistent
acados_ocp.make_consistent()
acados_ocp.make_consistent(verbose=verbose)

# module dependent post processing
if acados_ocp.solver_options.integrator_type == 'GNSF':
Expand Down Expand Up @@ -225,11 +226,11 @@ def __init__(self, acados_ocp: Union[AcadosOcp, AcadosMultiphaseOcp, None], json
if generate:
if json_file is not None:
acados_ocp.json_file = json_file
self.generate(acados_ocp, json_file=acados_ocp.json_file, simulink_opts=simulink_opts, cmake_builder=cmake_builder)
self.generate(acados_ocp, json_file=acados_ocp.json_file, simulink_opts=simulink_opts, cmake_builder=cmake_builder, verbose=verbose)
json_file = acados_ocp.json_file
else:
if acados_ocp is not None:
acados_ocp.make_consistent()
acados_ocp.make_consistent(verbose=verbose)

# load json, store options in object
with open(json_file, 'r') as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def __init__(self, sim: AcadosSim, N_batch: int, num_threads_in_batch_solve: Uni
json_file=json_file,
build=n==0 if build else False,
generate=n==0 if generate else False,
verbose=verbose)
verbose=verbose if n==0 else False,
)
for n in range(self.N_batch)]

self.__shared_lib = self.sim_solvers[0].shared_lib
Expand Down
Loading
0