add env setup for runtime to enable multiprocessing parameter search by joblib, closes #23

This commit is contained in:
2025-04-17 11:55:01 +02:00
parent a1057fc78b
commit 4072b97012
9 changed files with 163 additions and 21 deletions

View File

@@ -1,23 +1,22 @@
import multiprocessing
import os
import sys
from pathlib import Path
# import multiprocessing
# import os
# import sys
# from pathlib import Path
# os.environ["JOBLIB_DISABLE_SHARED_MEMORY"] = "1"
interpreter = r"A:\Arbeitsaufgaben\Delta-Barth\cs-wrapper\dopt.DeltaBarth\python\python.exe"
intp_pth = Path(interpreter).resolve()
# interpreter = r"A:\Arbeitsaufgaben\Delta-Barth\cs-wrapper\dopt.DeltaBarth\python\python.exe"
# intp_pth = Path(interpreter).resolve()
assert intp_pth.exists(), f"interpreter path seems not to exist: {intp_pth}"
# assert intp_pth.exists(), f"interpreter path seems not to exist: {intp_pth}"
# multiprocessing.set_executable(str(intp_pth))
# setattr(sys, "frozen", True) # !! causes termination
# sys.executable = str(intp_pth)
setattr(sys, "executable", str(intp_pth))
setattr(sys, "_base_executable", str(intp_pth))
# setattr(sys, "executable", str(intp_pth))
# setattr(sys, "_base_executable", str(intp_pth))
# multiprocessing.set_start_method("spawn", force=True)
target = Path(r"A:\Arbeitsaufgaben\Delta-Barth\cs-wrapper\dopt.DeltaBarth")
file = target / "executed.txt"
file.touch()
# target = Path(r"A:\Arbeitsaufgaben\Delta-Barth\cs-wrapper\dopt.DeltaBarth")
# file = target / "executed.txt"
# file.touch()

33
src/delta_barth/_env.py Normal file
View File

@@ -0,0 +1,33 @@
from __future__ import annotations
import sys
from pathlib import Path
from typing import Final
from dopt_basics import io
PY_RUNTIME_FOLDER: Final[str] = "python"
def prepare_env(
lib_path: Path,
) -> Path | None:
pyrt_folder = io.search_folder_path(
starting_path=lib_path,
stop_folder_name=PY_RUNTIME_FOLDER,
return_inclusive=True,
)
if pyrt_folder is None:
return None
pth_interpreter = pyrt_folder / "python.exe"
if not pth_interpreter.exists():
raise FileNotFoundError(
f"dopt-delta-barth seems to be deployed in a standalone runtime, "
f"but the interpreter was not found under: {pth_interpreter}"
)
setattr(sys, "executable", str(pth_interpreter))
setattr(sys, "_base_executable", str(pth_interpreter))
return pyrt_folder

View File

@@ -38,6 +38,7 @@ from delta_barth.constants import (
DEFAULT_DB_ERR_CODE,
DUMMY_DATA_PATH,
FEATURES_SALES_PROGNOSIS,
MAX_NUM_WORKERS,
SALES_MIN_NUM_DATAPOINTS,
)
from delta_barth.errors import STATUS_HANDLER, wrap_result
@@ -302,7 +303,7 @@ def _process_sales(
params,
scoring="neg_mean_absolute_error",
cv=kfold,
n_jobs=-1,
n_jobs=MAX_NUM_WORKERS,
n_iter=100,
verbose=0,
)