Skip to content

Commit 27f4d6d

Browse files
Augustin-Zidekcopybara-github
authored andcommitted
Make the num_cpus function compatible with platforms without os.sched_getaffinity (e.g. MacOS)
PiperOrigin-RevId: 948990027 Change-Id: I46bba29bbd0a9a160063dc885ac57675f56c9790
1 parent fd39d2c commit 27f4d6d

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

run_alphafold.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,20 @@
231231
'PDB sequence database path, used for template search.',
232232
)
233233

234+
235+
def _num_cpus_for_msa_tools() -> int:
236+
try:
237+
# Unfortunately, os.process_cpu_count() is only available in Python 3.13+.
238+
num_cpus = len(os.sched_getaffinity(0))
239+
except AttributeError:
240+
num_cpus = os.cpu_count() # MacOS doesn't have os.sched_getaffinity().
241+
return min(num_cpus if num_cpus is not None else 8, 8)
242+
243+
234244
# Number of CPUs to use for MSA tools.
235245
_JACKHMMER_N_CPU = flags.DEFINE_integer(
236246
'jackhmmer_n_cpu',
237-
# Unfortunately, os.process_cpu_count() is only available in Python 3.13+.
238-
min(len(os.sched_getaffinity(0)), 8),
247+
_num_cpus_for_msa_tools(),
239248
'Number of CPUs to use for Jackhmmer. Defaults to min(cpu_count, 8). Going'
240249
' above 8 CPUs provides very little additional speedup.',
241250
lower_bound=0,
@@ -250,8 +259,7 @@
250259
)
251260
_NHMMER_N_CPU = flags.DEFINE_integer(
252261
'nhmmer_n_cpu',
253-
# Unfortunately, os.process_cpu_count() is only available in Python 3.13+.
254-
min(len(os.sched_getaffinity(0)), 8),
262+
_num_cpus_for_msa_tools(),
255263
'Number of CPUs to use for Nhmmer. Defaults to min(cpu_count, 8). Going'
256264
' above 8 CPUs provides very little additional speedup.',
257265
lower_bound=0,

0 commit comments

Comments
 (0)