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

[WIP] defects, contacts, implicit constraints, multinode constraints with cx_intermediates, ... #946

Open
wants to merge 121 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
eb7c6e9
tempoo
EveCharbie Mar 4, 2025
4df4017
generalized get_external_forces
EveCharbie Mar 5, 2025
a1d76b2
Merge remote-tracking branch 'Ipuch/algebraic'
EveCharbie Mar 5, 2025
0966ba9
fixed the graphs on the existing examples
EveCharbie Mar 5, 2025
90820a7
Initial implementation of the implicit contact example
EveCharbie Mar 5, 2025
f0c0762
rigid contact names
EveCharbie Mar 5, 2025
d812997
external force set variable
EveCharbie Mar 5, 2025
51ec526
method renaming: dxdt -> get_states_end
EveCharbie Mar 5, 2025
3fc0789
allowed for dxdt=None
EveCharbie Mar 6, 2025
6a9697f
rigid_contact_velocity
EveCharbie Mar 6, 2025
1f8cddd
updated example
EveCharbie Mar 6, 2025
9bf5b85
version without subnodes (runs but does not work)
EveCharbie Mar 7, 2025
def851a
a_init with ALL_POINTS
EveCharbie Mar 7, 2025
fcee6fe
make sure slope interpretation is ok
EveCharbie Mar 12, 2025
80a0f6f
other way around ?
EveCharbie Mar 12, 2025
e513e22
Merge remote-tracking branch 'pyomeca/master' into cx_intermediates
EveCharbie Mar 13, 2025
f9de1f0
doc update
EveCharbie Mar 13, 2025
7eb8b28
algebraic states continuity
EveCharbie Mar 13, 2025
653ef0a
configure test update
EveCharbie Mar 13, 2025
042fb1f
I think I got it !!!
EveCharbie Mar 13, 2025
7190b91
blacked
EveCharbie Mar 13, 2025
6ed3a8f
updated example but problem with first defect
EveCharbie Mar 13, 2025
0d1a3c8
added an implicit defect at first subnode
EveCharbie Mar 13, 2025
3eb5c8b
LINEAR_CONTINUOUS in COLLOCATION
EveCharbie Mar 13, 2025
840830c
blacked
EveCharbie Mar 13, 2025
062839a
woups
EveCharbie Mar 13, 2025
e964a86
reverted first defect
EveCharbie Mar 14, 2025
680727f
THE BUG WAS HERE !!!
EveCharbie Mar 14, 2025
bcec035
soft contacts + independent contacts on each segment
EveCharbie Mar 14, 2025
cbbd1ec
rigid example update
EveCharbie Mar 14, 2025
44b0e20
soft contact works :D (just need to fix reintegration)
EveCharbie Mar 14, 2025
b6f88d2
contact force derivative runs... will it converge ?
EveCharbie Mar 14, 2025
ff561c8
Need to retest the rigid implementation (might be OK after all)
EveCharbie Mar 14, 2025
e3886fa
blacked
EveCharbie Mar 14, 2025
65d79d0
this hacky was ?
EveCharbie Mar 17, 2025
60ae31d
ode_solver in dynamics
EveCharbie Mar 17, 2025
4071a4b
blacked
EveCharbie Mar 17, 2025
349a2a6
contact type Enum
EveCharbie Mar 17, 2025
cbfad9c
fixed some more ode_solver tests
EveCharbie Mar 17, 2025
b103dc2
blacked
EveCharbie Mar 17, 2025
bf1b433
only defects for COLLOCATION
EveCharbie Mar 17, 2025
54e2bca
blacked
EveCharbie Mar 17, 2025
53cc1f3
Merge remote-tracking branch 'pyomeca/master' into dxdt_defect_refactor
EveCharbie Mar 17, 2025
3c578db
get forces by name
EveCharbie Mar 17, 2025
8c81efa
blacked
EveCharbie Mar 17, 2025
4a32604
removed comments
EveCharbie Mar 18, 2025
ed9adf1
Merge remote-tracking branch 'EveCharbie/cx_intermediates' into cx_in…
EveCharbie Mar 18, 2025
742385f
small doc update
EveCharbie Mar 18, 2025
0a716b2
fixed some tests
EveCharbie Mar 18, 2025
7bc8cb4
Fixed *** phase transition!!
EveCharbie Mar 18, 2025
11f9542
fixed some more
EveCharbie Mar 18, 2025
8de4617
I think I got it !!
EveCharbie Mar 18, 2025
9710d21
with a little luck this is OK
EveCharbie Mar 18, 2025
4d6ce1e
tes test values must be added
EveCharbie Mar 18, 2025
59b2443
fixed some tests + tested COLL/IRK with LINEAR_CONTINUOUS
EveCharbie Mar 19, 2025
1e10070
blacked
EveCharbie Mar 19, 2025
e1e6fe5
fixed some more tests
EveCharbie Mar 19, 2025
4ab9401
bis
EveCharbie Mar 19, 2025
bde5b98
blacked
EveCharbie Mar 19, 2025
441e9fa
still tests --'
EveCharbie Mar 19, 2025
19c7004
blacked
EveCharbie Mar 19, 2025
c5ff8cd
woups
EveCharbie Mar 19, 2025
2b8364b
.
EveCharbie Mar 19, 2025
8f23404
tests
EveCharbie Mar 19, 2025
f2b652c
Merge remote-tracking branch 'origin/cx_intermediates' into cx_interm…
EveCharbie Mar 19, 2025
e0b4b1b
added tests for the new examples
EveCharbie Mar 20, 2025
9caf54b
need the other PR to integrate
EveCharbie Mar 20, 2025
95a4aa3
fixed some tests
EveCharbie Mar 20, 2025
38a6b34
blacked
EveCharbie Mar 20, 2025
eb8d0af
fixed some more
EveCharbie Mar 20, 2025
a23f2eb
blacked
EveCharbie Mar 20, 2025
b275c6a
woups
EveCharbie Mar 20, 2025
7c1e89d
fix: fatigue dynamics
EveCharbie Mar 20, 2025
573fd20
fix: variational
EveCharbie Mar 20, 2025
2e6309b
blacked
EveCharbie Mar 20, 2025
3bd4800
fixed some tests
EveCharbie Mar 21, 2025
0bc79eb
integration works but the time alignement is not good
EveCharbie Mar 21, 2025
6e0df09
I think I fixed the reintegration in collocation ? :D
EveCharbie Mar 21, 2025
743f392
blacked
EveCharbie Mar 21, 2025
64e2243
fixed some tests
EveCharbie Mar 21, 2025
636b38b
muscle tests
EveCharbie Mar 21, 2025
b8cab01
still on the *** integration
EveCharbie Mar 21, 2025
d4ff08b
blacked
EveCharbie Mar 21, 2025
07f1635
;p
EveCharbie Mar 22, 2025
b1962a7
fixed noisy integrate
EveCharbie Mar 22, 2025
bb57bb0
blacked
EveCharbie Mar 22, 2025
61ef418
Merge branch 'cx_intermediates' into tempo_merge
EveCharbie Mar 22, 2025
405fcef
tried updating the new examples after merge (no convergence of soft)
EveCharbie Mar 22, 2025
340881e
better reintegration plot
EveCharbie Mar 22, 2025
dd0c74f
matching the original defects I used
EveCharbie Mar 22, 2025
9cf62f7
min qdot
EveCharbie Mar 22, 2025
a6f43e5
Merge branch 'cx_intermediates' into tempo_merge
EveCharbie Mar 22, 2025
37c5eb4
temporary integrate outside bioptim
EveCharbie Mar 22, 2025
0ccbaec
sol.integrate seems OK (the problem might be the first and last defects)
EveCharbie Mar 22, 2025
0e29363
explicit -> qddot equals forward dynamics
EveCharbie Mar 24, 2025
cf599c4
example is crap, but the dynamics is consistent
EveCharbie Mar 24, 2025
ef0a22e
main idea of contact type
EveCharbie Mar 24, 2025
fff1e94
reverted the old_ode_solver shenanigans
EveCharbie Mar 26, 2025
4dd59d3
list of ContactTypes
EveCharbie Mar 26, 2025
63a2818
removed as_states_dot
EveCharbie Mar 26, 2025
5b3e5a7
finalized torque_driven, going to remove soft_contact_dynamics
EveCharbie Mar 26, 2025
c9aef0d
removed soft_contact_dynamics
EveCharbie Mar 26, 2025
699a6fb
moved configure_contact
EveCharbie Mar 26, 2025
b56a2fc
made some more changes requested by pariterre
EveCharbie Mar 26, 2025
aa128d5
blacked
EveCharbie Mar 26, 2025
7e3922c
Merge remote-tracking branch 'pyomeca/master' into tempo_merge
EveCharbie Mar 26, 2025
3bbd907
removed ImplicitConstraintFcn
EveCharbie Mar 27, 2025
e9a3e7f
fixed tests
EveCharbie Mar 28, 2025
25f5179
blacked
EveCharbie Mar 28, 2025
983f180
shard 1
EveCharbie Mar 28, 2025
82c48e1
fixed some tests
EveCharbie Mar 28, 2025
1042c55
blacked
EveCharbie Mar 28, 2025
24ebbaf
swapped contact implicit for explicit during reintegration
EveCharbie Mar 28, 2025
cebee2f
fixed COLLOCATION with LINEAR
EveCharbie Mar 28, 2025
7101900
blacked
EveCharbie Mar 28, 2025
a09a6fe
contat_type in configure
EveCharbie Mar 28, 2025
25fb1a5
blacked
EveCharbie Mar 28, 2025
fbc6368
to rerun the tests
EveCharbie Mar 31, 2025
5e0e92e
woupsi inf loop
EveCharbie Mar 31, 2025
f630bb8
blacked
EveCharbie Mar 31, 2025
af07b8d
fixed some tests
EveCharbie Mar 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ As a tour guide that uses this binder, you can watch the `bioptim` workshop that
- [CostType](#enum-costtype)
- [SolutionIntegrator](#enum-solutionintegrator)
- [QuadratureRule](#enum-quadraturerule)
- [SoftContactDynamics](#enum-softcontactdynamics)
- [DefectType](#enum-defecttype)

</details>
Expand Down Expand Up @@ -707,7 +706,6 @@ OptimalControlProgram(
objective_functions: [Objective, ObjectiveList],
constraints: [Constraint, ConstraintList],
parameters: ParameterList,
ode_solver: OdeSolver,
control_type: [ControlType, list],
all_generalized_mapping: BiMapping,
q_mapping: BiMapping,
Expand Down Expand Up @@ -1760,18 +1758,6 @@ The type of integration used to integrate the cost function terms of Lagrange:
- APPROXIMATE_TRAPEZOIDAL: The integral is approximated by a trapezoidal rule using the state at the beginning of the next interval.
- TRAPEZOIDAL: The integral is approximated by a trapezoidal rule using the state at the end of the current interval.

### Enum: SoftContactDynamics
The type of transcription of any dynamics (e.g., rigidbody_dynamics or soft_contact_dynamics):
- ODE: soft contact dynamics is handled explicitly.
- CONSTRAINT: an extra control *fext* is added, and it ensures respecting soft contact_dynamics on nodes through a constraint.

### Enum: DefectType
- EXPLICIT: The defect comes from the explicit formulation.
- IMPLICIT: The defect comes from the implicit formulation.
- NOT_APPLICABLE: The defect is not applicable.



# Examples
In this section, we describe all the examples implemented with bioptim. They are ordered in separate files. Each subsection corresponds to the different files, dealing with different examples and topics.
Please note that the examples from the paper (see [Citing](#citing)) can be found in this repo
Expand Down
4 changes: 2 additions & 2 deletions bioptim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,16 @@
VariableType,
SolutionIntegrator,
QuadratureRule,
SoftContactDynamics,
DefectType,
MagnitudeType,
MultiCyclicCycleSolutions,
PhaseDynamics,
OnlineOptim,
ContactType,
)
from .misc.mapping import BiMappingList, BiMapping, Mapping, SelectionMapping, Dependency
from .models.biorbd.biorbd_model import BiorbdModel
from .models.biorbd.external_forces import ExternalForceSetTimeSeries
from .models.biorbd.external_forces import ExternalForceSetTimeSeries, ExternalForceSetVariables
from .models.biorbd.holonomic_biorbd_model import HolonomicBiorbdModel
from .models.biorbd.multi_biorbd_model import MultiBiorbdModel
from .models.biorbd.stochastic_biorbd_model import StochasticBiorbdModel
Expand Down
51 changes: 26 additions & 25 deletions bioptim/dynamics/configure_new_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def __init__(
nlp,
as_states: bool,
as_controls: bool,
as_states_dot: bool = False,
as_algebraic_states: bool = False,
fatigue: FatigueList = None,
combine_name: str = None,
Expand All @@ -40,8 +39,6 @@ def __init__(
A reference to the phase
as_states: bool
If the new variable should be added to the state variable set
as_states_dot: bool
If the new variable should be added to the state_dot variable set
as_controls: bool
If the new variable should be added to the control variable set
as_algebraic_states: bool
Expand All @@ -64,7 +61,6 @@ def __init__(
self.nlp = nlp
self.as_states = as_states
self.as_controls = as_controls
self.as_states_dot = as_states_dot
self.as_algebraic_states = as_algebraic_states
self.fatigue = fatigue
self.combine_name = combine_name
Expand Down Expand Up @@ -184,10 +180,6 @@ def _declare_variable_scaling(self):
self.nlp.x_scaling.add(
self.name, scaling=np.ones(len(self.nlp.variable_mappings[self.name].to_first.map_idx))
)
if self.as_states_dot and self.name not in self.nlp.xdot_scaling:
self.nlp.xdot_scaling.add(
self.name, scaling=np.ones(len(self.nlp.variable_mappings[self.name].to_first.map_idx))
)
if self.as_controls and self.name not in self.nlp.u_scaling:
self.nlp.u_scaling.add(
self.name, scaling=np.ones(len(self.nlp.variable_mappings[self.name].to_first.map_idx))
Expand Down Expand Up @@ -217,6 +209,7 @@ def _declare_legend(self):

def _declare_cx_and_plot(self):
if self.as_states:
# States
for node_index in range(
self.nlp.n_states_nodes if self.nlp.phase_dynamics == PhaseDynamics.ONE_PER_NODE else 1
):
Expand All @@ -243,6 +236,21 @@ def _declare_cx_and_plot(self):
combine_to=self.combine_name,
)

# States dot
for node_index in range(
self.nlp.n_states_nodes if self.nlp.phase_dynamics == PhaseDynamics.ONE_PER_NODE else 1
):
n_cx = self.nlp.ode_solver.n_required_cx + 2
cx_scaled = self.define_cx_scaled(n_col=n_cx, node_index=node_index)
cx = self.define_cx_unscaled(cx_scaled, np.ones_like(self.nlp.x_scaling[self.name].scaling))
self.nlp.states_dot.append(
self.name,
cx,
cx_scaled,
self.nlp.variable_mappings[self.name],
node_index,
)

if self.as_controls:
for node_index in range(
self.nlp.n_controls_nodes if self.nlp.phase_dynamics == PhaseDynamics.ONE_PER_NODE else 1
Expand Down Expand Up @@ -276,21 +284,6 @@ def _declare_cx_and_plot(self):
),
)

if self.as_states_dot:
for node_index in range(
self.nlp.n_states_nodes if self.nlp.phase_dynamics == PhaseDynamics.ONE_PER_NODE else 1
):
n_cx = self.nlp.ode_solver.n_required_cx + 2
cx_scaled = self.define_cx_scaled(n_col=n_cx, node_index=node_index)
cx = self.define_cx_unscaled(cx_scaled, self.nlp.xdot_scaling[self.name].scaling)
self.nlp.states_dot.append(
self.name,
cx,
cx_scaled,
self.nlp.variable_mappings[self.name],
node_index,
)

if self.as_algebraic_states:
for node_index in range(
self.nlp.n_states_nodes if self.nlp.phase_dynamics == PhaseDynamics.ONE_PER_NODE else 1
Expand Down Expand Up @@ -403,7 +396,13 @@ def _manage_fatigue_to_new_variable(

if split_controls:
NewVariableConfiguration(
var_names_with_suffix[-1], name_elements, ocp, nlp, as_states, as_controls, skip_plot=True
var_names_with_suffix[-1],
name_elements,
ocp,
nlp,
as_states=as_states,
as_controls=as_controls,
skip_plot=True,
)
nlp.plot[f"{var_names_with_suffix[-1]}_controls"] = CustomPlot(
lambda t0, phases_dt, node_idx, x, u, p, a, d, key: (
Expand All @@ -428,7 +427,9 @@ def _manage_fatigue_to_new_variable(

for p, params in enumerate(fatigue_suffix):
name_tp = f"{var_names_with_suffix[-1]}_{params}"
NewVariableConfiguration(name_tp, name_elements, ocp, nlp, True, False, skip_plot=True)
NewVariableConfiguration(
name_tp, name_elements, ocp, nlp, as_states=True, as_controls=False, skip_plot=True
)
nlp.plot[name_tp] = CustomPlot(
lambda t0, phases_dt, node_idx, x, u, p, a, d, key, mod: (
mod * x[nlp.states.key_index(key), :] if x.any() else np.ndarray((len(name_elements), 1)) * np.nan
Expand Down
Loading
Loading