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

[RTR] StochastiOCP merge #715

Merged
merged 57 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
23d5104
init and SOCP class
EveCharbie Jul 11, 2023
b1c4b2f
configure_problem
EveCharbie Jul 11, 2023
31456c2
dynamics
EveCharbie Jul 11, 2023
ceac023
examples
EveCharbie Jul 11, 2023
55cbe6e
model
EveCharbie Jul 11, 2023
5c07c92
interface + solver_options
EveCharbie Jul 11, 2023
ba924c0
penalty functions
EveCharbie Jul 11, 2023
2b42bfd
penalty controller + options
EveCharbie Jul 11, 2023
a7dc678
nlp + ocp
EveCharbie Jul 11, 2023
e30d3e0
optimization vector (not sure of this merge)
EveCharbie Jul 11, 2023
fdae6d1
problem type
EveCharbie Jul 11, 2023
01a74b5
solution (not sure of this merge)
EveCharbie Jul 11, 2023
0a36930
added test
EveCharbie Jul 11, 2023
c385e58
solve ivp
EveCharbie Jul 11, 2023
0574c20
forgot dynamics and integrator
EveCharbie Jul 11, 2023
e4c6f7d
updated examples
EveCharbie Jul 11, 2023
f1418ff
fixed bounds
EveCharbie Jul 11, 2023
0da11bc
dissected OCP into smaller functions
EveCharbie Jul 11, 2023
b9db0cf
copy-pasting error fix
EveCharbie Jul 12, 2023
4f5e424
Merge remote-tracking branch 'pyomeca/master' into StochasticOCP_merge
EveCharbie Jul 12, 2023
a5d4251
Problem here!
EveCharbie Jul 12, 2023
595ea0c
fixed the graphs
EveCharbie Jul 12, 2023
1f05943
updates torque_driven example
EveCharbie Jul 12, 2023
545a005
fixed chech_onditionning
EveCharbie Jul 12, 2023
1257a97
generalized to all integrators
EveCharbie Jul 12, 2023
93d8acf
fixed plot tests
EveCharbie Jul 12, 2023
749e3b5
fixed some tests
EveCharbie Jul 12, 2023
5a2076c
fixed solution
EveCharbie Jul 12, 2023
5bce6eb
test_all_examples passes
EveCharbie Jul 12, 2023
95782e3
fixed tests up to custom_model
EveCharbie Jul 12, 2023
a46076d
fixed tests up to mhe
EveCharbie Jul 12, 2023
797d041
fixed some more tests (up to penalty)
EveCharbie Jul 12, 2023
253946e
blacked
EveCharbie Jul 12, 2023
4004e44
moved function to understand
EveCharbie Jul 13, 2023
a2cc72a
fixed tests
EveCharbie Jul 14, 2023
7074121
blacked
EveCharbie Jul 14, 2023
c599dfb
cleaned example + refactor
EveCharbie Jul 14, 2023
cb696db
nlp_scaling_methods works again
EveCharbie Jul 14, 2023
24ad9ae
made it understandable (doc + name changes)
EveCharbie Jul 14, 2023
a8c0f51
made requested changes
EveCharbie Jul 14, 2023
21844e8
Merge remote-tracking branch 'pyomeca/master' into StochasticOCP_merge
EveCharbie Jul 14, 2023
de63b71
blacked
EveCharbie Jul 14, 2023
77aebcc
added a test for arm_reaching_torque_driven
EveCharbie Jul 14, 2023
e6fcde9
fixed plots
EveCharbie Jul 14, 2023
f1fa883
blacked
EveCharbie Jul 14, 2023
2e4c1d3
test mass_matrix + nleffects
EveCharbie Jul 14, 2023
6e6de63
blacked
EveCharbie Jul 14, 2023
1b615e0
fixed acados?
EveCharbie Jul 17, 2023
4c974c0
fixed last tests ?
EveCharbie Jul 17, 2023
37309af
error acados
EveCharbie Jul 17, 2023
6bb2632
blacked
EveCharbie Jul 17, 2023
50ce6e2
added doc to the readme
EveCharbie Jul 17, 2023
066e0f9
Merge remote-tracking branch 'origin/StochasticOCP_merge' into Stocha…
EveCharbie Jul 17, 2023
9188ab3
forgot g
EveCharbie Jul 17, 2023
e45bc11
fixed acados?
EveCharbie Jul 17, 2023
7ef44d4
blacked
EveCharbie Jul 17, 2023
377de7b
made requested changes
EveCharbie Jul 18, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ c_generated_code
# Bioptim files
bioptim/sandbox/
*.pkl

# Mac dev
*.DS_store
Binary file added OCP_equation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ As a tour guide that uses this binder, you can watch the `bioptim` workshop that
- [From the sources](#installing-from-the-sources-for-linux-mac-and-windows)
- [Installation complete](#installation-complete)

[Defining our optimal control problems](#defining-our-optimal-control-problems)

[A first practical example](#a-first-practical-example)
- [The import](#the-import)
- [Building the ocp](#building-the-ocp)
Expand Down Expand Up @@ -236,6 +238,19 @@ python setup.py install
Assuming everything went well, that is it!
You can already enjoy bioptimizing!

# Defining our optimal control problems
Here we will detail our implementation of optimal control problems and some definitions.
The mathematical transcription of the OCP is as follows:
![](OCP_equation.png)
The optimization variables are the states (x = variables that represent the state of the system at each node and that
are subject to continuity constraints), controls (u = decision variables defined at each node that have an effect on the system),
algebraic states (s = optimization variables that are defined at each node, but that are not subject to the
built-in continuity constraints), and parameters (p = optimization variables that are defined once per phase).
The state continuity constraints implementation may vary depending on the transcription of the problem (implicit vs explicit, direct multiple shooting vs direct collocations).

The cost function can include Mayer terms (function evaluated at one node) and Lagrange terms (functions integrated over the duration of the phase).
The optimization variables can be subject to equality and/or inequality constraints.

# A first practical example
The easiest way to learn `bioptim` is to dive into it.
So let's do that and build our first optimal control program together.
Expand Down
2 changes: 2 additions & 0 deletions bioptim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,6 @@
from .optimization.variable_scaling import VariableScalingList, VariableScaling
from .optimization.variational_optimal_control_program import VariationalOptimalControlProgram

from .optimization.stochastic_optimal_control_program import StochasticOptimalControlProgram
from .optimization.problem_type import SocpType
from .misc.casadi_expand import lt, le, gt, ge, if_else, if_else_zero
303 changes: 279 additions & 24 deletions bioptim/dynamics/configure_problem.py

Large diffs are not rendered by default.

19 changes: 17 additions & 2 deletions bioptim/dynamics/dynamics_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class DynamicsFunctions:
"""

@staticmethod
def custom(states: MX.sym, controls: MX.sym, parameters: MX.sym, nlp) -> DynamicsEvaluation:
def custom(
states: MX.sym, controls: MX.sym, parameters: MX.sym, stochastic_variables: MX.sym, nlp
) -> DynamicsEvaluation:
"""
Interface to custom dynamic function provided by the user.

Expand All @@ -65,13 +67,14 @@ def custom(states: MX.sym, controls: MX.sym, parameters: MX.sym, nlp) -> Dynamic
The defects of the implicit dynamics
"""

return nlp.dynamics_type.dynamic_function(states, controls, parameters, nlp)
return nlp.dynamics_type.dynamic_function(states, controls, parameters, stochastic_variables, nlp)

@staticmethod
def torque_driven(
states: MX.sym,
controls: MX.sym,
parameters: MX.sym,
stochastic_variables: MX.sym,
nlp,
with_contact: bool,
with_passive_torque: bool,
Expand Down Expand Up @@ -227,6 +230,7 @@ def torque_activations_driven(
states: MX.sym,
controls: MX.sym,
parameters: MX.sym,
stochastic_variables: MX.sym,
nlp,
with_contact: bool,
with_passive_torque: bool,
Expand Down Expand Up @@ -285,6 +289,7 @@ def torque_derivative_driven(
states: MX.sym,
controls: MX.sym,
parameters: MX.sym,
stochastic_variables: MX.sym,
nlp,
rigidbody_dynamics: RigidBodyDynamics,
with_contact: bool,
Expand Down Expand Up @@ -355,6 +360,7 @@ def forces_from_torque_driven(
states: MX.sym,
controls: MX.sym,
parameters: MX.sym,
stochastic_variables: MX.sym,
nlp,
with_passive_torque: bool = False,
with_ligament: bool = False,
Expand All @@ -370,6 +376,8 @@ def forces_from_torque_driven(
The controls of the system
parameters: MX.sym
The parameters of the system
stochastic_variables: MX.sym
The stochastic variables of the system
nlp: NonLinearProgram
The definition of the system
with_passive_torque: bool
Expand Down Expand Up @@ -400,6 +408,7 @@ def forces_from_torque_activation_driven(
states: MX.sym,
controls: MX.sym,
parameters: MX.sym,
stochastic_variables: MX.sym,
nlp,
with_passive_torque: bool = False,
with_ligament: bool = False,
Expand Down Expand Up @@ -445,6 +454,7 @@ def muscles_driven(
states: MX.sym,
controls: MX.sym,
parameters: MX.sym,
stochastic_variables: MX.sym,
nlp,
with_contact: bool,
with_passive_torque: bool = False,
Expand Down Expand Up @@ -580,6 +590,7 @@ def forces_from_muscle_driven(
states: MX.sym,
controls: MX.sym,
parameters: MX.sym,
stochastic_variables: MX.sym,
nlp,
with_passive_torque: bool = False,
with_ligament: bool = False,
Expand Down Expand Up @@ -626,6 +637,7 @@ def joints_acceleration_driven(
states: MX.sym,
controls: MX.sym,
parameters: MX.sym,
stochastic_variables: MX.sym,
nlp,
rigidbody_dynamics: RigidBodyDynamics = RigidBodyDynamics.ODE,
) -> DynamicsEvaluation:
Expand Down Expand Up @@ -892,6 +904,7 @@ def holonomic_torque_driven(
states: MX | SX,
controls: MX | SX,
parameters: MX | SX,
stochastic_variables: MX | SX,
nlp: NonLinearProgram,
) -> DynamicsEvaluation:
"""
Expand All @@ -905,6 +918,8 @@ def holonomic_torque_driven(
The controls of the system
parameters: MX | SX
The parameters acting on the system
stochastic_variables: MX | SX
The stochastic variables of the system
nlp: NonLinearProgram
A reference to the phase

Expand Down
Loading