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

Removing mx_reduced by creating "biorbd wrapper" #881

Merged
merged 109 commits into from
Nov 8, 2024

Conversation

EveCharbie
Copy link
Collaborator

@EveCharbie EveCharbie commented Jun 21, 2024

This change is Reviewable

@EveCharbie
Copy link
Collaborator Author

@pariterre @Ipuch This is what I was thinking about for the "biorbd wrapper".
I just did a proof of concept for pendulum.py to know what you guys think before I implement it for all biorbd functions.
This way, we do not have to carry around mx_reduced and I think we do not need .mx anymore neither because everything can be called directly with .cx.
It might get less clean when we add arguments which we cannot assume the shape (e.g. contact forces), but will still work.

@Ipuch
Copy link
Collaborator

Ipuch commented Jun 21, 2024

I would advocate for a supplementary interface (BiorbdModelToCasadiFunc ?) to biorbd. An entire class that does this for every function called by biorbd so we don't have to change the current class BiorbdModel, BiorbdMultiModel, Holonomic etc ...

Also, every function of the models that do not through a MX, absolutely need to be fixed. I'm thinking about rotation matrices that are still objects of biorbd for example.

Good Job !

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 5 of 5 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @EveCharbie)


bioptim/models/biorbd/biorbd_model.py line 212 at r1 (raw file):

    def reshape_qdot(self, k_stab=1) -> MX:
        q_mx_reduced = MX.sym("q_mx_reduced", self.nb_q, 1)

If we go this route, which I actually like, all MX should be removed from bioptim altogether (not 100% sure it works). It would be the responsability of the BioModel to keep track (if needed) of extra symbolic MX!


bioptim/models/biorbd/biorbd_model.py line 357 at r1 (raw file):

        q_mx_reduced = MX.sym("q_mx_reduced", self.nb_q, 1)
        qdot_mx_reduced = MX.sym("qdot_mx_reduced", self.nb_qdot, 1)
        tau_mx_reduced = MX.sym("tau_mx_reduced", self.nb_tau, 1)

Same here, it would be the dynamic responsability to declare MX.sym (if for instance they can't use SX, and return something which is dependent on .cx


bioptim/optimization/optimization_variable.py line 565 at r1 (raw file):

    @property
    def mx(self):
        return self.unscaled.mx

This would therefore rendered useless, which would GREATLY simplify bioptim (as only .cx would be useful)

Copy link
Collaborator Author

@EveCharbie EveCharbie 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: 4 of 5 files reviewed, 3 unresolved discussions (waiting on @pariterre)


bioptim/models/biorbd/biorbd_model.py line 212 at r1 (raw file):

Previously, pariterre (Pariterre) wrote…

If we go this route, which I actually like, all MX should be removed from bioptim altogether (not 100% sure it works). It would be the responsability of the BioModel to keep track (if needed) of extra symbolic MX!

Done.


bioptim/models/biorbd/biorbd_model.py line 357 at r1 (raw file):

Previously, pariterre (Pariterre) wrote…

Same here, it would be the dynamic responsability to declare MX.sym (if for instance they can't use SX, and return something which is dependent on .cx

Done.


bioptim/optimization/optimization_variable.py line 565 at r1 (raw file):

Previously, pariterre (Pariterre) wrote…

This would therefore rendered useless, which would GREATLY simplify bioptim (as only .cx would be useful)

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 9 of 12 files at r9, 24 of 24 files at r10, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @EveCharbie and @Ipuch)


bioptim/examples/torque_driven_ocp/spring_load.py line 151 at r10 (raw file):

    stiffness = 100
    tau += -sign(q[0]) * stiffness * q[0]  # damping

-=


bioptim/dynamics/configure_problem.py line 1968 at r10 (raw file):

        phase_dynamics: PhaseDynamics = PhaseDynamics.SHARED_DURING_THE_PHASE,
        numerical_data_timeseries: dict[str, np.ndarray] = None,
        # external_forces: ExternalForceSetTimeSeries = None,

To be removed

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 3 of 3 files at r11, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @Ipuch)

@pariterre pariterre merged commit f1c8b2e into pyomeca:master Nov 8, 2024
7 of 21 checks passed
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.

3 participants