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),
   1 / math.sqrt(2) * complex(1,0 )]

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


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()

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.