1616
1717from __future__ import annotations
1818
19+ import concurrent .futures as cf
1920import multiprocessing
2021import multiprocessing .pool
2122from collections .abc import Sequence
@@ -46,7 +47,7 @@ def z_phase_calibration_workflow(
4647 cycle_depths : Sequence [int ] = tuple (np .arange (3 , 100 , 20 )),
4748 random_state : cirq .RANDOM_STATE_OR_SEED_LIKE = None ,
4849 atol : float = 1e-3 ,
49- num_workers_or_pool : int | multiprocessing .pool .Pool = - 1 ,
50+ num_workers_or_pool : int | multiprocessing .pool .Pool | cf . Executor = - 1 ,
5051 pairs : Sequence [tuple [cirq .GridQubit , cirq .GridQubit ]] | None = None ,
5152 tags : Sequence [Any ] = (),
5253) -> tuple [xeb_fitting .XEBCharacterizationResult , pd .DataFrame ]:
@@ -81,7 +82,7 @@ def z_phase_calibration_workflow(
8182 cycle_depths: The cycle depths to use.
8283 random_state: The random state to use.
8384 atol: Absolute tolerance to be used by the minimizer.
84- num_workers_or_pool: An optional multi-processing pool or number of workers.
85+ num_workers_or_pool: An optional pool or number of workers.
8586 A zero value means no multiprocessing.
8687 A positive integer value will create a pool with the given number of workers.
8788 A negative value will create pool with maximum number of workers.
@@ -92,12 +93,12 @@ def z_phase_calibration_workflow(
9293 - A `pd.DataFrame` comparing the before and after fidelities.
9394 """
9495
95- pool : multiprocessing .pool .Pool | None = None
96+ pool : multiprocessing .pool .Pool | cf . Executor | None = None
9697 local_pool = False
9798 if isinstance (num_workers_or_pool , multiprocessing .pool .Pool ):
9899 pool = num_workers_or_pool # pragma: no cover
99100 elif num_workers_or_pool != 0 :
100- pool = multiprocessing . Pool (num_workers_or_pool if num_workers_or_pool > 0 else None )
101+ pool = cf . ThreadPoolExecutor (num_workers_or_pool if num_workers_or_pool > 0 else None )
101102 local_pool = True
102103
103104 fids_df_0 , circuits , sampled_df = parallel_xeb_workflow (
@@ -143,8 +144,8 @@ def z_phase_calibration_workflow(
143144 )
144145
145146 if local_pool :
146- assert isinstance (pool , multiprocessing . pool . Pool )
147- pool .close ()
147+ assert isinstance (pool , cf . Executor )
148+ pool .shutdown ()
148149 return result , before_after
149150
150151
@@ -159,7 +160,7 @@ def calibrate_z_phases(
159160 cycle_depths : Sequence [int ] = tuple (np .arange (3 , 100 , 20 )),
160161 random_state : cirq .RANDOM_STATE_OR_SEED_LIKE = None ,
161162 atol : float = 1e-3 ,
162- num_workers_or_pool : int | multiprocessing .pool .Pool = - 1 ,
163+ num_workers_or_pool : int | multiprocessing .pool .Pool | cf . Executor = - 1 ,
163164 pairs : Sequence [tuple [cirq .GridQubit , cirq .GridQubit ]] | None = None ,
164165 tags : Sequence [Any ] = (),
165166) -> dict [tuple [cirq .Qid , cirq .Qid ], cirq .PhasedFSimGate ]:
0 commit comments