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

Performance regression of BackendSamplerV2 and BackendEstimatorV2 #12290

Closed
t-imamichi opened this issue Apr 22, 2024 · 1 comment · Fixed by #12291
Closed

Performance regression of BackendSamplerV2 and BackendEstimatorV2 #12290

t-imamichi opened this issue Apr 22, 2024 · 1 comment · Fixed by #12291
Assignees
Labels
mod: primitives Related to the Primitives module type: feature request New feature or request

Comments

@t-imamichi
Copy link
Member

What should we add?

We updated Primitives V2 to enable SamplerV2 and EstimatorV2 to handle different numbers of shots or precision for each pub.
To address this, I implemented BackendSamplerV2 and BackendEstimatorV2 to call backend.run for each pub.
On the other hand, BackendEstimatorV1 and BackendSamplerV1 assume the same number of shots per run call and pass all circuits to backend.run only once.

Copied from Qiskit/qiskit-ibm-runtime#1631

Qiskit main (7175368)

from timeit import timeit

from qiskit_aer import AerSimulator
from qiskit_ibm_runtime.fake_provider import FakeSherbrooke

from qiskit import QuantumCircuit
from qiskit.primitives import BackendSampler, BackendSamplerV2
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

backend = AerSimulator.from_backend(FakeSherbrooke())
shots = 10000
num_copies = 20


def gen_circuit(num_qubits: int, reps: int):
    qc = QuantumCircuit(num_qubits)
    for _ in range(reps):
        qc.h(range(num_qubits))
        for i in range(0, num_qubits - 1, 2):
            qc.cx(i, i + 1)
    qc.measure_all()
    return qc


def bench_sampler_v1(qc: QuantumCircuit):
    print("\nBackendSamplerV1")
    sampler = BackendSampler(backend)
    print(f"{timeit(lambda: sampler.run([qc] * num_copies, shots=shots).result(), number=1)} sec")


def bench_sampler_v2(qc: QuantumCircuit):
    print("\nBackendSamplerV2")
    sampler = BackendSamplerV2(backend=backend)
    print(f"{timeit(lambda: sampler.run([qc] * num_copies, shots=shots).result(), number=1)} sec")


qc = gen_circuit(5, 5)
pm = generate_preset_pass_manager(optimization_level=2, backend=backend)
qc2 = pm.run(qc)
bench_sampler_v1(qc2)
bench_sampler_v2(qc2)

output

BackendSamplerV1
0.7136987919984676 sec

BackendSamplerV2
9.465235792002204 sec
@t-imamichi t-imamichi added the type: feature request New feature or request label Apr 22, 2024
@t-imamichi t-imamichi self-assigned this Apr 22, 2024
@t-imamichi t-imamichi added the mod: primitives Related to the Primitives module label Apr 22, 2024
@t-imamichi
Copy link
Member Author

t-imamichi commented Apr 25, 2024

#12291 fixes the performance issue.

output with main

BackendSamplerV1
0.5204217499995138 sec

BackendSamplerV2
0.5375754169945139 sec

Here is also results of estimator #12291 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: primitives Related to the Primitives module type: feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant