Please help me in building IBM Quantum Experience circuit for: $$ M|0\rangle = \frac{1}{2}(|0\rangle+|1\rangle+|2\rangle+|3\rangle) $$

Edit: Is it possible to make a circuit for a general transformation $M|0\rangle = \frac{1}{\sqrt{m}}\sum_{i=0}^{m-1}|i\rangle$ acting on $\log m$ qubits initialized to $|0\rangle$?

  • $\begingroup$ Simply put Hadamard gates on two qubits and that's it. $\endgroup$ – Martin Vesely Feb 12 '20 at 19:22
  • $\begingroup$ @MartinVesely can we give circuit for a general transformation $M|0\rangle = \frac{1}{\sqrt{m}}\sum_{i=0}^{m-1}|i\rangle$ by initializing $log~m$ qubits to $|0\rangle$. $\endgroup$ – Adam Levine Feb 13 '20 at 3:10

Answer to EDIT in question:

It is possible to prepeare a state

$$|\psi\rangle = \frac{1}{\sqrt{m}}\sum_{i=0}^{m-1}|i\rangle,$$

where $m = 2^n$ and $n$ is a number of qubits, by application of operator $\otimes H ^{n} = H_{q_0} \otimes H_{q_1} \otimes \dots \otimes H_{q_{n-1}}$, i.e. Hadamard gate is applied on each qubit involved. As a results, you will get $n=\log{m}$ qubits in superposition described by uniform probability distribution. It is a generalization of construction provided in answer by met927

EDIT: based on comment by Adam Levine: "what if for example $m=5$?"

It that case you have to prepare entangled state and the approach is a little bit more intricated. For $m=5$ you have to prepare state (I switched to more common convention with states expressed in binary numbers instead of decimal):

$$ |\psi\rangle = \frac{1}{\sqrt{5}}(|000\rangle + |001\rangle + |010\rangle+|011\rangle+|100\rangle), $$

i.e. three qubits state where $|101\rangle$, $|110\rangle$ and $|111\rangle$ have zero probability.

To prepare an arbitrary state, you can employ approach presented in this article: Transformation of quantum states using uniformly controlled rotations.

Based on the article, a circuit preparing state $|\psi\rangle$ is this:


Here you can see results provided by IBM Q simulator:

enter image description here

Apparently, the circuit prepared desired state with uniformly distributed values from $|000\rangle$ to $|100\rangle$.

EDIT 2: here is a code in QASM of the circuit above:

include "qelib1.inc";

qreg q[3];
creg c[3];

ry(0.927) q[0];

ry(pi/4) q[1];
cx q[0],q[1];
ry(pi/4) q[1];
cx q[0],q[1];

ry(pi/2) q[2];
cx q[1],q[2];
ry(-pi/4) q[2];
cx q[0],q[2];
ry(pi/4) q[2];
cx q[1],q[2];
cx q[0],q[2];

measure q[0] -> c[2];
measure q[1] -> c[1];
measure q[2] -> c[0];
  • 1
    $\begingroup$ If $m \neq 2^{n}$ for example $m=5$, what should be the approach? $\endgroup$ – Adam Levine Feb 13 '20 at 5:49
  • $\begingroup$ @AdamLevine: Good question, see expanded answer. $\endgroup$ – Martin Vesely Feb 13 '20 at 7:16
  • $\begingroup$ Please share code for the above circuit $\endgroup$ – Adam Levine Feb 13 '20 at 9:38
  • $\begingroup$ @AdamLevine: Please find it in the answer. $\endgroup$ – Martin Vesely Feb 13 '20 at 11:12
  • $\begingroup$ Dear Martin Vesely, following the paper - " Transformation of quantum states using uniformly controlled rotations." did you solve it by pen and paper? In paper, $|a\rangle \mapsto |e_{1}\rangle$ is given (this is not applicable for our transformation since it is already in $|e_{1}\rangle$ form), but how do I convert $|e_{1}\rangle \mapsto |b\rangle$ (where $|b\rangle$ is the state we require)? $\endgroup$ – Adam Levine Feb 14 '20 at 15:17

The circuit you have described is formed of 2 qubits, both in an equal superposition. This can be achieved by applying the H gate to both qubits, as this puts each qubit into superposition and takes us up to 4 possible states. In the IBM Quantum Experience, this circuit would look like 2 qubit superposition


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.