Asynchronously sample the state of the provided kernel `decorator` at the specified number of circuit executions (`shots_count`). When targeting a quantum platform with more than one QPU, the optional `qpu_id` allows for control over which QPU to enable. Will return a future whose r
(decorator,
*args,
shots_count=1000,
explicit_measurements=False,
noise_model=None,
qpu_id=0)
| 196 | |
| 197 | @trace.traced |
| 198 | def sample_async(decorator, |
| 199 | *args, |
| 200 | shots_count=1000, |
| 201 | explicit_measurements=False, |
| 202 | noise_model=None, |
| 203 | qpu_id=0): |
| 204 | """ |
| 205 | Asynchronously sample the state of the provided kernel `decorator` at the |
| 206 | specified number of circuit executions (`shots_count`). When targeting a |
| 207 | quantum platform with more than one QPU, the optional `qpu_id` allows for |
| 208 | control over which QPU to enable. Will return a future whose results can be |
| 209 | retrieved via `future.get()`. |
| 210 | |
| 211 | Args: |
| 212 | kernel (:class:`Kernel`): The :class:`Kernel` to execute `shots_count` |
| 213 | times on the QPU. |
| 214 | *arguments (Optional[Any]): The concrete values to evaluate the kernel |
| 215 | function at. Leave empty if the kernel doesn't accept any arguments. |
| 216 | shots_count (Optional[int]): The number of kernel executions on the |
| 217 | QPU. Defaults to 1000. Key-word only. |
| 218 | explicit_measurements (Optional[bool]): A flag to indicate whether or not |
| 219 | to concatenate measurements in execution order for the returned |
| 220 | sample result. |
| 221 | noise_model (Optional[`NoiseModel`]): The optional :class:`NoiseModel` |
| 222 | to add noise to the kernel execution on the simulator. Defaults to |
| 223 | an empty noise model. |
| 224 | `qpu_id` (Optional[int]): The optional identification for which QPU |
| 225 | on the platform to target. Defaults to zero. Key-word only. |
| 226 | |
| 227 | Returns: |
| 228 | :class:`AsyncSampleResult`: A dictionary containing the measurement count |
| 229 | results for the :class:`Kernel`. |
| 230 | """ |
| 231 | kernel = decorator |
| 232 | if not isa_kernel_decorator(decorator): |
| 233 | decorator = mk_decorator(decorator) |
| 234 | if decorator.formal_arity() != len(args): |
| 235 | raise RuntimeError( |
| 236 | "Invalid number of arguments passed to sample_async. " + |
| 237 | str(len(args)) + " given and " + str(decorator.formal_arity()) + |
| 238 | " expected.") |
| 239 | if (not isinstance(shots_count, int)) or (shots_count < 0): |
| 240 | raise RuntimeError( |
| 241 | "Invalid `shots_count`. Must be a non-negative number.") |
| 242 | if (decorator.return_type and |
| 243 | decorator.return_type != decorator.get_none_type()): |
| 244 | raise RuntimeError("The `sample_async` API only supports kernels that " |
| 245 | "return None (void). Consider using `run_async` for " |
| 246 | "kernels that return values.") |
| 247 | target = cudaq_runtime.get_target() |
| 248 | num_qpus = target.num_qpus() |
| 249 | if qpu_id >= num_qpus: |
| 250 | raise ValueError(f"qpu_id ({qpu_id}) exceeds the number of available " |
| 251 | f"QPUs ({num_qpus}).") |
| 252 | |
| 253 | if noise_model: |
| 254 | if target.is_remote(): |
| 255 | raise ValueError("Noise model is not supported on hardware QPU.") |
nothing calls this directly
no test coverage detected