Skip to content

Commit

Permalink
Add should_run_in_parallel to public API
Browse files Browse the repository at this point in the history
The function was added in a stable manner to enable backport to the 1.1
series, but from 1.2 onwards, we want this to be part of the public
interface so that others can rely on it too.
  • Loading branch information
jakelishman committed May 15, 2024
1 parent b12e9ec commit 0bdea9c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions qiskit/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
.. autofunction:: local_hardware_info
.. autofunction:: is_main_process
.. autofunction:: should_run_in_parallel
A helper function for calling a custom function with Python
:class:`~concurrent.futures.ProcessPoolExecutor`. Tasks can be executed in parallel using this function.
Expand Down
4 changes: 2 additions & 2 deletions qiskit/utils/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def parallel_map( # pylint: disable=dangerous-default-value
result = [task(value, *task_args, **task_kwargs) for value in values]
This will parallelise the results if the number of ``values`` is greater than one, and the
current system configuration permits parallelization.
This will parallelise the results if the number of ``values`` is greater than one and
:func:`should_run_in_parallel` returns ``True``. If not, it will run in serial.
Args:
task (func): Function that is to be called for each value in ``values``.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
features_misc:
- |
A new function, :func:`qiskit.utils.should_run_in_parallel`, is available to determine whether
:func:`.parallel_map` will choose to run in parallel or degrade to running in serial. This
decision is dependent on how many CPUs are available to Qiskit, what the :mod:`multiprocessing`
start method is, how many processes were requested.

0 comments on commit 0bdea9c

Please sign in to comment.