-
Notifications
You must be signed in to change notification settings - Fork 46
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
Multi-start module #555
Multi-start module #555
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 5 files reviewed, 1 unresolved discussion (waiting on @EveCharbie)
bioptim/optimization/multi_start.py
line 67 at r1 (raw file):
else: list_out += list_now
list_out = [instance for instance in product(*self.args_dict.values())]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: all files reviewed, 12 unresolved discussions (waiting on @EveCharbie)
bioptim/examples/getting_started/example_multistart.py
line 113 at r1 (raw file):
def solve_ocp(args: list = None):
Remove this function
Code quote:
def solve_ocp(args: list = None):
bioptim/examples/getting_started/example_multistart.py
line 130 at r1 (raw file):
biorbd_model_path = args[0] final_time = args[1]
All this should be in prepare_multistart (as suggested later)
Code quote:
biorbd_model_path = args[0]
final_time = args[1]
n_shooting = args[2]
seed = args[3]
ocp = prepare_ocp(biorbd_model_path, final_time, n_shooting)
ocp.add_plot_penalty(CostType.ALL)
sol = ocp.solve(Solver.IPOPT(show_online_optim=False)) # You cannot use show_online_optim with multi-start
bioptim/examples/getting_started/example_multistart.py
line 136 at r1 (raw file):
ocp = prepare_ocp(biorbd_model_path, final_time, n_shooting) ocp.add_plot_penalty(CostType.ALL) sol = ocp.solve(Solver.IPOPT(show_online_optim=False)) # You cannot use show_online_optim with multi-start
This should be called by the run()
Code quote:
sol = ocp.solve(Solver.IPOPT(show_online_optim=False)) # You cannot use show_online_optim with multi-start
bioptim/examples/getting_started/example_multistart.py
line 137 at r1 (raw file):
ocp.add_plot_penalty(CostType.ALL) sol = ocp.solve(Solver.IPOPT(show_online_optim=False)) # You cannot use show_online_optim with multi-start ocp.save(sol, f"solutions/pendulum_multi_start_random{seed}.bo", stand_alone=True)
The user can do this with the output from .run()
Code quote:
ocp.save(sol, f"solutions/pendulum_multi_start_random{seed}.bo", stand_alone=True)
bioptim/examples/getting_started/example_multistart.py
line 144 at r1 (raw file):
solve_ocp, n_random=10, n_pools=4,
Suggestion:
ocp = solve_ocp(biorbd_model_path, final_time, n_shooting, seed=42)
ocp.add_plot_penalty(CostType.ALL)
return MultiStart(
ocp,
n_random=10,
n_pools=4,
)
bioptim/examples/getting_started/example_multistart.py
line 155 at r1 (raw file):
biorbd_model_path=["models/pendulum.bioMod"], final_time=[1], n_shooting=[30, 40, 50] ) multi_start.run()
This should returns all the solution
multi_start.solve(solver=Solver.IPOPT(show_online_optim=False))
Suggestion:
multi_start.solve(Solver.IPOPT(show_online_optim=False))
bioptim/optimization/multi_start.py
line 23 at r1 (raw file):
n_random: int = 1, n_pools: int = 1, args_dict: dict = None,
Suggestion:
def __init__(
self,
ocp,
n_random: int = 1,
n_pools: int = 1,
**kwargs,
):
bioptim/optimization/multi_start.py
line 38 at r1 (raw file):
""" self.solve_ocp = solve_ocp
self.ocp = ocp
self.solver = solver
bioptim/optimization/multi_start.py
line 41 at r1 (raw file):
self.n_random = n_random self.n_pools = n_pools self.args_dict = args_dict
Suggestion:
self.args_dict = **kwargs
bioptim/optimization/multi_start.py
line 79 at r1 (raw file):
""" with Pool(self.n_pools) as p: p.map(self.solve_ocp, self.combined_args_to_list)
Suggestion:
p.map(self.ocp.solve, self.combined_args_to_list)
tests/test_global_getting_started.py
line 1146 at r1 (raw file):
biorbd_model_path=[bioptim_folder + "/models/pendulum.bioMod"], final_time=[1], n_shooting=[5, 10] ) multi_start.run()
.solve()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not exactly what you asked for, but I think it respects the idea the most possible
Reviewable status: 3 of 5 files reviewed, 12 unresolved discussions (waiting on @Ipuch and @pariterre)
bioptim/examples/getting_started/example_multistart.py
line 113 at r1 (raw file):
Previously, pariterre (Pariterre) wrote…
Remove this function
Done.
bioptim/examples/getting_started/example_multistart.py
line 130 at r1 (raw file):
Previously, pariterre (Pariterre) wrote…
All this should be in prepare_multistart (as suggested later)
Done.
bioptim/examples/getting_started/example_multistart.py
line 136 at r1 (raw file):
Previously, pariterre (Pariterre) wrote…
This should be called by the
run()
Done.
bioptim/examples/getting_started/example_multistart.py
line 137 at r1 (raw file):
Previously, pariterre (Pariterre) wrote…
The user can do this with the output from
.run()
Not possible to return sol because it cannot be pickled.
bioptim/examples/getting_started/example_multistart.py
line 144 at r1 (raw file):
solve_ocp, n_random=10, n_pools=4,
I cannot put ocp since the arguments would be fixed, but I put prepare_ocp
bioptim/examples/getting_started/example_multistart.py
line 155 at r1 (raw file):
Previously, pariterre (Pariterre) wrote…
This should returns all the solution
multi_start.solve(solver=Solver.IPOPT(show_online_optim=False))
Done.
bioptim/optimization/multi_start.py
line 23 at r1 (raw file):
n_random: int = 1, n_pools: int = 1, args_dict: dict = None,
Done.
bioptim/optimization/multi_start.py
line 38 at r1 (raw file):
Previously, pariterre (Pariterre) wrote…
self.ocp = ocp
self.solver = solver
Done.
bioptim/optimization/multi_start.py
line 41 at r1 (raw file):
self.n_random = n_random self.n_pools = n_pools self.args_dict = args_dict
Done.
bioptim/optimization/multi_start.py
line 67 at r1 (raw file):
Previously, Ipuch (Pierre Puchaud) wrote…
from itertools import product
list_out = [instance for instance in product(*self.args_dict.values())]
Done
bioptim/optimization/multi_start.py
line 79 at r1 (raw file):
""" with Pool(self.n_pools) as p: p.map(self.solve_ocp, self.combined_args_to_list)
Done.
tests/test_global_getting_started.py
line 1146 at r1 (raw file):
Previously, pariterre (Pariterre) wrote…
.solve()
Done.
f26c550
to
780f33e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 4 files at r2, 1 of 1 files at r3.
Reviewable status: 4 of 6 files reviewed, 4 unresolved discussions (waiting on @EveCharbie and @Ipuch)
bioptim/examples/getting_started/example_multistart.py
line 85 at r3 (raw file):
u_bounds[1, :] = 0 # Prevent the model from actively rotate # To be changed when the issue on NoisedInitialGuess is fixed
TODO
bioptim/examples/getting_started/example_multistart.py
line 143 at r3 (raw file):
prepare_ocp, solver=Solver.IPOPT(show_online_optim=False), # You cannot use show_online_optim with multi-start callback_function=save_results,
post_optimization_callback=save_results,
Code quote:
callback_function
bioptim/optimization/multi_start.py
line 46 at r3 (raw file):
self.prepare_ocp = prepare_ocp self.solver = solver self.callback_function = callback_function
post_optimization_callback
Code quote:
.callback_function = callback_function
small steps
215b60f
to
ff72b50
Compare
@EveCharbie I rebased this PR to integrate the new tests. Please use reset --hard (don't merge) to move to that PR if you need to push something later. Call me if needed |
@EveCharbie |
Codecov ReportBase: 83.76% // Head: 80.47% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #555 +/- ##
==========================================
- Coverage 83.76% 80.47% -3.29%
==========================================
Files 91 95 +4
Lines 10155 10382 +227
==========================================
- Hits 8506 8355 -151
- Misses 1649 2027 +378
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r4, 2 of 2 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Ipuch)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Ipuch)
All Submissions:
New Feature Submissions:
black . -l120 --exclude "external/*"
)?Changes to Core Features:
This change is