Skip to content

Commit 23d76cb

Browse files
committed
Log how many processes are being used in multiprocessing
1 parent 8059a0c commit 23d76cb

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

clarite/modules/analyze/regression/glm_regression.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def __init__(
8888
self.min_n = min_n
8989
self.report_categorical_betas = report_categorical_betas
9090
self.standardize_data = standardize_data
91+
if self.process_num is None:
92+
process_num = multiprocessing.cpu_count()
9193
self.process_num = process_num
9294

9395
# Ensure the data output type is compatible
@@ -323,7 +325,8 @@ def run(self):
323325
else:
324326
click.echo(
325327
click.style(
326-
f"Running {len(rv_list):,} {rv_type} variables...", fg="green"
328+
f"Running {len(rv_list):,} {rv_type} variables using {self.process_num} processes...",
329+
fg="green",
327330
)
328331
)
329332

clarite/modules/analyze/regression/interaction_regression.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def __init__(
7777
# Custom init involving kwargs passed to this regression
7878
self.report_betas = report_betas
7979
self._process_interactions(interactions)
80+
if self.process_num is None:
81+
process_num = multiprocessing.cpu_count()
8082
self.process_num = process_num
8183

8284
# Use a list of results instead of the default dict
@@ -212,6 +214,13 @@ def _run_interaction_regression(
212214

213215
def run(self):
214216
"""Run a regression object, returning the results and logging any warnings/errors"""
217+
# Log how many interactions are being run using how many processes
218+
click.echo(
219+
click.style(
220+
f"Running {len(self.interactions):,} interactions using {self.process_num} processes...",
221+
fg="green",
222+
)
223+
)
215224
with multiprocessing.Pool(processes=self.process_num) as pool:
216225
run_result = pool.starmap(
217226
self._run_interaction,

clarite/modules/analyze/regression/weighted_glm_regression.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def __init__(
9696
min_n=min_n,
9797
report_categorical_betas=report_categorical_betas,
9898
standardize_data=standardize_data,
99+
process_num=process_num,
99100
)
100101

101102
# Custom init involving kwargs passed to this regression
@@ -283,7 +284,8 @@ def run(self):
283284
else:
284285
click.echo(
285286
click.style(
286-
f"Running {len(rv_list):,} {rv_type} variables...", fg="green"
287+
f"Running {len(rv_list):,} {rv_type} variables using {self.process_num} processes...",
288+
fg="green",
287289
)
288290
)
289291

0 commit comments

Comments
 (0)