Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions bioptim/optimization/optimal_control_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,8 @@ def update_bounds(
)

for key in parameter_bounds.keys():
if parameter_bounds[key].type != InterpolationType.CONSTANT:
raise ValueError(f"Parameter bounds for '{key}' must use InterpolationType.CONSTANT")
self.parameter_bounds.add(key, parameter_bounds[key], phase=0)

for nlp in self.nlp:
Expand Down Expand Up @@ -1156,6 +1158,8 @@ def update_initial_guess(
)

for key in parameter_init.keys():
if parameter_init[key].type != InterpolationType.CONSTANT:
raise ValueError(f"Parameter initial guess for '{key}' must use InterpolationType.CONSTANT")
self.parameter_init.add(key, parameter_init[key], phase=0)

def add_plot(self, fig_name: Str, update_function: Callable, phase: Int = -1, **parameters: Any) -> None:
Expand Down
2 changes: 1 addition & 1 deletion bioptim/optimization/receding_horizon_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ def _initialize_one_cycle(self, dt: Float, states: AnyDict, controls: AnyDict, p
p_init.add(
key,
parameters_tp,
interpolation=InterpolationType.EACH_FRAME,
interpolation=InterpolationType.CONSTANT,
phase=0,
)

Expand Down
10 changes: 10 additions & 0 deletions tests/shard6/test_update_bounds_and_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ def my_parameter_function(bio_model, parameter: Parameter, extra_value):
parameter_bounds=parameter_bounds,
)

invalid_parameter_bounds = BoundsList()
invalid_parameter_bounds.add("gravity_z", min_bound=[g_min], max_bound=[g_max])
with pytest.raises(ValueError, match="Parameter bounds for 'gravity_z' must use InterpolationType.CONSTANT"):
ocp.update_bounds(parameter_bounds=invalid_parameter_bounds)

invalid_parameter_init = InitialGuessList()
invalid_parameter_init.add("gravity_z", [[g_init, g_init]], interpolation=InterpolationType.LINEAR)
with pytest.raises(ValueError, match="Parameter initial guess for 'gravity_z' must use InterpolationType.CONSTANT"):
ocp.update_initial_guess(parameter_init=invalid_parameter_init)

# Before modifying
expected = np.array([[0.1] + [-np.inf] * (nq * 2) * (ns + 1) + [-np.inf] * nq * ns + [g_min]]).T
npt.assert_almost_equal(ocp.bounds_vectors[0], expected)
Expand Down
Loading