Skip to content

Commit

Permalink
Optimized again
Browse files Browse the repository at this point in the history
  • Loading branch information
pariterre committed Jul 21, 2023
1 parent 4c0cb24 commit 6e4dc79
Show file tree
Hide file tree
Showing 21 changed files with 133 additions and 142 deletions.
2 changes: 1 addition & 1 deletion tests/test__global_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_plot_graphs_for_implicit_constraints(rigidbody_dynamics, assume_phase_d
final_time=1,
rigidbody_dynamics=rigidbody_dynamics,
assume_phase_dynamics=assume_phase_dynamics,
expand_dynamics=False,
expand_dynamics=True,
)
ocp.add_plot_penalty(CostType.ALL)
sol = ocp.solve()
Expand Down
36 changes: 18 additions & 18 deletions tests/test_acados_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_acados_no_obj(cost_type):
biorbd_model_path=bioptim_folder + "/models/cube.bioMod",
n_shooting=10,
tf=2,
expand_dynamics=False,
expand_dynamics=True,
)
solver = Solver.ACADOS()
solver.set_cost_type(cost_type)
Expand All @@ -64,7 +64,7 @@ def test_acados_one_mayer(cost_type):
bioptim_folder = os.path.dirname(ocp_module.__file__)

ocp = ocp_module.prepare_ocp(
biorbd_model_path=bioptim_folder + "/models/cube.bioMod", n_shooting=10, tf=2, expand_dynamics=False
biorbd_model_path=bioptim_folder + "/models/cube.bioMod", n_shooting=10, tf=2, expand_dynamics=True
)
objective_functions = ObjectiveList()
objective_functions.add(ObjectiveFcn.Mayer.MINIMIZE_STATE, key="q", index=[0], target=np.array([[1.0]]).T)
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_acados_mayer_first_node(cost_type):
biorbd_model_path=bioptim_folder + "/models/cube.bioMod",
n_shooting=10,
tf=2,
expand_dynamics=False,
expand_dynamics=True,
)
objective_functions = ObjectiveList()
objective_functions.add(
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_acados_several_mayer(cost_type):
biorbd_model_path=bioptim_folder + "/models/cube.bioMod",
n_shooting=10,
tf=2,
expand_dynamics=False,
expand_dynamics=True,
)
objective_functions = ObjectiveList()
objective_functions.add(ObjectiveFcn.Mayer.MINIMIZE_STATE, key="q", index=[0, 1], target=np.array([[1.0, 2.0]]).T)
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_acados_one_lagrange(cost_type):
biorbd_model_path=bioptim_folder + "/models/cube.bioMod",
n_shooting=n_shooting,
tf=2,
expand_dynamics=False,
expand_dynamics=True,
)
objective_functions = ObjectiveList()
objective_functions.add(
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_acados_one_lagrange_and_one_mayer(cost_type):
biorbd_model_path=bioptim_folder + "/models/cube.bioMod",
n_shooting=n_shooting,
tf=2,
expand_dynamics=False,
expand_dynamics=True,
)
objective_functions = ObjectiveList()
objective_functions.add(
Expand Down Expand Up @@ -260,7 +260,7 @@ def test_acados_control_lagrange_and_state_mayer(cost_type):
biorbd_model_path=bioptim_folder + "/models/cube.bioMod",
n_shooting=n_shooting,
tf=2,
expand_dynamics=False,
expand_dynamics=True,
)
objective_functions = ObjectiveList()
objective_functions.add(ObjectiveFcn.Lagrange.MINIMIZE_CONTROL, key="tau", multi_thread=False)
Expand Down Expand Up @@ -296,7 +296,7 @@ def test_acados_options(cost_type):
biorbd_model_path=bioptim_folder + "/models/pendulum.bioMod",
final_time=0.6,
n_shooting=200,
expand_dynamics=False,
expand_dynamics=True,
)

tols = [1e-1, 1e1]
Expand Down Expand Up @@ -330,7 +330,7 @@ def test_acados_fail_external():
biorbd_model_path=bioptim_folder + "/models/pendulum.bioMod",
final_time=1,
n_shooting=2,
expand_dynamics=False,
expand_dynamics=True,
)

solver = Solver.ACADOS()
Expand All @@ -354,7 +354,7 @@ def test_acados_fail_lls():
final_time=1,
n_shooting=2,
use_sx=True,
expand_dynamics=False,
expand_dynamics=True,
)

solver = Solver.ACADOS()
Expand All @@ -381,7 +381,7 @@ def test_acados_custom_dynamics(problem_type_custom):
problem_type_custom=problem_type_custom,
ode_solver=OdeSolver.RK4(),
use_sx=True,
expand_dynamics=False,
expand_dynamics=True,
)
constraints = ConstraintList()
constraints.add(ConstraintFcn.SUPERIMPOSE_MARKERS, node=Node.END, first_marker="m0", second_marker="m2")
Expand Down Expand Up @@ -426,7 +426,7 @@ def test_acados_one_parameter():
target_g=np.array([0, 0, -9.81]),
target_m=20,
use_sx=True,
expand_dynamics=False,
expand_dynamics=True,
)
model = ocp.nlp[0].model
objectives = ObjectiveList()
Expand Down Expand Up @@ -493,7 +493,7 @@ def test_acados_several_parameter():
target_g=np.array([0, 0, -9.81]),
target_m=20,
use_sx=True,
expand_dynamics=False,
expand_dynamics=True,
)
model = ocp.nlp[0].model
objectives = ObjectiveList()
Expand Down Expand Up @@ -562,7 +562,7 @@ def test_acados_one_end_constraints():
biorbd_model_path=bioptim_folder + "/models/cube.bioMod",
n_shooting=10,
tf=2,
expand_dynamics=False,
expand_dynamics=True,
)

model = ocp.nlp[0].model
Expand Down Expand Up @@ -616,7 +616,7 @@ def test_acados_constraints_all():
initialize_near_solution=True,
constr=False,
use_sx=True,
expand_dynamics=False,
expand_dynamics=True,
)

constraints = ConstraintList()
Expand Down Expand Up @@ -658,7 +658,7 @@ def test_acados_constraints_end_all():
initialize_near_solution=True,
constr=False,
use_sx=True,
expand_dynamics=False,
expand_dynamics=True,
)

constraints = ConstraintList()
Expand Down Expand Up @@ -699,7 +699,7 @@ def test_acados_assume_phase_dynamics_reject():
final_time=1,
n_shooting=10,
assume_phase_dynamics=False,
expand_dynamics=False,
expand_dynamics=True,
)

with pytest.raises(
Expand Down Expand Up @@ -753,7 +753,7 @@ def test_acados_bounds_not_implemented(failing):

mhe = MovingHorizonEstimator(
bio_model,
Dynamics(DynamicsFcn.TORQUE_DRIVEN, expand=False),
Dynamics(DynamicsFcn.TORQUE_DRIVEN, expand=True),
window_len,
window_duration,
x_init=x_init,
Expand Down
10 changes: 4 additions & 6 deletions tests/test_all_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test__acados__pendulum():
bioptim_folder = os.path.dirname(ocp_module.__file__)

ocp_module.prepare_ocp(
biorbd_model_path=bioptim_folder + "/models/pendulum.bioMod", n_shooting=41, final_time=3, expand_dynamics=False
biorbd_model_path=bioptim_folder + "/models/pendulum.bioMod", n_shooting=41, final_time=3, expand_dynamics=True
)


Expand Down Expand Up @@ -53,7 +53,7 @@ def test__getting_started__custom_bounds():
n_shooting=30,
final_time=2,
assume_phase_dynamics=True,
expand_dynamics=False,
expand_dynamics=True,
)


Expand All @@ -63,9 +63,7 @@ def test__getting_started__custom_constraints():
bioptim_folder = os.path.dirname(ocp_module.__file__)

ocp_module.prepare_ocp(
biorbd_model_path=bioptim_folder + "/models/cube.bioMod",
assume_phase_dynamics=True,
expand_dynamics=False,
biorbd_model_path=bioptim_folder + "/models/cube.bioMod", assume_phase_dynamics=True, expand_dynamics=False
)


Expand Down Expand Up @@ -95,7 +93,7 @@ def test__getting_started__custom_initial_guess(interpolation, random):
random_init=random,
initial_guess=interpolation,
assume_phase_dynamics=True,
expand_dynamics=False,
expand_dynamics=True,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_continuity_as_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_continuity_as_objective(assume_phase_dynamics):
n_shooting=3,
state_continuity_weight=1000000,
assume_phase_dynamics=assume_phase_dynamics,
expand_dynamics=False,
expand_dynamics=True,
)
sol = ocp.solve()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_controltype_none.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def prepare_ocp(
custom_model.declare_variables,
dynamic_function=custom_model.custom_dynamics,
phase=i,
expand=False,
expand=True,
)

# Creates the constraint for my n phases
Expand Down
2 changes: 1 addition & 1 deletion tests/test_custom_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_custom_model(assume_phase_dynamics):
configure_dynamics=configure_dynamics,
assume_phase_dynamics=assume_phase_dynamics,
n_threads=1,
expand_dynamics=False,
expand_dynamics=True,
)

np.testing.assert_almost_equal(ocp.nlp[0].model.nb_q, 1)
Expand Down
30 changes: 13 additions & 17 deletions tests/test_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_torque_driven(with_contact, with_external_force, cx, rigidbody_dynamics
DynamicsFcn.TORQUE_DRIVEN,
with_contact=with_contact,
rigidbody_dynamics=rigidbody_dynamics,
expand=False,
expand=True,
),
False,
)
Expand Down Expand Up @@ -212,7 +212,7 @@ def test_torque_driven_implicit(with_contact, cx, assume_phase_dynamics):
DynamicsFcn.TORQUE_DRIVEN,
with_contact=with_contact,
rigidbody_dynamics=RigidBodyDynamics.DAE_INVERSE_DYNAMICS,
expand=False,
expand=True,
),
False,
)
Expand Down Expand Up @@ -278,7 +278,7 @@ def test_torque_driven_soft_contacts_dynamics(with_contact, cx, implicit_contact
ocp,
"dynamics_type",
Dynamics(
DynamicsFcn.TORQUE_DRIVEN, with_contact=with_contact, soft_contacts_dynamics=implicit_contact, expand=False
DynamicsFcn.TORQUE_DRIVEN, with_contact=with_contact, soft_contacts_dynamics=implicit_contact, expand=True
),
False,
)
Expand Down Expand Up @@ -346,7 +346,7 @@ def test_torque_derivative_driven(with_contact, with_external_force, cx, assume_
Dynamics(
DynamicsFcn.TORQUE_DERIVATIVE_DRIVEN,
with_contact=with_contact,
expand=False,
expand=True,
),
False,
)
Expand Down Expand Up @@ -485,7 +485,7 @@ def test_torque_derivative_driven_implicit(with_contact, cx, assume_phase_dynami
DynamicsFcn.TORQUE_DERIVATIVE_DRIVEN,
with_contact=with_contact,
rigidbody_dynamics=RigidBodyDynamics.DAE_INVERSE_DYNAMICS,
expand=False,
expand=True,
),
False,
)
Expand Down Expand Up @@ -586,7 +586,7 @@ def test_torque_derivative_driven_soft_contacts_dynamics(with_contact, cx, impli
DynamicsFcn.TORQUE_DERIVATIVE_DRIVEN,
with_contact=with_contact,
soft_contacts_dynamics=implicit_contact,
expand=False,
expand=True,
),
False,
)
Expand Down Expand Up @@ -674,7 +674,7 @@ def test_soft_contacts_dynamics_errors(dynamics, assume_phase_dynamics):
NonLinearProgram.add(
ocp,
"dynamics_type",
Dynamics(dynamics, soft_contacts_dynamics=True, expand=False),
Dynamics(dynamics, soft_contacts_dynamics=True, expand=True),
False,
)
phase_index = [i for i in range(ocp.n_phases)]
Expand Down Expand Up @@ -716,7 +716,7 @@ def test_implicit_dynamics_errors(dynamics, assume_phase_dynamics):
NonLinearProgram.add(
ocp,
"dynamics_type",
Dynamics(dynamics, rigidbody_dynamics=RigidBodyDynamics.DAE_INVERSE_DYNAMICS, expand=False),
Dynamics(dynamics, rigidbody_dynamics=RigidBodyDynamics.DAE_INVERSE_DYNAMICS, expand=True),
False,
)
phase_index = [i for i in range(ocp.n_phases)]
Expand Down Expand Up @@ -761,7 +761,7 @@ def test_torque_activation_driven(with_contact, with_external_force, cx, assume_
NonLinearProgram.add(
ocp,
"dynamics_type",
Dynamics(DynamicsFcn.TORQUE_ACTIVATIONS_DRIVEN, with_contact=with_contact, expand=False),
Dynamics(DynamicsFcn.TORQUE_ACTIVATIONS_DRIVEN, with_contact=with_contact, expand=True),
False,
)
phase_index = [i for i in range(ocp.n_phases)]
Expand Down Expand Up @@ -867,7 +867,7 @@ def test_torque_activation_driven_with_residual_torque(
NonLinearProgram.add(
ocp,
"dynamics_type",
Dynamics(DynamicsFcn.TORQUE_ACTIVATIONS_DRIVEN, with_residual_torque=with_residual_torque, expand=False),
Dynamics(DynamicsFcn.TORQUE_ACTIVATIONS_DRIVEN, with_residual_torque=with_residual_torque, expand=True),
False,
)
phase_index = [i for i in range(ocp.n_phases)]
Expand Down Expand Up @@ -1500,7 +1500,7 @@ def test_joints_acceleration_driven(cx, rigid_body_dynamics, assume_phase_dynami
NonLinearProgram.add(
ocp,
"dynamics_type",
Dynamics(DynamicsFcn.JOINTS_ACCELERATION_DRIVEN, rigidbody_dynamics=rigid_body_dynamics, expand=False),
Dynamics(DynamicsFcn.JOINTS_ACCELERATION_DRIVEN, rigidbody_dynamics=rigid_body_dynamics, expand=True),
False,
)
np.random.seed(42)
Expand Down Expand Up @@ -1574,7 +1574,7 @@ def configure(ocp, nlp, with_contact=None):
NonLinearProgram.add(
ocp,
"dynamics_type",
Dynamics(configure, dynamic_function=custom_dynamic, with_contact=with_contact, expand=False),
Dynamics(configure, dynamic_function=custom_dynamic, with_contact=with_contact, expand=True),
False,
)
phase_index = [i for i in range(ocp.n_phases)]
Expand Down Expand Up @@ -1634,11 +1634,7 @@ def test_with_contact_error(dynamics_fcn, assume_phase_dynamics):
objective_functions = ObjectiveList()

# Dynamics
dynamics = Dynamics(
dynamics_fcn,
with_contact=True,
expand=False,
)
dynamics = Dynamics(dynamics_fcn, with_contact=True, expand=True)

# Path constraint
x_bounds = BoundsList()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_global_fail.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def custom_mx_fail(controller: PenaltyController):
):
OptimalControlProgram(
BiorbdModel(model_path),
Dynamics(DynamicsFcn.TORQUE_DRIVEN, expand=False),
Dynamics(DynamicsFcn.TORQUE_DRIVEN, expand=True),
30,
2,
constraints=constraints,
Expand Down Expand Up @@ -78,7 +78,7 @@ def custom_mx_fail(controller: PenaltyController):

ocp = OptimalControlProgram(
BiorbdModel(model_path),
Dynamics(DynamicsFcn.TORQUE_DRIVEN, expand=False),
Dynamics(DynamicsFcn.TORQUE_DRIVEN, expand=True),
30,
2,
constraints=constraints,
Expand Down
Loading

0 comments on commit 6e4dc79

Please sign in to comment.