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: Use cloudpickle for passing data to workers #1467

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
23 changes: 14 additions & 9 deletions pypesto/optimize/ess/sacess.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from uuid import uuid1
from warnings import warn

import cloudpickle
import numpy as np

import pypesto
Expand Down Expand Up @@ -242,9 +243,13 @@ def minimize(
name=f"{self.__class__.__name__}-worker-{i:02d}",
target=_run_worker,
args=(
worker,
problem,
startpoint_method,
cloudpickle.dumps(
(
worker,
problem,
startpoint_method,
),
),
logging_thread.queue,
),
)
Expand Down Expand Up @@ -782,16 +787,16 @@ def get_temp_result_filename(worker_idx: int, tmpdir: str | Path) -> str:
return str(Path(tmpdir, f"sacess-{worker_idx:02d}_tmp.h5").absolute())


def _run_worker(
worker: SacessWorker,
problem: Problem,
startpoint_method: StartpointMethod,
log_process_queue: multiprocessing.Queue,
):
def _run_worker(pickled_args: bytes, log_process_queue: multiprocessing.Queue):
"""Run the given SACESS worker.

Helper function as entrypoint for sacess worker processes.
"""
unpickled_args: tuple[
SacessWorker, Problem, StartpointMethod
] = cloudpickle.loads(pickled_args)
(worker, problem, startpoint_method) = unpickled_args

# different random seeds per process
np.random.seed((os.getpid() * int(time.time() * 1000)) % 2**32)

Expand Down