# How to write the code for decomposing only a subset of gates in a quantum circuit via Qiskit?

I have a quantum circuit with a number of gates, and some of them are labeled by some letters without showing the details inside. I have known the quantumcircuit.decompose() would help, but it would decompose all the gates. I am wondering whether we can choose only a subset of gates to decompose. How to write the code? Really appreciate it if some examples can be provided.

You can just pass the gate label to decompose method:

op1 = random_unitary(4)
op2 = random_unitary(4)
op3 = random_unitary(4)

circ = QuantumCircuit(2)
circ.unitary(op1, [0, 1], 'label_1')
circ.unitary(op2, [0, 1], 'label_2')
circ.unitary(op3, [0, 1], 'label_3')

circ.decompose(gates_to_decompose = 'label_2').draw('mpl')


gates_to_decompose can be a list such as ['label_1', 'label_2']

• Thank you very much ! I have tried the following code: qc_Oracle1.decompose(gates_to_decompose = 'abc').draw('mpl'), and got TypeError: decompose() got an unexpected keyword argument 'gates_to_decompose'. Does it mean decompose () does not have the 'gates_to_decompose' argument ? Mar 17 at 13:36
• Check your Qiskit version. gates_to_decompose added in Terra 0.19 (Qiskit 0.33). Mar 17 at 13:49
• It works, thank you! It is indeed the qiskit version that causes the error. Mar 17 at 14:20