Skip to content

Commit

Permalink
fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EveCharbie committed Oct 29, 2024
1 parent 46ee47f commit 8bb744b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
11 changes: 8 additions & 3 deletions bioptim/dynamics/configure_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,10 @@ def torque_driven(
# Configure the contact forces
if with_contact:
ConfigureProblem.configure_contact_function(ocp, nlp, DynamicsFunctions.forces_from_torque_driven)

# Configure the soft contact forces
ConfigureProblem.configure_soft_contact_function(ocp, nlp)

# Algebraic constraints of soft contact forces if needed
if soft_contacts_dynamics == SoftContactDynamics.CONSTRAINT:
ocp.implicit_constraints.add(
Expand Down Expand Up @@ -853,9 +855,10 @@ def configure_lagrange_multipliers_function(ocp, nlp, dyn_func: Callable, **extr
nlp.numerical_timeseries.cx,
],
[
dyn_func(
dyn_func()(
nlp.get_var_from_states_or_controls("q_u", nlp.states.scaled.cx, nlp.controls.scaled.cx),
nlp.get_var_from_states_or_controls("qdot_u", nlp.states.scaled.cx, nlp.controls.scaled.cx),
DM.zeros(nlp.model.nb_dependent_joints, 1),
DynamicsFunctions.get(nlp.controls["tau"], nlp.controls.scaled.cx),
)
],
Expand Down Expand Up @@ -917,8 +920,9 @@ def configure_qv(ocp, nlp, dyn_func: Callable, **extra_params):
nlp.numerical_timeseries.cx,
],
[
dyn_func(
dyn_func()(
nlp.get_var_from_states_or_controls("q_u", nlp.states.cx, nlp.controls.cx),
DM.zeros(nlp.model.nb_dependent_joints, 1),
)
],
["t_span", "x", "u", "p", "a", "d"],
Expand Down Expand Up @@ -975,9 +979,10 @@ def configure_qdotv(ocp, nlp, dyn_func: Callable, **extra_params):
nlp.numerical_timeseries.cx,
],
[
dyn_func(
dyn_func()(
nlp.get_var_from_states_or_controls("q_u", nlp.states.scaled.cx, nlp.controls.scaled.cx),
nlp.get_var_from_states_or_controls("qdot_u", nlp.states.scaled.cx, nlp.controls.scaled.cx),
DM.zeros(nlp.model.nb_dependent_joints, 1),
)
],
["t_span", "x", "u", "p", "a", "d"],
Expand Down
8 changes: 3 additions & 5 deletions bioptim/dynamics/dynamics_functions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import numpy as np
from casadi import horzcat, vertcat, MX, SX
from casadi import horzcat, vertcat, MX, SX, DM

from .dynamics_evaluation import DynamicsEvaluation
from .fatigue.fatigue_dynamics import FatigueList
from ..misc.enums import DefectType
from ..misc.mapping import BiMapping
from ..optimization.optimization_variable import OptimizationVariable

Expand Down Expand Up @@ -1138,7 +1136,7 @@ def holonomic_torque_driven(
tau = DynamicsFunctions.get(nlp.controls["tau"], controls)
q_v_init = DM.zeros(
nlp.model.nb_dependent_joints
) # @ipuch: I'm not sure of this, where q_v_init is supposed to be if not zeros?
qddot_u = nlp.model.partitioned_forward_dynamics()(q_u, qdot_u, q_v_init, tau, nlp.parameters.cx)
)
qddot_u = nlp.model.partitioned_forward_dynamics()(q_u, qdot_u, q_v_init, tau)

return DynamicsEvaluation(dxdt=vertcat(qdot_u, qddot_u), defects=None)
1 change: 1 addition & 0 deletions bioptim/limits/penalty_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ def add_or_replace_to_penalty_pool(self, ocp, nlp):

# The active controller is always the last one, and they all should be the same length anyway
for node in range(len(controllers[-1])):
# TODO
# TODO WARNING THE NEXT IF STATEMENT IS A BUG DELIBERATELY INTRODUCED TO FIT THE PREVIOUS RESULTS.
# IT SHOULD BE REMOVED AS SOON AS THE MERGE IS DONE (AND VALUES OF THE TESTS ADJUSTED)
if self.integrate and self.target is not None:
Expand Down
2 changes: 1 addition & 1 deletion bioptim/misc/external_forces.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_external_forces_segments(external_forces: ExternalForces):
for key in external_forces.keys():
force_torsor = external_forces[key]
# Check sanity first
if force_torsor.force_reference_frame == ReferenceFrame.GLOBAL and force_torsor.point_of_application_reference_frame == ReferenceFrame.LOCAL and force.torque_data is not None:
if force_torsor.force_reference_frame == ReferenceFrame.GLOBAL and force_torsor.point_of_application_reference_frame == ReferenceFrame.LOCAL and force_torsor.torque_data is not None:
raise NotImplementedError("External forces in global reference frame cannot have a point of application in the local reference frame and torques defined at the same time yet")
elif force_torsor.force_reference_frame == ReferenceFrame.LOCAL and force_torsor.point_of_application_reference_frame == ReferenceFrame.GLOBAL:
raise NotImplementedError("External forces in local reference frame cannot have a point of application in the global reference frame yet")
Expand Down
2 changes: 1 addition & 1 deletion bioptim/models/biorbd/holonomic_biorbd_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def _compute_qdot_v(self) -> Function:
q = self.compute_q()(self.q_u, self.q_v_init)
biorbd_return = self.compute_qdot_v()(q, self.qdot_u)
casadi_fun = Function(
"compute_qdot_v", [self.q, self.qdot_u, self.q_v_init], [biorbd_return], ["q", "qdot_u"], ["qdot_v"]
"compute_qdot_v", [self.q_u, self.qdot_u, self.q_v_init], [biorbd_return], ["q_u", "qdot_u", "q_v_init"], ["qdot_v"]
)
return casadi_fun

Expand Down
2 changes: 1 addition & 1 deletion tests/shard1/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def test_multi_cyclic_cycle_solutions():
def test_external_forces_type():
assert ExternalForceType.FORCE.value == "force"
assert ExternalForceType.TORQUE.value == "torque"
assert ExternalForceType.TORQUE_AND_FORCE.value == "force_and_torque"
assert ExternalForceType.TORQUE_AND_FORCE.value == "torque_and_force"

# verify the number of elements
assert len(ExternalForceType) == 3
Expand Down
1 change: 0 additions & 1 deletion tests/shard3/test_get_time_solution.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

import pytest
import numpy as np
import numpy.testing as npt

from bioptim import OdeSolver, Solver, PhaseDynamics, SolutionMerge, TimeAlignment, ControlType, Solution
Expand Down

0 comments on commit 8bb744b

Please sign in to comment.