Skip to content

Commit

Permalink
SacessOptimizer: Fix occasional deadlocks (#1204)
Browse files Browse the repository at this point in the history
Previously, it could happen that SacessOptimizer runs into a deadlock due to a copied thread. Fixed here.
  • Loading branch information
dweindl authored Nov 21, 2023
1 parent a6e300f commit 27595f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pypesto/optimize/ess/sacess.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def minimize(
logging_thread = logging.handlers.QueueListener(
multiprocessing.Queue(-1), logging_handler
)
logging_thread.start()

# shared memory manager to handle shared state
# (simulates the sacess manager process)
Expand Down Expand Up @@ -183,6 +182,11 @@ def minimize(
]
for p in worker_processes:
p.start()

# start logging thread only AFTER starting the worker processes
# to prevent deadlocks
logging_thread.start()

# wait for finish
for p in worker_processes:
p.join()
Expand Down
11 changes: 9 additions & 2 deletions test/optimize/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ def test_history_beats_optimizer():
)


@pytest.mark.filterwarnings(
"ignore:Passing `startpoint_method` directly is deprecated.*:DeprecationWarning"
)
@pytest.mark.parametrize("ess_type", ["ess", "cess", "sacess"])
@pytest.mark.parametrize("local_optimizer", [None, optimize.FidesOptimizer()])
@pytest.mark.flaky(reruns=3)
Expand Down Expand Up @@ -485,8 +488,12 @@ def test_ess(problem, local_optimizer, ess_type, request):
):
# Not pickleable - incompatible with CESS
pytest.skip()
# SACESS with 4 processes
ess_init_args = get_default_ess_options(num_workers=4, dim=problem.dim)
# SACESS with 12 processes
# We use a higher number than reasonable to be more likely to trigger
# any potential race conditions (gh-1204)
ess_init_args = get_default_ess_options(
num_workers=12, dim=problem.dim
)
for x in ess_init_args:
x['local_optimizer'] = local_optimizer
ess = SacessOptimizer(
Expand Down

0 comments on commit 27595f5

Please sign in to comment.