From 64b180caf591ab303cb6a4b4a7a91162491fa0dc Mon Sep 17 00:00:00 2001 From: Timothy Willard <9395586+TimothyWillard@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:34:17 -0500 Subject: [PATCH] Change `max_workers` to 1 Attempt to diagnose CI failures by forcing `max_workers=1`. --- flepimop/gempyor_pkg/src/gempyor/outcomes.py | 2 ++ flepimop/gempyor_pkg/src/gempyor/seir.py | 1 + .../tests/parameters/test_parameters_class.py | 33 +++++++++++-------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/outcomes.py b/flepimop/gempyor_pkg/src/gempyor/outcomes.py index f0c60ca1c..d57765960 100644 --- a/flepimop/gempyor_pkg/src/gempyor/outcomes.py +++ b/flepimop/gempyor_pkg/src/gempyor/outcomes.py @@ -91,6 +91,8 @@ def onerun_delayframe_outcomes( load_ID: bool = False, sim_id2load: int = None, ): + np.random.seed(seed=sim_id2write) + with Timer("buildOutcome.structure"): parameters = read_parameters_from_config(modinf) diff --git a/flepimop/gempyor_pkg/src/gempyor/seir.py b/flepimop/gempyor_pkg/src/gempyor/seir.py index 77b303f2b..53d9017f0 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seir.py +++ b/flepimop/gempyor_pkg/src/gempyor/seir.py @@ -1,5 +1,6 @@ import itertools import logging +import random import time import numpy as np diff --git a/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py b/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py index 663b56e6a..c281dfbb2 100644 --- a/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py +++ b/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py @@ -1,6 +1,7 @@ from datetime import date from functools import partial from itertools import repeat +import multiprocessing as mp import pathlib from tempfile import NamedTemporaryFile from typing import Any, Callable @@ -717,32 +718,36 @@ def test_parameters_reduce(self) -> None: pass def test_reinitialize_parameters(self, tmp_path: pathlib.Path) -> None: + from concurrent.futures import ProcessPoolExecutor + mock_inputs = distribution_three_valid_parameter_factory(tmp_path) np.random.seed(123) params = mock_inputs.create_parameters_instance() - results = tqdm.contrib.concurrent.process_map( - sample_params, - repeat(params, times=6), - repeat(False, times=6), - max_workers=2, - disable=True, - ) + with ProcessPoolExecutor(max_workers=2, mp_context=mp.get_context("spawn")) as ex: + results = list( + ex.map( + sample_params, + repeat(params, times=6), + repeat(False, times=6), + ) + ) for i in range(1, len(results)): assert np.allclose(results[i - 1], results[i]) np.random.seed(123) - results_with_reinit = tqdm.contrib.concurrent.process_map( - sample_params, - repeat(params, times=6), - repeat(True, times=6), - max_workers=2, - disable=True, - ) + with ProcessPoolExecutor(max_workers=2, mp_context=mp.get_context("spawn")) as ex: + results_with_reinit = list( + ex.map( + sample_params, + repeat(params, times=6), + repeat(True, times=6), + ) + ) for i in range(1, len(results_with_reinit)): assert not np.allclose(results_with_reinit[i - 1], results_with_reinit[i])