Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a transpile issue of BackendSampler #9236

Merged
merged 6 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion qiskit/primitives/backend_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def transpiled_circuits(self) -> list[QuantumCircuit]:
"""
if self._skip_transpilation:
self._transpiled_circuits = list(self._circuits)
elif self._transpiled_circuits is None:
elif self._transpiled_circuits is None or len(self._transpiled_circuits) != len(
self._circuits
):
# Only transpile if have not done so yet
self._transpile()
return self._transpiled_circuits
Expand Down
13 changes: 13 additions & 0 deletions test/python/primitives/test_backend_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,19 @@ def test_primitive_job_size_limit_backend_v1(self):
self.assertDictAlmostEqual(result.quasi_dists[0], {0: 1}, 0.1)
self.assertDictAlmostEqual(result.quasi_dists[1], {1: 1}, 0.1)

def test_sequential_run(self):
"""Test sequential run."""
qc = QuantumCircuit(1)
qc.measure_all()
qc2 = QuantumCircuit(1)
qc2.x(0)
qc2.measure_all()
sampler = BackendSampler(backend=FakeNairobi())
result = sampler.run([qc]).result()
result2 = sampler.run([qc2]).result()
self.assertDictAlmostEqual(result.quasi_dists[0], {0: 1}, 0.1)
self.assertDictAlmostEqual(result2.quasi_dists[0], {1: 1}, 0.1)


if __name__ == "__main__":
unittest.main()