-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
type: feature requestNew feature or requestNew feature or request
Milestone
Description
Problem
The reference primitives in Terra are a lot slower if they are given a wrapped circuit versus a decomposed circuit. This seems to happen because parameter binding takes much longer on the wrapped circuit due to the call to _rebind_definition
. Here's a small example using the EfficientSU2
circuit and it's decomposed version, where the latter is ~3 times faster.
import time
from qiskit.primitives import Estimator
from qiskit.circuit.library import EfficientSU2
from qiskit.quantum_info import SparsePauliOp
circuit = EfficientSU2(num_qubits=12, reps=10)
values = [1.23] * circuit.num_parameters
op = SparsePauliOp(["Z" * circuit.num_qubits])
start = time.time()
for _ in range(100):
__ = Estimator().run([circuit], [op], [values])
print("Boxed took:", time.time() - start)
decomposed = circuit.decompose()
start = time.time()
for _ in range(100):
__ = Estimator().run([decomposed], [op], [values])
print("Unboxed took:", time.time() - start)
Boxed took: 15.107944965362549
Unboxed took: 5.981446266174316
Profiles
Here's a profiling for the boxed version:
Proposed solution
The reference primitives should unroll the circuits to gates that own the parameters, i.e. a basis of all the standard gates. Since caching is already implemented we could just store this unrolled version.
Metadata
Metadata
Assignees
Labels
type: feature requestNew feature or requestNew feature or request