from qiskit import *

qc1=QuantumCircuit(2,2)
qc2=QuantumCircuit(3,3)
#qc=qc1+qc2
#qc.draw()
#Note: circuits are incompatible

qc1=QuantumCircuit(2,2)
qc1.h(0)
qc1.s(1)
qc2=QuantumCircuit(2,2)
qc2.x(1)
qc2.cx(0,1)


qc1.draw(output='mpl')

qc2.draw(output='mpl')

qc=qc1+qc2
qc.draw(output='mpl')

qc1=QuantumCircuit(2,2)
qc1.h(0)
qc1.s(1)
qc1.draw(output='mpl')

qc2=QuantumCircuit(3,3)
qc2.x(1)
qc2.cx(0,2)
qc2.draw(output='mpl')

# rhs added to lhs
qc=qc2.compose(qc1)
qc.draw(output='mpl')

qc.num_qubits

# If inplace attribute is not included , then it returns QuantumCircuit
type(qc2.compose(qc1))

qc1=QuantumCircuit(2,2)
qc1.h(0)
qc1.s(1)
qc2=QuantumCircuit(3,3)
qc2.x(1)
qc2.cx(0,2)
qc2.compose(qc1,inplace=True)
qc2.draw(output='mpl')

type(qc2)

qc2.num_qubits

# If inplace attribute is true , then it returns None
type(qc2.compose(qc1,inplace=True))

qc1=QuantumCircuit(2,2)
qc1.h(0)
qc1.s(1)
qc2=QuantumCircuit(3,3)
qc2.x(1)
qc2.cx(0,2)
qc2.compose(qc1,qubits=[2,1],inplace=True)
qc2.draw(output='mpl')

qc=QuantumCircuit(2,2)
qc.h(0)
qc.cx(0,1)
qc.x(1)
qc.draw(output='mpl')

qc_meas=QuantumCircuit(2)
qc_meas.measure_all()
qc_meas.draw(output='mpl')

qc.compose(qc_meas,inplace=True)

qc.draw(output='mpl')

