Skip to content

Commit e78056b

Browse files
committed
debugging consecutive libE calls with gen_on_manager
1 parent c433ecb commit e78056b

4 files changed

Lines changed: 20 additions & 21 deletions

File tree

libensemble/comms/comms.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,6 @@ def result(self, timeout=None):
207207
raise RemoteException(self._exception.msg, self._exception.exc)
208208
return self._result
209209

210-
@staticmethod
211-
def _qcomm_main(comm, main, *args, **kwargs):
212-
"""Main routine -- handles return values and exceptions."""
213-
try:
214-
if not kwargs.get("user_function"):
215-
_result = main(comm, *args, **kwargs)
216-
else:
217-
_result = main(*args)
218-
comm.send(CommResult(_result))
219-
except Exception as e:
220-
comm.send(CommResultErr(str(e), format_exc()))
221-
raise e
222-
223210
@property
224211
def running(self):
225212
"""Check if the thread/process is running."""
@@ -233,6 +220,19 @@ def __exit__(self, etype, value, traceback):
233220
self.handle.join()
234221

235222

223+
def _qcomm_main(comm, main, *args, **kwargs):
224+
"""Main routine -- handles return values and exceptions."""
225+
try:
226+
if not kwargs.get("user_function"):
227+
_result = main(comm, *args, **kwargs)
228+
else:
229+
_result = main(*args)
230+
comm.send(CommResult(_result))
231+
except Exception as e:
232+
comm.send(CommResultErr(str(e), format_exc()))
233+
raise e
234+
235+
236236
class QCommThread(QCommLocal):
237237
"""Launch a user function in a thread with an attached QComm."""
238238

@@ -241,7 +241,7 @@ def __init__(self, main, nworkers, *args, **kwargs):
241241
self.outbox = thread_queue.Queue()
242242
super().__init__(self, main, *args, **kwargs)
243243
comm = QComm(self.inbox, self.outbox, nworkers)
244-
self.handle = Thread(target=QCommThread._qcomm_main, args=(comm, main) + args, kwargs=kwargs)
244+
self.handle = Thread(target=_qcomm_main, args=(comm, main) + args, kwargs=kwargs)
245245

246246
def terminate(self, timeout=None):
247247
"""Terminate the thread.
@@ -265,7 +265,7 @@ def __init__(self, main, nworkers, *args, **kwargs):
265265
self.outbox = Queue()
266266
super().__init__(self, main, *args, **kwargs)
267267
comm = QComm(self.inbox, self.outbox, nworkers)
268-
self.handle = Process(target=QCommProcess._qcomm_main, args=(comm, main) + args, kwargs=kwargs)
268+
self.handle = Process(target=_qcomm_main, args=(comm, main) + args, kwargs=kwargs)
269269

270270
def terminate(self, timeout=None):
271271
"""Terminate the process."""

libensemble/comms/logs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def manager_logging_config(specs={}):
203203
def exit_logger():
204204
stat_timer.stop()
205205
stat_logger.info(f"Exiting ensemble at: {stat_timer.date_end} Time Taken: {stat_timer.elapsed}")
206+
stat_logger.handlers[0].close()
206207

207208
# If closing logs - each libE() call will log to a new file.
208209
# fh.close()

libensemble/manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ def _kill_workers(self) -> None:
302302
"""Kills the workers"""
303303
for w in self.W["worker_id"]:
304304
self.wcomms[w].send(STOP_TAG, MAN_SIGNAL_FINISH)
305+
if w == 0:
306+
self.wcomms[0].result()
307+
self.wcomms[0] = None
305308

306309
# --- Checkpointing logic
307310

@@ -691,6 +694,7 @@ def run(self, persis_info: dict) -> (dict, int, int):
691694
finally:
692695
# Return persis_info, exit_flag, elapsed time
693696
result = self._final_receive_and_kill(persis_info)
697+
self.wcomms = None
694698
sys.stdout.flush()
695699
sys.stderr.flush()
696700
return result

libensemble/tests/functionality_tests/test_GPU_gen_resources.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@
4242
from libensemble.sim_funcs.var_resources import gpu_variable_resources_from_gen as sim_f
4343
from libensemble.tools import add_unique_random_streams, parse_args
4444

45-
# TODO: multiple libE calls with gen-on-manager currently not supported with spawn on macOS
46-
if sys.platform == "darwin":
47-
from multiprocessing import set_start_method
48-
49-
set_start_method("fork", force=True)
50-
5145
# from libensemble import logger
5246
# logger.set_level("DEBUG") # For testing the test
5347

0 commit comments

Comments
 (0)