# How to set initial state on IBM Q?

For my undergraduate final project I am working on a Quantum Inspired Genetic Algorithm.

For this I am using IBM Q real devices and I need to set a custom initial state on qubits. Using the statevector simulator this was possible, however I am not sure how to do so on real quantum hardware. For example I want to put qubit into state $$|\psi\rangle = \sqrt{0.3}|0\rangle + \sqrt{0.7}|1\rangle$$.

• Hi! Were you using qc.initialize() before? This can still be run on the real devices – met927 Feb 6 '20 at 18:06
• Did you have an issue with running it? I just tested and was able to – met927 Feb 6 '20 at 18:12
• Just note that quantum tomography is used for a quantum state measurement, not for qubits initialization. – Martin Vesely Feb 6 '20 at 18:16
• You can run qc.initialize([1,0], 0) to initialize it into the |0> state, where the 1st param is the vector to use and the 2nd is the qubits to apply it to. The state you are describing isn't a valid quantum state, as a^2 + b^2 = 1 – met927 Feb 6 '20 at 18:17
• I understand that Adhisha is looking for method how to initialize state of qubit and I edited the question accordingly. – Martin Vesely Feb 6 '20 at 22:12

To prepare an arbitrary single qubit state it is possible to use $$\mathrm{U3}$$ gate. The gate is defined by a matrix

$$\mathrm{U3}(\theta, \phi, \lambda)= \begin{pmatrix} \cos(\theta/2) & -\mathrm{e}^{i\lambda}\sin(\theta/2) \\ \mathrm{e}^{i\phi}\sin(\theta/2) & \mathrm{e}^{i(\phi+\lambda)}\cos(\theta/2) \end{pmatrix}.$$

When then gate is applied on a qubit in state $$|0\rangle$$ (i.e. initial state of all qubits on IBM Q), it is transformed to state

$$|\varphi_0\rangle = \cos(\theta/2)|0\rangle + \mathrm{e}^{i\phi}\sin(\theta/2)|1\rangle.$$

Setting parameters $$\theta$$ and $$\phi$$ allows you to get any single qubit state you need.

In your case $$|\psi\rangle = \sqrt{0.3}|0\rangle + \sqrt{0.7}|1\rangle$$, so obviously $$\phi = 0$$.

Since $$\cos(\theta/2) = \sqrt{0.3}$$ parameter $$\theta$$ is given as

$$\theta = 2 \arccos(\sqrt{0.3}) = 1.9823.$$

Note 1: In case $$\alpha$$ and $$\beta$$ are real numbers, $$\phi = 0$$ always and you can apply $$\mathrm{Ry}(\theta)$$ gate (i.e. y-rotation) with same parameter $$\theta$$ instead because $$\mathrm{Ry}(\theta) = \mathrm{U3}(\theta,0,0)$$.

Note 2: To preare any multiqubit quantum state, a method introduced in Transformation of quantum states using uniformly controlled rotations can be employed.