# Visualize full UCC circuit in qiskit

I am experimenting with the UCC module in qiskit nature. From pyscf, I got 1-body and 2-body integrals (I need to use custom integrals) and thus created a mapped Hamiltonian. Then, I create a UCC object and find the optimal parameters, and finally, I visualize the circuit. The code I used (without imports & pyscf-overhead) is shown below.

electronic_energy = ElectronicEnergy.from_raw_integrals(
ElectronicBasis.MO, one_body_ints, two_body_ints
)
hamiltonian = electronic_energy.second_q_ops()[0]
qubit_converter = QubitConverter(mapper=JordanWignerMapper())
qubit_op = qubit_converter.convert(hamiltonian,num_particles=num_particles)
initial_state = HartreeFock(
num_spin_orbitals=num_spin_orbitals,
num_particles=num_particles,
qubit_converter=qubit_converter,
)
reps=1
var_form = UCC(
excitations="sd",
num_particles=num_particles,
num_spin_orbitals=num_spin_orbitals,
initial_state=initial_state,
qubit_converter=qubit_converter,
reps=reps,
)
optimizer=COBYLA(maxiter=1000)
vqe = VQE(ansatz=var_form, optimizer=optimizer,quantum_instance=Aer.get_backend("aer_simulator_statevector"))
vqe_result =vqe.compute_minimum_eigenvalue(qubit_op)
from qiskit.tools.visualization import circuit_drawer
circuit=vqe.get_optimal_circuit()
circuit_drawer(circuit, output='mpl', plot_barriers=False)
plt.show()


I thought that I could visualize the full circuit by printing/drawing the circuit object. This is however not the case, all I get is the following:

How can I visualize the full circuit?

You can use QuantumCircuit.decompose() for shallow decomposition

circuit.decompose().draw('mpl')


The result will be

For further decomposition you can use Unroller transpiler pass

from qiskit.transpiler.passes import Unroller
from qiskit.converters import circuit_to_dag, dag_to_circuit

# You can specify the target basis gate set:
unroller = Unroller(basis=['u', 'cx'])
unrolled_circuit = dag_to_circuit(unroller.run(circuit_to_dag(circuit)))
unrolled_circuit.draw('mpl')