MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / run_async

Function run_async

python/cudaq/runtime/run.py:71–125  ·  view source on GitHub ↗

Run the provided `kernel` with the given kernel `arguments` over the specified number of circuit executions (`shots_count`) asynchronously on the specified `qpu_id`. Args: kernel (:class:`Kernel`): The :class:`Kernel` to execute `shots_count` times on the QPU. *arguments (Optional[Any]): T

(decorator, *args, shots_count=100, noise_model=None, qpu_id=0)

Source from the content-addressed store, hash-verified

69
70@trace.traced
71def run_async(decorator, *args, shots_count=100, noise_model=None, qpu_id=0):
72 """
73Run the provided `kernel` with the given kernel `arguments` over the specified
74number of circuit executions (`shots_count`) asynchronously on the specified
75`qpu_id`.
76
77Args:
78 kernel (:class:`Kernel`): The :class:`Kernel` to execute `shots_count` times
79 on the QPU.
80 *arguments (Optional[Any]): The concrete values to evaluate the kernel
81 function at. Leave empty if the kernel doesn't accept any arguments. For
82 example, if the kernel takes two `float` values as input, the `run` call
83 should be structured as `cudaq.run(kernel, firstFloat, secondFloat)`.
84 shots_count (Optional[int]): The number of kernel executions on the QPU.
85 Defaults to 100. Key-word only.
86 noise_model (Optional[`NoiseModel`]): The optional :class:`NoiseModel` to add
87 noise to the kernel execution on the simulator. Defaults to an empty noise
88 model.
89 `qpu_id` (Optional[int]): The id of the QPU. Defaults to 0. Key-word only.
90
91Returns:
92 `AsyncRunResult`:
93 A handle, which can be waited on via a `get()` method, which returns an array
94 of `kernel` return values. The length of the list is equal to `shots_count`.
95 """
96
97 if isa_kernel_decorator(decorator):
98 if decorator.qkeModule is None:
99 raise RuntimeError(
100 "Unsupported target / Invalid kernel for `run`: missing module")
101
102 if decorator.formal_arity() != len(args):
103 raise RuntimeError("Invalid number of arguments passed to run_async. " +
104 str(len(args)) + " given and " +
105 str(decorator.formal_arity()) + " expected.")
106 if (not isinstance(shots_count, int)) or (shots_count < 0):
107 raise RuntimeError(
108 "Invalid `shots_count`. Must be a non-negative number.")
109
110 target = cudaq_runtime.get_target()
111 num_qpus = target.num_qpus()
112 if qpu_id >= num_qpus:
113 raise ValueError(f"qpu_id ({qpu_id}) exceeds the number of available "
114 f"QPUs ({num_qpus}).")
115
116 if noise_model != None:
117 if target.is_remote():
118 raise ValueError("Noise model is not supported on hardware QPU.")
119
120 processedArgs, module = decorator.prepare_call(*args)
121 async_results = cudaq_runtime.run_async_impl(decorator.uniqName + ".run",
122 module, shots_count,
123 noise_model, qpu_id,
124 *processedArgs)
125 return AsyncRunResult(async_results, module)

Callers 5

mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50

Calls 6

isa_kernel_decoratorFunction · 0.90
AsyncRunResultClass · 0.85
formal_arityMethod · 0.80
num_qpusMethod · 0.80
is_remoteMethod · 0.80
prepare_callMethod · 0.80

Tested by

no test coverage detected