Skip to content

Commit

Permalink
Merge pull request #888 from pariterre/plot_server
Browse files Browse the repository at this point in the history
Fixing some problem MULTIPROCESS_SERVER (#888)

Co-Authored-By: eve-mac <[email protected]>
  • Loading branch information
Ipuch and EveCharbie authored Aug 8, 2024
2 parents 7279b82 + 7f4b0b0 commit ddfbcd8
Show file tree
Hide file tree
Showing 13 changed files with 392 additions and 307 deletions.
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

0 comments on commit ddfbcd8

Please sign in to comment.