From 587d6783c41b294040f381dea960bd768830acf5 Mon Sep 17 00:00:00 2001 From: Alpha Date: Thu, 9 Nov 2023 09:48:25 +0000 Subject: [PATCH 1/2] #746 Issue Fixed --- .../arm_reaching_muscle_driven.py | 4 +- .../arm_reaching_torque_driven_explicit.py | 2 +- bioptim/limits/constraints.py | 46 +++++++++---------- bioptim/limits/multinode_penalty.py | 10 ++-- bioptim/limits/objective_functions.py | 12 ++--- bioptim/limits/penalty.py | 32 ++++++------- bioptim/limits/penalty_controller.py | 2 +- bioptim/limits/penalty_option.py | 30 ++++++------ .../variational_optimal_control_program.py | 24 +++++----- 9 files changed, 81 insertions(+), 81 deletions(-) diff --git a/bioptim/examples/stochastic_optimal_control/arm_reaching_muscle_driven.py b/bioptim/examples/stochastic_optimal_control/arm_reaching_muscle_driven.py index 51d8f2643..cf6191953 100644 --- a/bioptim/examples/stochastic_optimal_control/arm_reaching_muscle_driven.py +++ b/bioptim/examples/stochastic_optimal_control/arm_reaching_muscle_driven.py @@ -298,7 +298,7 @@ def expected_feedback_effort(controllers: list[PenaltyController], sensory_noise controllers[0].controls.cx_start, controllers[0].parameters.cx_start, controllers[0].stochastic_variables.cx_start, - controllers[0].get_nlp, + controllers[0].nlp, ) trace_k_sensor_k = cas.trace(k_matrix @ sensory_noise_matrix @ k_matrix.T) e_fb = k_matrix @ ((hand_pos_velo - ref) + sensory_noise_magnitude) @@ -329,7 +329,7 @@ def zero_acceleration(controller: PenaltyController, force_field_magnitude: floa controller.controls.cx_start, controller.parameters.cx_start, controller.stochastic_variables.cx_start, - controller.get_nlp, + controller.nlp, force_field_magnitude=force_field_magnitude, with_noise=False, ) diff --git a/bioptim/examples/stochastic_optimal_control/arm_reaching_torque_driven_explicit.py b/bioptim/examples/stochastic_optimal_control/arm_reaching_torque_driven_explicit.py index 47d62237c..880b32d82 100644 --- a/bioptim/examples/stochastic_optimal_control/arm_reaching_torque_driven_explicit.py +++ b/bioptim/examples/stochastic_optimal_control/arm_reaching_torque_driven_explicit.py @@ -299,7 +299,7 @@ def expected_feedback_effort(controllers: list[PenaltyController]) -> cas.MX: controllers[0].controls.cx_start, controllers[0].parameters.cx_start, controllers[0].stochastic_variables.cx_start, - controllers[0].get_nlp, + controllers[0].nlp, ) e_fb = k_matrix @ ((estimated_ref - ref) + controllers[0].model.sensory_noise_magnitude) jac_e_fb_x = cas.jacobian(e_fb, controllers[0].states.cx_start) diff --git a/bioptim/limits/constraints.py b/bioptim/limits/constraints.py index 5d3965aea..d25bcf585 100644 --- a/bioptim/limits/constraints.py +++ b/bioptim/limits/constraints.py @@ -123,18 +123,18 @@ def _add_penalty_to_pool(self, controller: PenaltyController): if self.penalty_type == PenaltyType.INTERNAL: pool = ( - controller.get_nlp.g_internal - if controller is not None and controller.get_nlp + controller.nlp.g_internal + if controller is not None and controller.nlp else controller.ocp.g_internal ) elif self.penalty_type == ConstraintType.IMPLICIT: pool = ( - controller.get_nlp.g_implicit - if controller is not None and controller.get_nlp + controller.nlp.g_implicit + if controller is not None and controller.nlp else controller.ocp.g_implicit ) elif self.penalty_type == PenaltyType.USER: - pool = controller.get_nlp.g if controller is not None and controller.get_nlp else controller.ocp.g + pool = controller.nlp.g if controller is not None and controller.nlp else controller.ocp.g else: raise ValueError(f"Invalid constraint type {self.penalty_type}.") pool[self.list_index] = self @@ -267,7 +267,7 @@ def non_slipping( constraint.min_bound = np.array([0, 0]) constraint.max_bound = np.array([np.inf, np.inf]) - contact = controller.get_nlp.contact_forces_func( + contact = controller.nlp.contact_forces_func( controller.time.cx, controller.states.cx_start, controller.controls.cx_start, @@ -338,7 +338,7 @@ def torque_max_from_q_and_qdot( n_rows = value.shape[0] // 2 else: if ( - controller.get_nlp.phase_dynamics == PhaseDynamics.ONE_PER_NODE + controller.nlp.phase_dynamics == PhaseDynamics.ONE_PER_NODE and not isinstance(constraint.rows, int) and len(constraint.rows) == value.shape[0] ): @@ -461,7 +461,7 @@ def tau_equals_inverse_dynamics( tau = tau + passive_torque if with_passive_torque else tau tau = tau + controller.model.ligament_joint_torque(q, qdot) if with_ligament else tau - if controller.get_nlp.external_forces: + if controller.nlp.external_forces: raise NotImplementedError( "This implicit constraint tau_equals_inverse_dynamics is not implemented yet with external forces" ) @@ -554,7 +554,7 @@ def tau_from_muscle_equal_inverse_dynamics( muscle_tau = muscle_tau + controller.model.ligament_joint_torque(q, qdot) if with_ligament else muscle_tau qddot = controller.states["qddot"].mx if "qddot" in controller.states else controller.controls["qddot"].mx - if controller.get_nlp.external_forces: + if controller.nlp.external_forces: raise NotImplementedError( "This implicit constraint tau_from_muscle_equal_inverse_dynamics is not implemented yet with external forces" ) @@ -591,7 +591,7 @@ def implicit_soft_contact_forces(_: Constraint, controller: PenaltyController, * force_idx.append(4 + (6 * i_sc)) force_idx.append(5 + (6 * i_sc)) - soft_contact_all = controller.get_nlp.soft_contact_forces_func( + soft_contact_all = controller.nlp.soft_contact_forces_func( controller.states.mx, controller.controls.mx, controller.parameters.mx ) soft_contact_force = soft_contact_all[force_idx] @@ -615,7 +615,7 @@ def stochastic_covariance_matrix_continuity_implicit( """ # TODO: Charbie -> This is only True for x=[q, qdot], u=[tau] (have to think on how to generalize it) - if not controller.get_nlp.is_stochastic: + if not controller.nlp.is_stochastic: raise RuntimeError("This function is only valid for stochastic problems") if "cholesky_cov" in controller.stochastic_variables.keys(): @@ -650,7 +650,7 @@ def stochastic_covariance_matrix_continuity_implicit( cov_implicit_deffect = cov_next - cov_matrix penalty.expand = ( - controller.get_nlp.dynamics_type.expand_dynamics + controller.nlp.dynamics_type.expand_dynamics ) # TODO: Charbie -> should this be always true? penalty.explicit_derivative = True penalty.multi_thread = True @@ -667,7 +667,7 @@ def stochastic_df_dx_implicit( This function constrains the stochastic matrix A to its actual value which is A = df/dx """ - if not controller.get_nlp.is_stochastic: + if not controller.nlp.is_stochastic: raise RuntimeError("This function is only valid for stochastic problems") dt = controller.tf / controller.ns @@ -746,10 +746,10 @@ def stochastic_helper_matrix_collocation( and G = collocation slope constraints (defects). """ - if not controller.get_nlp.is_stochastic: + if not controller.nlp.is_stochastic: raise RuntimeError("This function is only valid for stochastic problems") - polynomial_degree = controller.get_nlp.ode_solver.polynomial_degree + polynomial_degree = controller.nlp.ode_solver.polynomial_degree Mc, _ = ConstraintFunction.Functions.collocation_jacobians( penalty, controller, @@ -790,10 +790,10 @@ def stochastic_covariance_matrix_continuity_collocation( """ # TODO: Charbie -> This is only True for x=[q, qdot], u=[tau] (have to think on how to generalize it) - if not controller.get_nlp.is_stochastic: + if not controller.nlp.is_stochastic: raise RuntimeError("This function is only valid for stochastic problems") - polynomial_degree = controller.get_nlp.ode_solver.polynomial_degree + polynomial_degree = controller.nlp.ode_solver.polynomial_degree _, Pf = ConstraintFunction.Functions.collocation_jacobians( penalty, controller, @@ -847,7 +847,7 @@ def stochastic_mean_sensory_input_equals_reference( controls=controller.controls.cx_start, parameters=controller.parameters.cx_start, stochastic_variables=controller.stochastic_variables.cx_start, - nlp=controller.get_nlp, + nlp=controller.nlp, ) return sensory_input - ref @@ -1176,18 +1176,18 @@ def _add_penalty_to_pool(self, controller: PenaltyController): if self.penalty_type == PenaltyType.INTERNAL: pool = ( - controller.get_nlp.g_internal - if controller is not None and controller.get_nlp + controller.nlp.g_internal + if controller is not None and controller.nlp else controller.ocp.g_internal ) elif self.penalty_type == ConstraintType.IMPLICIT: pool = ( - controller.get_nlp.g_implicit - if controller is not None and controller.get_nlp + controller.nlp.g_implicit + if controller is not None and controller.nlp else controller.ocp.g_implicit ) elif self.penalty_type == PenaltyType.USER: - pool = controller.get_nlp.g if controller is not None and controller.get_nlp else controller.ocp.g + pool = controller.nlp.g if controller is not None and controller.nlp else controller.ocp.g else: raise ValueError(f"Invalid constraint type {self.penalty_type}.") pool[self.list_index] = self diff --git a/bioptim/limits/multinode_penalty.py b/bioptim/limits/multinode_penalty.py index b82f42a46..389e5f0b5 100644 --- a/bioptim/limits/multinode_penalty.py +++ b/bioptim/limits/multinode_penalty.py @@ -84,7 +84,7 @@ def _add_penalty_to_pool(self, controller: list[PenaltyController, PenaltyContro ) ocp = controller[0].ocp - nlp = controller[0].get_nlp + nlp = controller[0].nlp pool = self._get_pool_to_add_penalty(ocp, nlp) pool[self.list_index] = self @@ -378,7 +378,7 @@ def stochastic_helper_matrix_explicit( controllers: list[PenaltyController, PenaltyController] """ - if not controllers[0].get_nlp.is_stochastic: + if not controllers[0].nlp.is_stochastic: raise RuntimeError("This function is only valid for stochastic problems") if controllers[0].phase_idx != controllers[1].phase_idx: raise RuntimeError("For this constraint to make sens, the two nodes must belong to the same phase.") @@ -447,7 +447,7 @@ def stochastic_helper_matrix_implicit( controllers: list[PenaltyController, PenaltyController] The penalty node elements """ - if not controllers[0].get_nlp.is_stochastic: + if not controllers[0].nlp.is_stochastic: raise RuntimeError("This function is only valid for stochastic problems") if controllers[0].phase_idx != controllers[1].phase_idx: raise RuntimeError("For this constraint to make sens, the two nodes must belong to the same phase.") @@ -481,7 +481,7 @@ def stochastic_covariance_matrix_continuity_implicit( """ # TODO: Charbie -> This is only True for x=[q, qdot], u=[tau] (have to think on how to generalize it) - if not controllers[0].get_nlp.is_stochastic: + if not controllers[0].nlp.is_stochastic: raise RuntimeError("This function is only valid for stochastic problems") cov_matrix = StochasticBioModel.reshape_to_matrix( @@ -522,7 +522,7 @@ def stochastic_df_dw_implicit( """ # TODO: Charbie -> This is only True for x=[q, qdot], u=[tau] (have to think on how to generalize it) - if not controllers[0].get_nlp.is_stochastic: + if not controllers[0].nlp.is_stochastic: raise RuntimeError("This function is only valid for stochastic problems") dt = controllers[0].tf / controllers[0].ns diff --git a/bioptim/limits/objective_functions.py b/bioptim/limits/objective_functions.py index 04e59b83c..5890b0a78 100644 --- a/bioptim/limits/objective_functions.py +++ b/bioptim/limits/objective_functions.py @@ -83,12 +83,12 @@ def _add_penalty_to_pool(self, controller: PenaltyController): if self.penalty_type == PenaltyType.INTERNAL: pool = ( - controller.get_nlp.J_internal - if controller is not None and controller.get_nlp + controller.nlp.J_internal + if controller is not None and controller.nlp else controller.ocp.J_internal ) elif self.penalty_type == PenaltyType.USER: - pool = controller.get_nlp.J if controller is not None and controller.get_nlp else controller.ocp.J + pool = controller.nlp.J if controller is not None and controller.nlp else controller.ocp.J else: raise ValueError(f"Invalid objective type {self.penalty_type}.") pool[self.list_index] = self @@ -492,12 +492,12 @@ def _add_penalty_to_pool(self, controller: PenaltyController): if self.penalty_type == PenaltyType.INTERNAL: pool = ( - controller.get_nlp.J_internal - if controller is not None and controller.get_nlp + controller.nlp.J_internal + if controller is not None and controller.nlp else controller.ocp.J_internal ) elif self.penalty_type == PenaltyType.USER: - pool = controller.get_nlp.J if controller is not None and controller.get_nlp else controller.ocp.J + pool = controller.nlp.J if controller is not None and controller.nlp else controller.ocp.J else: raise ValueError(f"Invalid objective type {self.penalty_type}.") pool[self.list_index] = self diff --git a/bioptim/limits/penalty.py b/bioptim/limits/penalty.py index afeba62a9..948a28a66 100644 --- a/bioptim/limits/penalty.py +++ b/bioptim/limits/penalty.py @@ -87,12 +87,12 @@ def minimize_controls(penalty: PenaltyOption, controller: PenaltyController, key """ penalty.quadratic = True if penalty.quadratic is None else penalty.quadratic - if key in controller.get_nlp.variable_mappings: - target_mapping = controller.get_nlp.variable_mappings[key] + if key in controller.nlp.variable_mappings: + target_mapping = controller.nlp.variable_mappings[key] else: target_mapping = BiMapping( - to_first=list(range(controller.get_nlp.controls[key].cx_start.shape[0])), - to_second=list(range(controller.get_nlp.controls[key].cx_start.shape[0])), + to_first=list(range(controller.nlp.controls[key].cx_start.shape[0])), + to_second=list(range(controller.nlp.controls[key].cx_start.shape[0])), ) # TODO: why if condition, target_mapping not used (Pariterre?) if penalty.integration_rule == QuadratureRule.RECTANGLE_LEFT: @@ -159,12 +159,12 @@ def stochastic_minimize_variables(penalty: PenaltyOption, controller: PenaltyCon penalty.quadratic = True if penalty.quadratic is None else penalty.quadratic penalty.multi_thread = True if penalty.multi_thread is None else penalty.multi_thread - if key in controller.get_nlp.variable_mappings: - target_mapping = controller.get_nlp.variable_mappings[key] + if key in controller.nlp.variable_mappings: + target_mapping = controller.nlp.variable_mappings[key] else: target_mapping = BiMapping( - to_first=list(range(controller.get_nlp.controls[key].cx_start.shape[0])), - to_second=list(range(controller.get_nlp.controls[key].cx_start.shape[0])), + to_first=list(range(controller.nlp.controls[key].cx_start.shape[0])), + to_second=list(range(controller.nlp.controls[key].cx_start.shape[0])), ) return controller.stochastic_variables[key].cx_start @@ -223,7 +223,7 @@ def stochastic_minimize_expected_feedback_efforts(penalty: PenaltyOption, contro controls=controller.controls.cx_start, parameters=controller.parameters.cx_start, stochastic_variables=controller.stochastic_variables.cx_start, - nlp=controller.get_nlp, + nlp=controller.nlp, ) e_fb = k_matrix @ ((ee - ref) + controller.model.sensory_noise_magnitude) @@ -805,13 +805,13 @@ def minimize_contact_forces( penalty.cols should not be defined if contact_index is defined """ - if controller.get_nlp.contact_forces_func is None: + if controller.nlp.contact_forces_func is None: raise RuntimeError("minimize_contact_forces requires a contact dynamics") PenaltyFunctionAbstract.set_axes_rows(penalty, contact_index) penalty.quadratic = True if penalty.quadratic is None else penalty.quadratic - contact_force = controller.get_nlp.contact_forces_func( + contact_force = controller.nlp.contact_forces_func( controller.time.cx, controller.states.cx_start, controller.controls.cx_start, @@ -840,7 +840,7 @@ def minimize_soft_contact_forces( penalty.cols should not be defined if contact_index is defined """ - if controller.get_nlp.soft_contact_forces_func is None: + if controller.nlp.soft_contact_forces_func is None: raise RuntimeError("minimize_contact_forces requires a soft contact dynamics") PenaltyFunctionAbstract.set_axes_rows(penalty, contact_index) @@ -851,7 +851,7 @@ def minimize_soft_contact_forces( force_idx.append(3 + (6 * i_sc)) force_idx.append(4 + (6 * i_sc)) force_idx.append(5 + (6 * i_sc)) - soft_contact_force = controller.get_nlp.soft_contact_forces_func( + soft_contact_force = controller.nlp.soft_contact_forces_func( controller.time.cx, controller.states.cx_start, controller.controls.cx_start, controller.parameters.cx ) return soft_contact_force[force_idx] @@ -1127,11 +1127,11 @@ def state_continuity(penalty: PenaltyOption, controller: PenaltyController | lis if isinstance(penalty.node, (list, tuple)) and len(penalty.node) != 1: raise RuntimeError("continuity should be called one node at a time") - penalty.expand = controller.get_nlp.dynamics_type.expand_continuity + penalty.expand = controller.nlp.dynamics_type.expand_continuity if ( len(penalty.node_idx) > 1 - and not controller.get_nlp.phase_dynamics == PhaseDynamics.SHARED_DURING_THE_PHASE + and not controller.nlp.phase_dynamics == PhaseDynamics.SHARED_DURING_THE_PHASE ): raise NotImplementedError( f"Length of node index superior to 1 is not implemented yet," @@ -1139,7 +1139,7 @@ def state_continuity(penalty: PenaltyOption, controller: PenaltyController | lis ) continuity = controller.states.cx_end - if controller.get_nlp.ode_solver.is_direct_collocation: + if controller.nlp.ode_solver.is_direct_collocation: cx = horzcat(*([controller.states.cx_start] + controller.states.cx_intermediates_list)) continuity -= controller.integrate( x0=cx, u=u, p=controller.parameters.cx, s=controller.stochastic_variables.cx_start diff --git a/bioptim/limits/penalty_controller.py b/bioptim/limits/penalty_controller.py index 827799700..86f3422e7 100644 --- a/bioptim/limits/penalty_controller.py +++ b/bioptim/limits/penalty_controller.py @@ -81,7 +81,7 @@ def ocp(self): return self._ocp @property - def get_nlp(self): + def nlp(self): """ This method returns the underlying nlp. Please note that acting directly with the nlp is not want you should do. Unless you see no way to access what you need otherwise, we strongly suggest that you use the normal path diff --git a/bioptim/limits/penalty_option.py b/bioptim/limits/penalty_option.py index 6a2be0bc2..c862ebb25 100644 --- a/bioptim/limits/penalty_option.py +++ b/bioptim/limits/penalty_option.py @@ -307,7 +307,7 @@ def _check_target_dimensions(self, controller: PenaltyController | None, n_time_ ) if self.target[0].shape != shape: # A second chance the shape is correct is if the targets are declared but phase_dynamics is ONE_PER_NODE - if controller.get_nlp.phase_dynamics == PhaseDynamics.ONE_PER_NODE and self.target[0].shape[-1] == len( + if controller.nlp.phase_dynamics == PhaseDynamics.ONE_PER_NODE and self.target[0].shape[-1] == len( self.node_idx ): pass @@ -355,7 +355,7 @@ def _check_target_dimensions(self, controller: PenaltyController | None, n_time_ for target in self.target: if target.shape != shape: # A second chance the shape is correct if phase_dynamics is ONE_PER_NODE - if controller.get_nlp.phase_dynamics == PhaseDynamics.ONE_PER_NODE and target.shape[-1] == len( + if controller.nlp.phase_dynamics == PhaseDynamics.ONE_PER_NODE and target.shape[-1] == len( self.node_idx ): pass @@ -466,9 +466,9 @@ def _set_penalty_function( else: state_cx_scaled = controllers[1].states_scaled.cx if ( - controllers[1].get_nlp.phase_dynamics == PhaseDynamics.SHARED_DURING_THE_PHASE + controllers[1].nlp.phase_dynamics == PhaseDynamics.SHARED_DURING_THE_PHASE or controllers[1].node_index < controllers[1].ns - or controllers[1].get_nlp.control_type != ControlType.CONSTANT + or controllers[1].nlp.control_type != ControlType.CONSTANT ): if controllers[0].controls_scaled.cx.shape[0] > controllers[1].controls_scaled.cx.shape[0]: fake = controllers[0].cx( @@ -502,7 +502,7 @@ def _set_penalty_function( else: state_cx_scaled = vertcat(state_cx_scaled, controllers[0].states_scaled.cx) if ( - controllers[0].get_nlp.phase_dynamics == PhaseDynamics.SHARED_DURING_THE_PHASE + controllers[0].nlp.phase_dynamics == PhaseDynamics.SHARED_DURING_THE_PHASE or controllers[0].node_index < controllers[0].ns ): if controllers[1].controls_scaled.cx.shape[0] > controllers[0].controls_scaled.cx.shape[0]: @@ -536,9 +536,9 @@ def _set_penalty_function( else: state_cx_scaled = vertcat(state_cx_scaled, controllers[0].states_scaled.cx_start) if ( - controllers[0].get_nlp.phase_dynamics == PhaseDynamics.SHARED_DURING_THE_PHASE + controllers[0].nlp.phase_dynamics == PhaseDynamics.SHARED_DURING_THE_PHASE or controllers[0].node_index < controllers[0].ns - or controllers[1].get_nlp.control_type != ControlType.CONSTANT + or controllers[1].nlp.control_type != ControlType.CONSTANT ): if ( controllers[1].controls_scaled.cx_start.shape[0] @@ -598,7 +598,7 @@ def _set_penalty_function( control_cx_scaled = ocp.cx() stochastic_cx_scaled = ocp.cx() for ctrl in controllers: - if ctrl.node_index == controller.get_nlp.ns: + if ctrl.node_index == controller.nlp.ns: state_cx_scaled = vertcat(state_cx_scaled, ctrl.states_scaled.cx_start) control_cx_scaled = vertcat(control_cx_scaled, ctrl.controls_scaled.cx_start) stochastic_cx_scaled = vertcat(stochastic_cx_scaled, ctrl.stochastic_variables_scaled.cx_start) @@ -621,7 +621,7 @@ def _set_penalty_function( name = self.name state_cx_scaled = controller.states_scaled.cx_start if ( - controller.get_nlp.phase_dynamics == PhaseDynamics.SHARED_DURING_THE_PHASE + controller.nlp.phase_dynamics == PhaseDynamics.SHARED_DURING_THE_PHASE or controller.node_index < controller.ns ): if self.integrate or controller.ode_solver.is_direct_collocation: @@ -679,7 +679,7 @@ def _set_penalty_function( self.function_non_threaded[node] = self.function[node] if self.derivative: - if controller.get_nlp.ode_solver.is_direct_collocation and node != ocp.nlp[self.phase].ns: + if controller.nlp.ode_solver.is_direct_collocation and node != ocp.nlp[self.phase].ns: state_cx_scaled = vertcat( *( [controller.states_scaled.cx_end] @@ -890,7 +890,7 @@ def _set_penalty_function( @staticmethod def define_target_mapping(controller: PenaltyController, key: str): - target_mapping = controller.get_nlp.variable_mappings[key] + target_mapping = controller.nlp.variable_mappings[key] return target_mapping def add_target_to_plot(self, controller: PenaltyController, combine_to: str): @@ -947,7 +947,7 @@ def plot_function(t, x, u, p, s, penalty=None): penalty=self if plot_type == PlotType.POINT else None, color="tab:red", plot_type=plot_type, - phase=controller.get_nlp.phase_idx, + phase=controller.nlp.phase_idx, axes_idx=target_mapping, # TODO verify if not all elements has target node_idx=controller.t, ) @@ -992,7 +992,7 @@ def add_or_replace_to_penalty_pool(self, ocp, nlp): self.node = current_node_type # Finalize - self.ensure_penalty_sanity(ocp, controllers[0].get_nlp) + self.ensure_penalty_sanity(ocp, controllers[0].nlp) else: controllers = [self._get_penalty_controller(ocp, nlp)] @@ -1019,9 +1019,9 @@ def add_or_replace_to_penalty_pool(self, ocp, nlp): # Define much more function than needed, but we don't mind since they are reference copy of each other ns = ( - max(controllers[0].get_nlp.ns, controllers[1].get_nlp.ns) + max(controllers[0].nlp.ns, controllers[1].nlp.ns) if len(controllers) > 1 - else controllers[0].get_nlp.ns + else controllers[0].nlp.ns ) + 1 self.function = self.function * ns self.weighted_function = self.weighted_function * ns diff --git a/bioptim/optimization/variational_optimal_control_program.py b/bioptim/optimization/variational_optimal_control_program.py index 273cb5cff..882df52a2 100644 --- a/bioptim/optimization/variational_optimal_control_program.py +++ b/bioptim/optimization/variational_optimal_control_program.py @@ -391,8 +391,8 @@ def variational_integrator_three_nodes( """ if self.bio_model.has_holonomic_constraints: - return controllers[0].get_nlp.implicit_dynamics_func[0]( - controllers[0].get_nlp.dt, + return controllers[0].nlp.implicit_dynamics_func[0]( + controllers[0].nlp.dt, controllers[0].states["q"].cx, controllers[1].states["q"].cx, controllers[2].states["q"].cx, @@ -402,8 +402,8 @@ def variational_integrator_three_nodes( controllers[1].states["lambdas"].cx, ) else: - return controllers[0].get_nlp.implicit_dynamics_func[0]( - controllers[0].get_nlp.dt, + return controllers[0].nlp.implicit_dynamics_func[0]( + controllers[0].nlp.dt, controllers[0].states["q"].cx, controllers[1].states["q"].cx, controllers[2].states["q"].cx, @@ -430,8 +430,8 @@ def variational_integrator_initial( """ if self.bio_model.has_holonomic_constraints: - return controllers[0].get_nlp.implicit_dynamics_func_first_node[0]( - controllers[0].get_nlp.dt, + return controllers[0].nlp.implicit_dynamics_func_first_node[0]( + controllers[0].nlp.dt, controllers[0].states["q"].cx, controllers[0].parameters.cx[:n_qdot], controllers[1].states["q"].cx, @@ -440,8 +440,8 @@ def variational_integrator_initial( controllers[0].states["lambdas"].cx, ) else: - return controllers[0].get_nlp.implicit_dynamics_func_first_node[0]( - controllers[0].get_nlp.dt, + return controllers[0].nlp.implicit_dynamics_func_first_node[0]( + controllers[0].nlp.dt, controllers[0].states["q"].cx, controllers[0].parameters.cx[:n_qdot], controllers[1].states["q"].cx, @@ -468,8 +468,8 @@ def variational_integrator_final( """ if self.bio_model.has_holonomic_constraints: - return controllers[0].get_nlp.implicit_dynamics_func_last_node[0]( - controllers[0].get_nlp.dt, + return controllers[0].nlp.implicit_dynamics_func_last_node[0]( + controllers[0].nlp.dt, controllers[0].states["q"].cx, controllers[1].states["q"].cx, controllers[0].parameters.cx[n_qdot : 2 * n_qdot], @@ -478,8 +478,8 @@ def variational_integrator_final( controllers[1].states["lambdas"].cx, ) else: - return controllers[0].get_nlp.implicit_dynamics_func_last_node[0]( - controllers[0].get_nlp.dt, + return controllers[0].nlp.implicit_dynamics_func_last_node[0]( + controllers[0].nlp.dt, controllers[0].states["q"].cx, controllers[1].states["q"].cx, controllers[0].parameters.cx[n_qdot : 2 * n_qdot], From 842dc4169eca9f0ce30c23f64490aeb2427454b9 Mon Sep 17 00:00:00 2001 From: Alpha Date: Fri, 10 Nov 2023 10:14:56 +0000 Subject: [PATCH 2/2] fix: #706 Issue More options in ipopt solverOptions (Renaming based on CasADi::IpoptSolver Class Reference) --- bioptim/interfaces/solver_options.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bioptim/interfaces/solver_options.py b/bioptim/interfaces/solver_options.py index 6816d7e6d..c4732ad1d 100644 --- a/bioptim/interfaces/solver_options.py +++ b/bioptim/interfaces/solver_options.py @@ -484,7 +484,7 @@ def lbfgs_memory(self): return self._lbfgs_memory @property - def maximum_iterations(self): + def max_iter(self): return self._max_iter @property @@ -638,7 +638,7 @@ class ACADOS(Generic): QP solver to be used in the NLP solver. String in (‘PARTIAL_CONDENSING_HPIPM’, ‘FULL_CONDENSING_QPOASES’, ‘FULL_CONDENSING_HPIPM’, ‘PARTIAL_CONDENSING_QPDUNES’, ‘PARTIAL_CONDENSING_OSQP’). Default: ‘PARTIAL_CONDENSING_HPIPM’ - _hessian_approx: str + _hessian_approximation: str Hessian approximation. _integrator_type: str Integrator type. @@ -682,7 +682,7 @@ class ACADOS(Generic): type: SolverType = SolverType.ACADOS _qp_solver: str = "PARTIAL_CONDENSING_HPIPM" # FULL_CONDENSING_QPOASES - _hessian_approx: str = "GAUSS_NEWTON" + _hessian_approximation: str = "GAUSS_NEWTON" _integrator_type: str = "IRK" _nlp_solver_type: str = "SQP" _nlp_solver_tol_comp: float = 1e-06 @@ -722,11 +722,11 @@ def set_option_unsafe(self, val: float | int | str, name: str): self.set_only_first_options_has_changed(True) @property - def hessian_approx(self): - return self._hessian_approx + def hessian_approximation(self): + return self._hessian_approximation def set_hessian_approx(self, val: str): - self._hessian_approx = val + self._hessian_approximation = val self.set_only_first_options_has_changed(True) @property