You need to convert a circuit into an instruction, not a gate. A gate is assumed to be invertible, which is not the case if you have measurements and classical conditionals. Therefore, you need to create a custom instruction. Here is a short tutorial for that:
First, create a circuit will all your gates and instructions, with measurements and conditionals. This will be the custom instruction:
from qiskit import *
from qiskit.circuit.library import *
qr = QuantumRegister(2)
cr = ClassicalRegister(2)
circuit = QuantumCircuit(qr, cr, name='my_inst')
circuit.h(qr[0])
circuit.cx(qr[0], qr[1])
circuit.measure(qr[1], cr[0])
circuit.append(XGate(), [qr[0]]).c_if(cr,2)
circuit.draw('text')
┌───┐ ┌───┐
q4_0: ┤ H ├──■──────┤ X ├─
└───┘┌─┴─┐┌─┐ └─┬─┘
q4_1: ─────┤ X ├┤M├───┼───
└───┘└╥┘┌──┴──┐
c4: 2/═══════════╩═╡ = 2 ╞
0 └─────┘
Then, you need to convert this circuit into an instruction:
my_inst = circuit.to_instruction()
This instruction can be append to another super circuit:
big_circuit = QuantumCircuit(5, 2)
big_circuit.h(range(5))
big_circuit.append(my_inst, range(2), range(2))
big_circuit.h(range(5))
big_circuit.draw('text')
┌───┐┌──────────┐┌───┐
q_0: ┤ H ├┤0 ├┤ H ├
├───┤│ │├───┤
q_1: ┤ H ├┤1 ├┤ H ├
├───┤│ │├───┤
q_2: ┤ H ├┤ ├┤ H ├
├───┤│ │├───┤
q_3: ┤ H ├┤ my_inst ├┤ H ├
├───┤│ │├───┤
q_4: ┤ H ├┤ ├┤ H ├
└───┘│ │└───┘
c_0: ═════╡0 ╞═════
│ │
c_1: ═════╡1 ╞═════
└──────────┘
There it is. If you decompose the instructions in this circuit, you will see the internal operations:
big_circuit.decompose().draw('text')
┌──────────┐ ┌───┐ ┌───┐ ┌──────────┐
q_0: ┤ U2(0,pi) ├───┤ H ├──────■──────────────────┤ X ├─┤ U2(0,pi) ├
├──────────┤ └───┘ ┌─┴─┐┌─┐┌──────────┐ └─┬─┘ └──────────┘
q_1: ┤ U2(0,pi) ├────────────┤ X ├┤M├┤ U2(0,pi) ├───┼───────────────
├──────────┤┌──────────┐└───┘└╥┘└──────────┘ │
q_2: ┤ U2(0,pi) ├┤ U2(0,pi) ├──────╫────────────────┼───────────────
├──────────┤├──────────┤ ║ │
q_3: ┤ U2(0,pi) ├┤ U2(0,pi) ├──────╫────────────────┼───────────────
├──────────┤├──────────┤ ║ │
q_4: ┤ U2(0,pi) ├┤ U2(0,pi) ├──────╫────────────────┼───────────────
└──────────┘└──────────┘ ║ ┌──┴──┐
c: 2/══════════════════════════════╩═════════════╡ = 2 ╞════════════
0 └─────┘
If you want to decompose the circuit to a particular base, you can use the transpiler for that:
decomposed = transpile(big_circuit, basis_gates=['cx', 'u3'], optimization_level=0)
decomposed.draw('text', fold=-1)
┌───────────────┐┌───────────────┐ ┌─────────────┐┌───────────────┐
q_0: ┤ U3(pi/2,0,pi) ├┤ U3(pi/2,0,pi) ├──■──────────────────────┤ U3(pi,0,pi) ├┤ U3(pi/2,0,pi) ├
├───────────────┤└───────────────┘┌─┴─┐┌─┐┌───────────────┐└──────┬──────┘└───────────────┘
q_1: ┤ U3(pi/2,0,pi) ├─────────────────┤ X ├┤M├┤ U3(pi/2,0,pi) ├───────┼────────────────────────
├───────────────┤┌───────────────┐└───┘└╥┘└───────────────┘ │
q_2: ┤ U3(pi/2,0,pi) ├┤ U3(pi/2,0,pi) ├──────╫─────────────────────────┼────────────────────────
├───────────────┤├───────────────┤ ║ │
q_3: ┤ U3(pi/2,0,pi) ├┤ U3(pi/2,0,pi) ├──────╫─────────────────────────┼────────────────────────
├───────────────┤├───────────────┤ ║ │
q_4: ┤ U3(pi/2,0,pi) ├┤ U3(pi/2,0,pi) ├──────╫─────────────────────────┼────────────────────────
└───────────────┘└───────────────┘ ║ ┌──┴──┐
c: 2/════════════════════════════════════════╩══════════════════════╡ = 2 ╞═════════════════════
0 └─────┘