-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
Milestone
Description
What should we add?
Calling QuantumCircuit.bind_parameters
can have drastically different performance depending on whether or not the circuit contains wrapped instructions. For example, comparing the time to build and bind parameters for an EfficientSU2
circuit, where in the first case, we call bind_parameters
directly on EfficientSU2
, and in the second, after unwrapping EfficientSU2
via a call to decompose
:
from simple_benchmark import benchmark
def _build_wrapped(num_layers):
qc = EfficientSU2(100, entanglement='linear', reps=int(num_layers))
qc.bind_parameters({p: math.pi/2 for p in qc.parameters})
def _build_unwrapped(num_layers):
qc = EfficientSU2(100, entanglement='linear', reps=int(num_layers)).decompose()
qc.bind_parameters({p: math.pi/2 for p in qc.parameters})
funcs = [_build_wrapped, _build_unwrapped]
b = benchmark([_build_wrapped, _build_unwrapped],
{i: i for i in np.linspace(1, 100, 5)},
'num_layers',
function_aliases={_build_wrapped: 'wrapped', _build_unwrapped: 'decomposed'}
)
Related to #10269 . During profiling @mtreinish found most of the time for the wrapped case spent in recursive calls to https://github.com/Qiskit/qiskit-terra/blob/main/qiskit/circuit/quantumcircuit.py#L2933-L2944 .