def test_penalty_custom_with_bounds_failing_max_bound(value): def custom_with_bounds(ocp, nlp, t, x, u, p): my_values = DM.zeros((12, 1)) + x[0] return -10, my_values, 10 ocp = prepare_test_ocp() x = [DM.ones((12, 1)) * value] penalty_type = ConstraintFcn.CUSTOM penalty = Constraint(penalty_type) penalty.max_bound = 0 penalty.custom_function = custom_with_bounds with pytest.raises(RuntimeError): penalty_type.value[0](penalty, ocp, ocp.nlp[0], [], x, [], [])
def test_penalty_custom_with_bounds_failing_max_bound(value): def custom_with_bounds(pn): return -10, pn.nlp.states["q"].cx, 10 ocp = prepare_test_ocp() t = [0] x = [DM.ones((12, 1)) * value] u = [0] penalty_type = ConstraintFcn.CUSTOM penalty = Constraint(penalty_type) penalty.max_bound = 0 penalty.custom_function = custom_with_bounds with pytest.raises( RuntimeError, match= "You cannot have non linear bounds for custom constraints and min_bound or max_bound defined", ): penalty_type.value[0](penalty, PenaltyNodeList(ocp, ocp.nlp[0], t, x, [], []))