I have recently started working on qiskit and I am struggling to use qc.initialize API in any practical or useful application. I have read at multiple places that they are used to feed data to the quantum circuits. For developing an understanding of the quantum computers, I executed the code of Bernstein Vazirani Algorithm(secret number detector) on qasm_simulator using Pycharm IDE as shown below without using any initialization circuit.

import qiskit
from qiskit import IBMQ
import time
from qiskit import *
from qiskit.tools.visualization import plot_histogram
from qiskit.tools.visualization import plot_bloch_multivector
import matplotlib.pyplot as plt
from qiskit.tools.monitor import job_monitor
#IBMQ.save_account('Account key',overwrite=True)  #  Run it for once

# 6 bit secret number
secretNumber= '101001'

circuit= QuantumCircuit(6+1,6) # 6 qubit for secret no. +1 qubit
circuit. h([0,1,2,3,4,5])

# splitting the string into char
splitSecretNumber= list(secretNumber)
lengthofSecretNumber= len(splitSecretNumber)

while(x< lengthofSecretNumber):


simulator= Aer.get_backend('qasm_simulator')
simulationResult = execute(circuit,simulator, shots=1).result()
counts= simulationResult.get_counts()

Please guide me to convert this code to take Input data using initialization circuit. Also, please suggest me some good papers to read on initialization. Thanks in advance.


1 Answer 1


There is a nuance in the usefulness of these initialisation method that is important to get:

they are used to feed data to the quantum circuits when encoding this data in the amplitude of the statevector is needed.

In your specific case of Bernstein Vazirani, you do not need to load anything in the amplitudes of the statevector as you only have one number, written in binary, that can be loaded by flipping qubits. You did exactly this with the cx gates in your while loop.

You can use the initialisation method described in your question when you want to load a vector of float numbers on the quantum computer. For example if you want to load $\left[\frac{1}{10},\frac{4}{10},\frac{6}{10},\frac{47}{100}\right]$ into the 2-qubit state $\frac{1}{10} \vert 00 \rangle + \frac{4}{10}\vert 01 \rangle + \frac{6}{10} \vert 10 \rangle + \frac{47}{100} \vert 11 \rangle$.

Now about papers, Qiskit implements the algorithm in this paper: "Synthesis of Quantum Logic Circuits" Shende, Bullock, Markov https://arxiv.org/abs/quant-ph/0406176v5 as noted in the documentation here.

  • $\begingroup$ Thank you @Adrien. Can you suggest me some way to modify the python code and make it work using the Initialize API or provide me with some link? $\endgroup$
    – Manu
    Jun 30, 2021 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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