# Draw “Initialize” circuit as sequence of single gates

I have just tried to apply initialize function to a simple circuit. There is any way to display how is done internally the initialization circuit instead of a single block with label "initialize"?

Here is the output of the minimal working example you can find below:

            ┌──────────────────────────────────┐
q2476_0: |0>┤0                                 ├
│  initialize(0.70711,0,0,0.70711) │
q2476_1: |0>┤1                                 ├
└──────────────────────────────────┘


Minimal working example:

import numpy as np
import math
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister

desired_vector = [
1 / math.sqrt(2) * complex(1, 0),
0,
0,
1 / math.sqrt(2) * complex(1,0 )]

q = QuantumRegister(2)
qc = QuantumCircuit(q)
qc.initialize(desired_vector, [q[0],q[1]])

qc.draw(output='mpl')
print(qc)


## 1 Answer

There is a way, though it is pretty hacky. Going off of the code you provided:

qc.initialize(desired_vector, [q[0],q[1]]).gates_to_uncompute().draw()
qc.decompose().decompose().decompose().decompose().draw()


The first line will provide gates that uncompute intialize. However it will only show up as Multiplex gates.

The second line is what decomposes the Multiplex gates into familiar gates. You need one decompose() call for each Multiplex gate. In this scenario, you will see 4 Multiplex gates, so you need 4 decompose() calls.

Note: initialize assumes the state is currently in the ground state. Because of this, the new circuit that is made will include a reset on each qubit at the beginning of the circuit.