diff --git a/qiskit/utils/__init__.py b/qiskit/utils/__init__.py index 30935437ebf2..5c6c8e4d5550 100644 --- a/qiskit/utils/__init__.py +++ b/qiskit/utils/__init__.py @@ -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. diff --git a/qiskit/utils/parallel.py b/qiskit/utils/parallel.py index f87eeb815967..b1a199b62b7e 100644 --- a/qiskit/utils/parallel.py +++ b/qiskit/utils/parallel.py @@ -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``. diff --git a/releasenotes/notes/parallel-check-public-7faed5f3e20e1d03.yaml b/releasenotes/notes/parallel-check-public-7faed5f3e20e1d03.yaml new file mode 100644 index 000000000000..e2b7f6942f0d --- /dev/null +++ b/releasenotes/notes/parallel-check-public-7faed5f3e20e1d03.yaml @@ -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.