I would like to prepare the following initial state for variational quantum algorithms: $$ \sin\theta_1 \sin\theta_2 \sin\theta_3 |000\rangle + \sin\theta_1 \sin\theta_2 \cos\theta_3 |001\rangle + \sin\theta_1 \cos\theta_2 |010\rangle + \cos\theta_1 |100 \rangle. $$

Should I make a circuit for this state from scratch? Or is there any library to find a circuit to make this state such as Cirq or Qiskit?


2 Answers 2


If you call initialize in this case, you will be specifying a general state in $\mathbb{C}^8$. However what you have is more specialized. For example only having 4 nonzero amplitudes. So the call to initialize won't know this a priori. So it won't realize the initialization circuit can be decomposed easily. Or at least it will need to do some extra simplification steps before realizing this.

I'm going to change $\sin$ and $\cos$ from your state. You can fix this by changing the angles with appropriate angle redefinitions. $\theta \to \frac{\pi}{2}-\theta$.

$$ | \psi_1 \rangle = (\mathrm{R}(\theta_1) \otimes I_4) | 0 0 0 \rangle = \cos \theta_1 | 0 0 0 \rangle + \sin \theta_1 | 1 0 0 \rangle\\ | \psi_2 \rangle = (\mathrm{CR}(0,\theta_2) \otimes I_2) | \psi_1 \rangle = \cos \theta_1 \cos \theta_2 | 0 0 0 \rangle + \cos \theta_1 \sin \theta_2 | 0 1 0 \rangle + \sin \theta_1 | 1 0 0 \rangle\\ | \psi \rangle = \mathrm{CCR}(00,\theta_3) | \psi_2 \rangle $$

where $\mathrm{R}(\theta)$ is to indicate a 2 by 2 rotation matrix.

$\mathrm{CR}(0,\theta)$ is to indicate controlled $\mathrm{R}(\theta)$ on the second index but controlled on 0 instead of 1 on the first.

$\mathrm{CCR}(00,\theta)$ is to indicate controlled $\mathrm{R}(\theta)$ on the third index but controlled on 00 instead of 11 on the first two.

You should be able to fix the angles and get the controls back to normal from here.


You can initialize a quantum state by using the QuantumCircuit.initialize() function. For example, to initialize a circuit into the state |1>, we can perform the initialization as follows :

vector = [0,1]
qr = QuantumRegister(1)
qc = QuantumCircuit(qr)

qc.initialize(vector, [qr[0]])

There is more detail about how to use it in this tutorial


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.