Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
wshanks committed Oct 30, 2024
1 parent 371ed52 commit a7d4046
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 6 additions & 1 deletion qiskit/primitives/backend_sampler_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class _MeasureInfo:
list indexing memory slot.
"""


class BackendSamplerV2(BaseSamplerV2):
"""Evaluates bitstrings for provided quantum circuits
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions test/python/primitives/test_backend_sampler_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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]
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit a7d4046

Please sign in to comment.