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

Parameter binding substantially slower on wrapped circuit vs unwrapped #10282

Closed
kdk opened this issue Jun 14, 2023 · 0 comments · Fixed by #10284
Closed

Parameter binding substantially slower on wrapped circuit vs unwrapped #10282

kdk opened this issue Jun 14, 2023 · 0 comments · Fixed by #10284
Assignees
Labels
Milestone

Comments

@kdk
Copy link
Member

kdk commented Jun 14, 2023

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'}
             )

image

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 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants