-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Recursively controlling a circuit takes exponential time and memory #11823
Comments
This is because That said, when it actually comes to synthesising the gates through |
Just as an immediate copy-pastable example of the above: from qiskit import QuantumCircuit
N = 100
sub_qc = QuantumCircuit(1)
sub_qc.x(0)
out = QuantumCircuit(N)
out.compose(sub_qc,range(sub_qc.num_qubits), inplace=True)
for kk in range(N-1):
sub_qc = sub_qc.control(annotated=True)
out.compose(sub_qc,range(sub_qc.num_qubits), inplace=True) |
Fwiw, slightly better form for this would be to do: from qiskit import QuantumCircuit
N = 100
sub_qc = QuantumCircuit(1)
sub_qc.x(0)
sub = sub_qc.to_gate()
out = QuantumCircuit(N)
out.append(sub, range(sub.num_qubits))
for kk in range(N-1):
sub = sub.control(annotated=True)
out.append(sub, range(sub.num_qubits))
|
Ok thanks. I am trying to benchmark various aspects of Qiskit, and this one broke things, where as other frameworks can handle the controlled circuit. Is there anyway for an user to find out what |
It's not on by default because that would have been a major breaking API change, and we're not confident that it's as well supported through the entire stack as the current form yet. It will become the default once it and its synthesis have matured a little more - I'd imagine changing the default of For example, at the moment, the multiple What are you meaning by "any way for a user to find out what it does?"? It's a modifier, so it doesn't really do anything (in the sense of the eager synthesis of |
Yeah, no I answered my own question when I tried to change the basis on the circuit and it just kept running. It also modifies the circuit drawing, which is not too important, but unexpected. |
Continuing with Jake's example, here are a few thoughts on the following synthesis step: An expression of the form For
The pass is recursive, descending into the definitions of custom gates, and it needs basis gates and equivalence library to know which definitions to examine and which to skip. For One could do a bit better by replacing the code
by
in which case the synthesis algorithm would treat the annotated |
Indeed, it seems that the current synthesis algorithms for multi-controlled gates could be improved. See the discussion in #5872 |
Environment
What is happening?
Recursively adding controls to an initial sub-circuit will cause Qiskit to hang, using up ever increasing CPU and memory resources. E.g. the below will never complete, but taking
N=5
or so will.How can we reproduce the issue?
Run above
What should happen?
It should not take apparently exponential time
Any suggestions?
No response
The text was updated successfully, but these errors were encountered: