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

Bimapping troubles #912

Open
Ipuch opened this issue Feb 4, 2025 · 2 comments
Open

Bimapping troubles #912

Ipuch opened this issue Feb 4, 2025 · 2 comments

Comments

@Ipuch
Copy link
Collaborator

Ipuch commented Feb 4, 2025

Currently, I'm encountering an issue with how bimappings are handled in bioptim. In essence, I believe they are being applied globally across the entire Optimal Control Problem (OCP) when a per-phase approach is needed.

Context:

My problem involves transitioning between two different kinematic models across multiple phases.

Phase 1: Model has q_u, qdot_u, and tau associated with a certain number of degrees of freedom (DOFs).
Transition: The model changes to one with reduced DOFs (one less, specifically).
Phase 2: The model now has q and qdot, but the extra tau element is no longer present.

Problem:

I want to apply a mapping to the tau vector in the first phase, specifically to account for the extra DoF. However, I do not want to apply this mapping in the second phase because the DOF and the corresponding tau element no longer exist.

Currently, the applied mapping seems to be automatically applied to all phases, including the second phase where it's not valid and causing issues.

I found this line responsible for it :

variable_mappings = variable_mappings.variable_mapping_fill_phases(self.n_phases)

And this,

def variable_mapping_fill_phases(self, n_phases):
for mappings in self.options:
for key in mappings:
if mappings[key].automatic_multiple_phase:
for i_phase in range(n_phases):
if i_phase == 0:
mappings[key].phase = 0
else:
self.add(name=key, bimapping=mappings[key], phase=i_phase)
return self

The automatic_multiple_phase attribute , currently in OptionDict, affects all its child classes. However, it seems solely relevant to Bimapping. I'm questioning whether this global scope is necessary, particularly regarding the default application of mappings across all phases. I propose relocating automatic_multiple_phase to Bimapping and changing the default behavior to a phase-by-phase application. @pariterre @EveCharbie, could you share your insights and the rationale behind the current implementation?"

@EveCharbie
Copy link
Collaborator

I totally agree !
I think it will be easier to fix once issue #717 (node_mapping / phase_mapping) is fixed.
If you can wait until the weekend, I can make a PR for #717 (aka clean up my own mess) before you start tackling the current issue.

@Ipuch
Copy link
Collaborator Author

Ipuch commented Feb 5, 2025

I can wait :)

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

No branches or pull requests

2 participants