From a7d4046da6887d4e5d498c2f333c7285b90a9596 Mon Sep 17 00:00:00 2001 From: Will Shanks Date: Wed, 30 Oct 2024 14:09:47 -0400 Subject: [PATCH] black --- qiskit/primitives/backend_sampler_v2.py | 7 ++++++- test/python/primitives/test_backend_sampler_v2.py | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/qiskit/primitives/backend_sampler_v2.py b/qiskit/primitives/backend_sampler_v2.py index 4333d41e8d2..40a6d8560e0 100644 --- a/qiskit/primitives/backend_sampler_v2.py +++ b/qiskit/primitives/backend_sampler_v2.py @@ -77,6 +77,7 @@ class _MeasureInfo: list indexing memory slot. """ + class BackendSamplerV2(BaseSamplerV2): """Evaluates bitstrings for provided quantum circuits @@ -199,7 +200,11 @@ def _run_pubs(self, pubs: list[SamplerPub], shots: int) -> list[SamplerPubResult # pack memory to an ndarray of uint8 results = [] start = 0 - meas_level = None if self._options.run_options is None else self._options.run_options.get("meas_level") + meas_level = ( + None + if self._options.run_options is None + else self._options.run_options.get("meas_level") + ) for pub, bound in zip(pubs, bound_circuits): meas_info, max_num_bytes = _analyze_circuit(pub.circuit) end = start + bound.size diff --git a/test/python/primitives/test_backend_sampler_v2.py b/test/python/primitives/test_backend_sampler_v2.py index 8215754465a..c6caab5fa33 100644 --- a/test/python/primitives/test_backend_sampler_v2.py +++ b/test/python/primitives/test_backend_sampler_v2.py @@ -63,6 +63,7 @@ class Level1BackendV2(GenericBackendV2): classical register. For ``meas_return="avg"``, the individual shot results are still calculated and then averaged. """ + level1_sigma = 0.1 def run(self, run_input, **options): @@ -84,7 +85,9 @@ def run(self, run_input, **options): result_dict = inner_job.result().to_dict() for circ, exp_result in zip(run_input, result_dict["results"]): num_clbits = sum(cr.size for cr in circ.cregs) - bitstrings = [format(int(x, 16), f"0{num_clbits}b") for x in exp_result["data"]["memory"]] + bitstrings = [ + format(int(x, 16), f"0{num_clbits}b") for x in exp_result["data"]["memory"] + ] new_data = [ [ [2 * int(d) - 1 + rng.normal(scale=self.level1_sigma), i] @@ -1016,7 +1019,7 @@ def test_run_level1(self): "run_options": { "meas_level": 1, "meas_return": "single", - } + }, } sampler = BackendSamplerV2(backend=backend, options=options) result_single = sampler.run([qc]).result() @@ -1027,7 +1030,7 @@ def test_run_level1(self): "run_options": { "meas_level": 1, "meas_return": "avg", - } + }, } sampler = BackendSamplerV2(backend=backend, options=options) result_avg = sampler.run([qc]).result()