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

QuantumCircuit.decompose raises an error with a conditional U gate for Qiskit 1.3.0rc2 and the main branch #13493

Open
t-imamichi opened this issue Nov 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@t-imamichi
Copy link
Member

t-imamichi commented Nov 26, 2024

Environment

  • Qiskit version: 1.3.0rc2, main
  • Python version: 3.12.7
  • Operating system: macOS 15.1.1

What is happening?

A circuit with a conditional gate raises an error when decompose is invoked. It does not happen for 1.2.4

How can we reproduce the issue?

from qiskit import QuantumCircuit, __version__

qc = QuantumCircuit(1, 1)
qc.u(0, 0, 0, 0).c_if(0, 0)

print(__version__)
print(qc)
print(qc.decompose())
# qiskit 1.2.4
1.2.4
     ┌──────────┐
  q: ┤ U(0,0,0) ├
     └────╥─────┘
     ┌────╨────┐
c: 1/╡ c_0=0x0 ╞═
     └─────────┘
     ┌──────────┐
  q: ┤ U(0,0,0) ├
     └────╥─────┘
     ┌────╨────┐
c: 1/╡ c_0=0x0 ╞═
     └─────────┘
# 1.3.0rc2 and main branch
1.3.0rc2
     ┌──────────┐
  q: ┤ U(0,0,0) ├
     └────╥─────┘
     ┌────╨────┐
c: 1/╡ c_0=0x0 ╞═
     └─────────┘
Traceback (most recent call last):
  File "/Users/ima/tasks/4_2024/qiskit/terra/tmp/cond.py", line 8, in <module>
    print(qc.decompose())
          ^^^^^^^^^^^^^^
  File "/Users/ima/envs/q130/lib/python3.12/site-packages/qiskit/circuit/quantumcircuit.py", line 3288, in decompose
    dag = pass_.run(dag)
          ^^^^^^^^^^^^^^
  File "/Users/ima/envs/q130/lib/python3.12/site-packages/qiskit/transpiler/passes/basis/decompose.py", line 72, in run
    node_as_dag = _node_to_dag(node)
                  ^^^^^^^^^^^^^^^^^^
  File "/Users/ima/envs/q130/lib/python3.12/site-packages/qiskit/transpiler/passes/basis/decompose.py", line 130, in _node_to_dag
    dag.apply_operation_back(node.op, node.qargs, node.cargs)
qiskit.dagcircuit.exceptions.DAGCircuitError: 'invalid clbits in condition for u'

What should happen?

No error should be raised as same as 1.2.4

Any suggestions?

The following procedure, which exists in stable/1.2, is perhaps necessary to handle UGate.c_if in _apply_op_node_back?

def _apply_op_node_back(self, node: DAGOpNode, *, check: bool = False):
additional = ()
if _may_have_additional_wires(node):
# This is the slow path; most of the time, this won't happen.
additional = set(_additional_wires(node.op)).difference(node.cargs)

@t-imamichi t-imamichi added the bug Something isn't working label Nov 26, 2024
@t-imamichi t-imamichi changed the title QuantumCircuit.decompose raises an error with a conditional gate for Qiskit 1.3.0rc2 and the main branch QuantumCircuit.decompose raises an error with a conditional U gate for Qiskit 1.3.0rc2 and the main branch Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant