Skip to content

Commit

Permalink
blacked
Browse files Browse the repository at this point in the history
  • Loading branch information
EveCharbie committed Feb 2, 2024
1 parent 0cea469 commit cc355f7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
12 changes: 7 additions & 5 deletions bioptim/gui/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,14 @@ def legend_without_duplicate_labels(ax):
else:
nb_subplots = max(
[
max(
len(nlp.plot[variable].phase_mappings.to_first.map_idx),
max(nlp.plot[variable].phase_mappings.to_first.map_idx) + 1,
(
max(
len(nlp.plot[variable].phase_mappings.to_first.map_idx),
max(nlp.plot[variable].phase_mappings.to_first.map_idx) + 1,
)
if variable in nlp.plot
else 0
)
if variable in nlp.plot
else 0
for nlp in self.ocp.nlp
]
)
Expand Down
10 changes: 7 additions & 3 deletions tests/shard3/test_initial_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ def test_initial_guess_error_messages(phase_dynamics):
objective_functions=objective_functions,
)

with pytest.raises(ValueError, match="bad_key is not a state variable, please check for typos in the declaration of x_init"):
with pytest.raises(
ValueError, match="bad_key is not a state variable, please check for typos in the declaration of x_init"
):
x_init = InitialGuessList()
x_init.add("bad_key", [1, 2])
bio_model = BiorbdModel(biorbd_model_path)
Expand All @@ -350,7 +352,9 @@ def test_initial_guess_error_messages(phase_dynamics):
)

del bio_model # This is to fix a memory bug
with pytest.raises(ValueError, match="bad_key is not a control variable, please check for typos in the declaration of u_init"):
with pytest.raises(
ValueError, match="bad_key is not a control variable, please check for typos in the declaration of u_init"
):
u_init = InitialGuessList()
u_init.add("bad_key", [1, 2])
bio_model = BiorbdModel(biorbd_model_path)
Expand All @@ -361,4 +365,4 @@ def test_initial_guess_error_messages(phase_dynamics):
phase_time=1,
u_init=u_init,
objective_functions=objective_functions,
)
)
17 changes: 13 additions & 4 deletions tests/shard4/test_update_bounds_and_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,36 @@ def test_double_update_bounds_and_init(phase_dynamics):
ocp.update_bounds(x_init, u_init)
with pytest.raises(RuntimeError, match="u_bounds should be built from a BoundsList"):
ocp.update_bounds(None, u_init)
with pytest.raises(ValueError, match="bad_key is not a state variable, please check for typos in the declaration of x_bounds"):
with pytest.raises(
ValueError, match="bad_key is not a state variable, please check for typos in the declaration of x_bounds"
):
x_bounds = BoundsList()
x_bounds.add("bad_key", [1, 2])
ocp.update_bounds(x_bounds, u_bounds)
with pytest.raises(ValueError, match="bad_key is not a control variable, please check for typos in the declaration of u_bounds"):
with pytest.raises(
ValueError, match="bad_key is not a control variable, please check for typos in the declaration of u_bounds"
):
x_bounds = BoundsList()
x_bounds["q"] = -np.ones((nq, 1)), np.ones((nq, 1))
u_bounds = BoundsList()
u_bounds.add("bad_key", [1, 2])
ocp.update_bounds(x_bounds, u_bounds)
with pytest.raises(ValueError, match="bad_key is not a state variable, please check for typos in the declaration of x_init"):
with pytest.raises(
ValueError, match="bad_key is not a state variable, please check for typos in the declaration of x_init"
):
x_init = InitialGuessList()
x_init.add("bad_key", [1, 2])
ocp.update_initial_guess(x_init, u_init)
with pytest.raises(ValueError, match="bad_key is not a control variable, please check for typos in the declaration of u_init"):
with pytest.raises(
ValueError, match="bad_key is not a control variable, please check for typos in the declaration of u_init"
):
x_init = InitialGuessList()
x_init["q"] = 0.5 * np.ones((nq, 1))
u_init = InitialGuessList()
u_init.add("bad_key", [1, 2])
ocp.update_initial_guess(x_init, u_init)


@pytest.mark.parametrize("phase_dynamics", [PhaseDynamics.SHARED_DURING_THE_PHASE, PhaseDynamics.ONE_PER_NODE])
def test_update_bounds_and_init_with_param(phase_dynamics):
def my_parameter_function(bio_model, value, extra_value):
Expand Down

0 comments on commit cc355f7

Please sign in to comment.