Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if we have radau and inverse dynamics constraints in collocation #448

Merged
merged 21 commits into from
Jun 9, 2022

Conversation

Ipuch
Copy link
Collaborator

@Ipuch Ipuch commented Mar 2, 2022

All Submissions:

  • Have you followed the guidelines in our Contributing document [docs/contribution.md]?
  • Have you checked to ensure there aren't other open [Pull Requests] for the same update/change?
  • Have you opened/linked the issue related to your pull request?
  • Have you used the tag [WIP] for on-going changes, and removed it when the pull request was ready?
  • When ready to merge, have you sent a comment pinging @pariterre in it?

New Feature Submissions:

  1. Does your submission pass the tests (if not please explain why this is intended)?
  2. Did you write a proper documentation (docstrings and ReadMe)
  3. Have you linted your code locally prior to submission (using the command: black . -l120 --exclude "external/*")?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new examples for your core changes, as applicable?
  • Have you written new tests for your core changes, as applicable?

according to
https://github.com/casadi/casadi/blob/402fe583f0d3cf1fc77d1e1ac933f75d86083124/casadi/solvers/collocation.cpp#L125


This change is Reviewable

@codecov
Copy link

codecov bot commented Mar 2, 2022

Codecov Report

Merging #448 (4969fb9) into CrazyDynamics (5d3d4ab) will increase coverage by 3.02%.
The diff coverage is 92.13%.

❗ Current head 4969fb9 differs from pull request most recent head fe6d5c6. Consider uploading reports for the commit fe6d5c6 to get more accurate results

@@                Coverage Diff                @@
##           CrazyDynamics     #448      +/-   ##
=================================================
+ Coverage          80.84%   83.86%   +3.02%     
=================================================
  Files                 85       86       +1     
  Lines               9299     9354      +55     
=================================================
+ Hits                7518     7845     +327     
+ Misses              1781     1509     -272     
Impacted Files Coverage Δ
bioptim/dynamics/integrator.py 94.73% <66.66%> (-2.20%) ⬇️
bioptim/dynamics/dynamics_functions.py 95.72% <93.93%> (-0.47%) ⬇️
bioptim/dynamics/configure_problem.py 89.14% <95.45%> (+0.05%) ⬆️
bioptim/__init__.py 100.00% <100.00%> (ø)
bioptim/dynamics/dynamics_evaluation.py 100.00% <100.00%> (ø)
bioptim/dynamics/ode_solver.py 88.49% <100.00%> (+0.10%) ⬆️
...ioptim/examples/getting_started/custom_dynamics.py 88.88% <100.00%> (ø)
...es/muscle_driven_ocp/muscle_activations_tracker.py 75.23% <100.00%> (ø)
...es/muscle_driven_ocp/muscle_excitations_tracker.py 72.64% <100.00%> (ø)
bioptim/examples/torque_driven_ocp/spring_load.py 90.00% <100.00%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5d3d4ab...fe6d5c6. Read the comment docs.

@Ipuch Ipuch changed the title if we have radau [WIP] if we have radau and inverse dynamics constraints in collocation Mar 2, 2022
@Ipuch
Copy link
Collaborator Author

Ipuch commented Mar 3, 2022

related to #421

@Ipuch
Copy link
Collaborator Author

Ipuch commented Mar 3, 2022

and #385

bioptim/dynamics/integrator.py Outdated Show resolved Hide resolved
bioptim/dynamics/integrator.py Outdated Show resolved Hide resolved
bioptim/examples/getting_started/pendulum.py Outdated Show resolved Hide resolved
bioptim/examples/getting_started/pendulum.py Outdated Show resolved Hide resolved
bioptim/dynamics/configure_problem.py Outdated Show resolved Hide resolved
bioptim/dynamics/configure_problem.py Outdated Show resolved Hide resolved
Copy link
Member

@pariterre pariterre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work so far!

bioptim/dynamics/configure_problem.py Outdated Show resolved Hide resolved
bioptim/dynamics/configure_problem.py Show resolved Hide resolved
bioptim/dynamics/configure_problem.py Outdated Show resolved Hide resolved
bioptim/dynamics/dynamics_functions.py Outdated Show resolved Hide resolved
bioptim/dynamics/dynamics_functions.py Outdated Show resolved Hide resolved
bioptim/examples/getting_started/custom_dynamics.py Outdated Show resolved Hide resolved
tests/test_dynamics.py Outdated Show resolved Hide resolved
tests/test_global_getting_started.py Outdated Show resolved Hide resolved
@Ipuch
Copy link
Collaborator Author

Ipuch commented Mar 10, 2022

I couldn't find out why the bimapping in test_symmetry_by_mapping(ode_solver) is not applied on qddot which is a states_dot. It fails in IRK and collocation then.

Copy link
Member

@pariterre pariterre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 11 files at r3, 12 of 12 files at r4, all commit messages.
Reviewable status: 15 of 16 files reviewed, 8 unresolved discussions (waiting on @Ipuch and @pariterre)


bioptim/dynamics/dynamics_functions.py, line 48 at r4 (raw file):

    @staticmethod
    def custom(states: MX.sym, controls: MX.sym, parameters: MX.sym, nlp):

The return should be -> DynamicsEvalution


bioptim/dynamics/dynamics_functions.py, line 102 at r4 (raw file):

        fatigue : FatigueList
            A list of fatigue elements
        """

Please add back the Returns, but adjust it to the DynamicsEvaluation class


bioptim/dynamics/dynamics_functions.py, line 116 at r4 (raw file):

            dxdt[nlp.states["qdot"].index, :] = DynamicsFunctions.get(nlp.controls["qddot"], controls)
        else:

Remove spacing


bioptim/dynamics/dynamics_functions.py, line 212 at r4 (raw file):

        with_contact: bool
            If the dynamic with contact should be used
        """

Please add back the Returns, but adjust it to the DynamicsEvaluation class


bioptim/dynamics/dynamics_functions.py, line 248 at r4 (raw file):

        with_contact: bool
            If the dynamic with contact should be used
        """

Please add back the Returns, but adjust it to the DynamicsEvaluation class


bioptim/dynamics/dynamics_functions.py, line 373 at r4 (raw file):

        with_torque: bool
            If the dynamic should be added with residual torques
        """

Please add back the Returns, but adjust it to the DynamicsEvaluation class


bioptim/examples/getting_started/custom_dynamics.py, line 76 at r4 (raw file):

    # the implicit dynamics f(x,u,p,xdot)=0 as the second argument
    # which may be useful for IRK or COLLOCATION integrators
    return DynamicsEvaluation(vertcat(dq, ddq), None)

Maybe add the hints here so lambda user sees what it means (DynamicsEvaluation(dxdt=..., ...=...))


bioptim/optimization/non_linear_program.py, line 119 at r4 (raw file):

        self.dt = None
        self.dynamics = []
        self.dynamics_sym = DynamicsEvaluation()

dynamics_sym? Why not dynamics_evalution as it is a DynamicsEvaluation class... Otherwise everyone has to remember that dynamics_sym is not an MX.sym instance, but a DynamicsEvaluation..

@Ipuch Ipuch changed the base branch from master to CrazyDynamics April 29, 2022 20:19
@Ipuch
Copy link
Collaborator Author

Ipuch commented May 24, 2022

@pariterre reviewable, and I think mergeable on CrazyDyanmics.

@Ipuch Ipuch changed the title [WIP] if we have radau and inverse dynamics constraints in collocation if we have radau and inverse dynamics constraints in collocation May 25, 2022
Copy link
Collaborator Author

@Ipuch Ipuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 17 files reviewed, 8 unresolved discussions (waiting on @pariterre)


bioptim/dynamics/dynamics_functions.py line 71 at r3 (raw file):

Previously, pariterre (Pariterre) wrote…

This should also take into account the dynamics when the user does not provide the implicit version.

I'm not sure to understand what you meant


bioptim/dynamics/dynamics_functions.py line 569 at r3 (raw file):

Previously, pariterre (Pariterre) wrote…

This is not tested but I feel it should be

this function was not used so deleted


bioptim/dynamics/dynamics_functions.py line 48 at r4 (raw file):

Previously, pariterre (Pariterre) wrote…

The return should be -> DynamicsEvalution

ok


bioptim/dynamics/dynamics_functions.py line 102 at r4 (raw file):

Previously, pariterre (Pariterre) wrote…

Please add back the Returns, but adjust it to the DynamicsEvaluation class

done


bioptim/dynamics/dynamics_functions.py line 116 at r4 (raw file):

Previously, pariterre (Pariterre) wrote…

Remove spacing

done


bioptim/dynamics/dynamics_functions.py line 212 at r4 (raw file):

Previously, pariterre (Pariterre) wrote…

Please add back the Returns, but adjust it to the DynamicsEvaluation class

done


bioptim/dynamics/dynamics_functions.py line 248 at r4 (raw file):

Previously, pariterre (Pariterre) wrote…

Please add back the Returns, but adjust it to the DynamicsEvaluation class

done


bioptim/dynamics/dynamics_functions.py line 373 at r4 (raw file):

Previously, pariterre (Pariterre) wrote…

Please add back the Returns, but adjust it to the DynamicsEvaluation class

done


bioptim/examples/getting_started/custom_dynamics.py line 76 at r4 (raw file):

Previously, pariterre (Pariterre) wrote…

Maybe add the hints here so lambda user sees what it means (DynamicsEvaluation(dxdt=..., ...=...))

done


bioptim/optimization/non_linear_program.py line 119 at r4 (raw file):

Previously, pariterre (Pariterre) wrote…

dynamics_sym? Why not dynamics_evalution as it is a DynamicsEvaluation class... Otherwise everyone has to remember that dynamics_sym is not an MX.sym instance, but a DynamicsEvaluation..

done

Copy link
Member

@pariterre pariterre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 11 files at r3, 4 of 4 files at r5, 10 of 12 files at r6, 2 of 2 files at r7, 1 of 1 files at r8, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @Ipuch and @pariterre)


bioptim/dynamics/configure_problem.py line 160 at r7 (raw file):

        ConfigureProblem.configure_qdot(nlp, True, False, True)
        ConfigureProblem.configure_tau(nlp, False, True, fatigue)
        ConfigureProblem.configure_qddot(nlp, False, False, True)

move this to an else


bioptim/dynamics/configure_problem.py line 170 at r7 (raw file):

            or rigidbody_dynamics == RigidBodyDynamics.DAE_INVERSE_DYNAMICS_JERK
        ):
            ConfigureProblem.configure_qddot(nlp, True, False)

There is a bug here


bioptim/dynamics/integrator.py line 618 at r7 (raw file):

                xp_j += self._c[r, j] * states[r]

            if self.defects_type == "explicit":

DefectType.EXPLICIT
DefectType.IMPLICIT
DefectType.NOT_APPLICABLE


bioptim/dynamics/ode_solver.py line 237 at r7 (raw file):

        """

        def __init__(self, polynomial_degree: int = 4, method: str = "legendre", defects_type: str = "explicit"):

ENUM


bioptim/dynamics/ode_solver.py line 316 at r7 (raw file):

        """

        def __init__(self, polynomial_degree: int = 4, method: str = "legendre", defects_type: str = "explicit"):

ENUM

Copy link
Collaborator Author

@Ipuch Ipuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @pariterre)


bioptim/dynamics/configure_problem.py line 160 at r7 (raw file):

Previously, pariterre (Pariterre) wrote…

move this to an else

not implemented yet


bioptim/dynamics/configure_problem.py line 170 at r7 (raw file):

Previously, pariterre (Pariterre) wrote…

There is a bug here

done


bioptim/dynamics/integrator.py line 618 at r7 (raw file):

Previously, pariterre (Pariterre) wrote…

DefectType.EXPLICIT
DefectType.IMPLICIT
DefectType.NOT_APPLICABLE

done


bioptim/dynamics/ode_solver.py line 237 at r7 (raw file):

Previously, pariterre (Pariterre) wrote…

ENUM

done


bioptim/dynamics/ode_solver.py line 316 at r7 (raw file):

Previously, pariterre (Pariterre) wrote…

ENUM

done

@Ipuch
Copy link
Collaborator Author

Ipuch commented May 27, 2022

done.

Copy link
Member

@pariterre pariterre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 8 of 8 files at r9, 1 of 1 files at r10, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Ipuch)


bioptim/examples/getting_started/pendulum.py line 34 at r10 (raw file):

    n_shooting: int,
    ode_solver: OdeSolver = OdeSolver.IRK(),
    use_sx: bool = False,

Please revert to the actual example

Code quote:

    ode_solver: OdeSolver = OdeSolver.IRK(),
    use_sx: bool = False,

Copy link
Member

@pariterre pariterre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r11, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Ipuch)

@pariterre pariterre merged commit 5be6662 into pyomeca:CrazyDynamics Jun 9, 2022
@Ipuch Ipuch deleted the collocation_test branch June 9, 2022 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants