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

Fixing some problem MULTIPROCESS_SERVER #888

Merged
merged 13 commits into from
Aug 8, 2024
3 changes: 2 additions & 1 deletion bioptim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
from .limits.multinode_constraint import MultinodeConstraintFcn, MultinodeConstraintList, MultinodeConstraint
from .limits.multinode_objective import MultinodeObjectiveFcn, MultinodeObjectiveList, MultinodeObjective
from .limits.objective_functions import ObjectiveFcn, ObjectiveList, Objective, ParameterObjectiveList
from .limits.path_conditions import BoundsList, InitialGuessList
from .limits.path_conditions import BoundsList, InitialGuessList, Bounds, InitialGuess
from .limits.fatigue_path_conditions import FatigueBounds, FatigueInitialGuess
from .limits.penalty_controller import PenaltyController
from .limits.penalty_helpers import PenaltyHelpers
Expand Down Expand Up @@ -231,4 +231,5 @@
from .optimization.problem_type import SocpType
from .misc.casadi_expand import lt, le, gt, ge, if_else, if_else_zero

from .gui.plot import CustomPlot
from .gui.online_callback_server import PlottingServer
3 changes: 2 additions & 1 deletion bioptim/examples/getting_started/pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def main():

# --- Solve the ocp --- #
# Default is OnlineOptim.MULTIPROCESS on Linux, OnlineOptim.MULTIPROCESS_SERVER on Windows and None on MacOS
sol = ocp.solve(Solver.IPOPT(show_online_optim=OnlineOptim.DEFAULT))
# To see the graphs on MacOS, one must run the server manually (see resources/plotting_server.py)
sol = ocp.solve(Solver.IPOPT(online_optim=OnlineOptim.DEFAULT))

# --- Show the results graph --- #
sol.print_cost()
Expand Down
2 changes: 1 addition & 1 deletion bioptim/gui/online_callback_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class OnlineCallbackAbstract(Callback, ABC):
Send the current data to the plotter
"""

def __init__(self, ocp, opts: dict = None, show_options: dict = None):
def __init__(self, ocp, opts: dict = None, **show_options):
"""
Parameters
----------
Expand Down
4 changes: 2 additions & 2 deletions bioptim/gui/online_callback_multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class OnlineCallbackMultiprocess(OnlineCallbackAbstract):
The multiprocessing placeholder
"""

def __init__(self, ocp, opts: dict = None, show_options: dict = None):
super(OnlineCallbackMultiprocess, self).__init__(ocp, opts, show_options)
def __init__(self, ocp, opts: dict = None, **show_options):
super(OnlineCallbackMultiprocess, self).__init__(ocp, opts, **show_options)

self.queue = mp.Queue()
self.plotter = self.ProcessPlotter(self.ocp)
Expand Down
9 changes: 7 additions & 2 deletions bioptim/gui/online_callback_multiprocess_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .online_callback_server import PlottingServer, OnlineCallbackServer


def _start_as_multiprocess_internal(**kwargs):
def _start_server_internal(**kwargs):
"""
Starts the server (necessary for multiprocessing), this method should not be called directly, apart from
run_as_multiprocess
Expand All @@ -26,7 +26,12 @@ def __init__(self, *args, **kwargs):
"""
host = kwargs["host"] if "host" in kwargs else None
port = kwargs["port"] if "port" in kwargs else None
process = Process(target=_start_as_multiprocess_internal, kwargs={"host": host, "port": port})
log_level = None
if "log_level" in kwargs:
log_level = kwargs["log_level"]
del kwargs["log_level"]

process = Process(target=_start_server_internal, kwargs={"host": host, "port": port, "log_level": log_level})
process.start()

super(OnlineCallbackMultiprocessServer, self).__init__(*args, **kwargs)
Loading
Loading