From c0b3f8ea3534f6c53884393a25f7f73a32f06752 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 28 Nov 2026 12:18:58 -0600 Subject: [PATCH] long mpc: add acados solver type stub so it type checks without a build (#39502) --- .../acados_ocp_solver_pyx.pyi | 27 +++++++++++++++++++ .../lib/longitudinal_mpc_lib/long_mpc.py | 3 +++ 2 files changed, 30 insertions(+) create mode 100644 openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/acados_ocp_solver_pyx.pyi diff --git a/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/acados_ocp_solver_pyx.pyi b/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/acados_ocp_solver_pyx.pyi new file mode 100644 index 0000000000..d0e7ffa359 --- /dev/null +++ b/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/acados_ocp_solver_pyx.pyi @@ -0,0 +1,27 @@ +# acados_template's Cython solver, compiled against c_generated_code by the SConscript +from typing import Any + +import numpy as np + +class AcadosOcpSolverCython: + def __init__(self, model_name: str, nlp_solver_type: str, N: int) -> None: ... + def solve_for_x0(self, x0_bar: np.ndarray) -> np.ndarray: ... + def solve(self) -> int: ... + def reset(self, reset_qp_solver_mem: int = 1) -> int: ... + def custom_update(self, data_: np.ndarray) -> int: ... + def set_new_time_steps(self, new_time_steps: np.ndarray) -> None: ... + def update_qp_solver_cond_N(self, qp_solver_cond_N: int) -> None: ... + def eval_param_sens(self, index: int, stage: int = 0, field: str = "ex") -> None: ... + def get(self, stage: int, field_: str) -> np.ndarray: ... + def print_statistics(self) -> None: ... + def store_iterate(self, filename: str = '', overwrite: bool = False) -> None: ... + def load_iterate(self, filename: str) -> None: ... + def get_stats(self, field_: str) -> Any: ... + def get_cost(self) -> float: ... + def get_residuals(self, recompute: bool = False) -> np.ndarray: ... + def set(self, stage: int, field_: str, value_: Any) -> None: ... + def cost_set(self, stage: int, field_: str, value_: Any) -> None: ... + def constraints_set(self, stage: int, field_: str, value_: Any) -> None: ... + def get_from_qp_in(self, stage: int, field_: str) -> np.ndarray: ... + def options_set(self, field_: str, value_: Any) -> None: ... + def set_params_sparse(self, stage: int, idx_values_: np.ndarray, param_values_: np.ndarray) -> None: ... diff --git a/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py b/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py index ad19ddebae..d9803b1cf7 100755 --- a/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py +++ b/openpilot/selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py @@ -3,6 +3,7 @@ import os import time import math from dataclasses import dataclass +from typing import TYPE_CHECKING import numpy as np from openpilot.cereal import log from opendbc.car.interfaces import ACCEL_MIN, ACCEL_MAX @@ -15,6 +16,8 @@ from openpilot.selfdrive.controls.radard import _LEAD_ACCEL_TAU, RADAR_TO_CAMERA if __name__ == '__main__': # generating code from acados.acados_template import AcadosModel, AcadosOcp, AcadosOcpSolver +elif TYPE_CHECKING: + from openpilot.selfdrive.controls.lib.longitudinal_mpc_lib.acados_ocp_solver_pyx import AcadosOcpSolverCython else: from openpilot.selfdrive.controls.lib.longitudinal_mpc_lib.c_generated_code.acados_ocp_solver_pyx import AcadosOcpSolverCython