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

SacessOptimizer: Fix occasional deadlocks #1204

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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