Skip to content

Recursively controlling a circuit takes exponential time and memory #11823

@nonhermitian

Description

@nonhermitian

Environment

  • Qiskit version: 1.0
  • Python version: 3.12
  • Operating system: OSX and Linux

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.

N = 10
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()
    out.compose(sub_qc,range(sub_qc.num_qubits), inplace=True)

How can we reproduce the issue?

Run above

What should happen?

It should not take apparently exponential time

Any suggestions?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions