From 408cbee2a4d2aa42e471a013457909f9ff770051 Mon Sep 17 00:00:00 2001 From: Takashi Imamichi <31178928+t-imamichi@users.noreply.github.com> Date: Wed, 21 Sep 2022 23:28:27 +0900 Subject: [PATCH] Add input data check for Sampler (#519) * add input data check for sampler * update * update * remove a validation check * move the check to BaseSampler * remove the unit test Co-authored-by: Jessie Yu --- qiskit_ibm_runtime/qiskit/primitives/base_sampler.py | 8 ++++++++ .../notes/add-sampler-error-check-20e5672c7ff17004.yaml | 7 +++++++ 2 files changed, 15 insertions(+) create mode 100644 releasenotes/notes/add-sampler-error-check-20e5672c7ff17004.yaml diff --git a/qiskit_ibm_runtime/qiskit/primitives/base_sampler.py b/qiskit_ibm_runtime/qiskit/primitives/base_sampler.py index bb09e240d..ccf9b80ce 100644 --- a/qiskit_ibm_runtime/qiskit/primitives/base_sampler.py +++ b/qiskit_ibm_runtime/qiskit/primitives/base_sampler.py @@ -359,6 +359,14 @@ def run( f"the number of parameters ({circuit.num_parameters}) for the {i}-th circuit." ) + for i, circuit in enumerate(circuits): + if circuit.num_clbits == 0: + raise QiskitError( + f"The {i}-th circuit does not have any classical bit. " + "Sampler requires classical bits, plus measurements " + "on the desired qubits." + ) + return self._run(circuits, parameter_values, parameter_views, **run_options) @abstractmethod diff --git a/releasenotes/notes/add-sampler-error-check-20e5672c7ff17004.yaml b/releasenotes/notes/add-sampler-error-check-20e5672c7ff17004.yaml new file mode 100644 index 000000000..881012228 --- /dev/null +++ b/releasenotes/notes/add-sampler-error-check-20e5672c7ff17004.yaml @@ -0,0 +1,7 @@ + +--- +upgrade: + - | + Added a validation check to :meth:`~qiskit_ibm_runtime.Sampler.run`. + It raises an error if there is no classical bit. +