# Use of $X$ gates in creating probability distribution in a quantum circuit

I have been trying to understand the Grover-Rudolph scheme for loading a probability distribution into a quantum circuit. This article gives a demonstration of this scheme by creating a probability distribution of 8 states in a quantum circuit.

My question is about the use of $$X$$ gates in the circuit. I don't quite understand the reasoning behind their placements. I want to be able to go deeper into the algorithm, creating maybe 128 states in a 7-qubit circuit, but to do so, I need to understand when to use an $$X$$ gate.

• Qiskit has implemented many such probability loading circuits in the framework, you can make use of LogNormal, Normal, from here : qiskit-community.github.io/qiskit-finance/stubs/… If you want to build a $2^7$ states, you just make a circuit with this many number of qubits and compose the probability distribution you want to load. i.e if just making the state is your end goal. Commented Feb 1 at 15:23
• or you can look at this answer here and make use of Quantum GAN to load the probability distribution you want: quantumcomputing.stackexchange.com/questions/23702/… Commented Feb 1 at 15:25

The $$X$$ gates are a transformation of the conditional RY rotation gates. You could compute $$(X \otimes I) \text{CR}_Y (X \otimes I)$$ (where $$\text{CR}_Y$$ is the conditional $$R_Y$$ gate) to find a reduced version of the circuit if you like. I find it's
\begin{align} (X \otimes I) \text{CR}_Y (X \otimes I) &= \begin{pmatrix} 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ \end{pmatrix} \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos(\frac{\theta}{2}) & -\sin(\frac{\theta}{2}) \\ 0 & 0 & \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) \\ \end{pmatrix} \begin{pmatrix} 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ \end{pmatrix} \\ &= \begin{pmatrix} \cos(\frac{\theta}{2}) & -\sin(\frac{\theta}{2}) & 0 & 0 \\ \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{pmatrix} \end{align}
A similar computation can be done for the double conditional $$R_Y$$ gate and so on.
The $$R_Y$$ gate is nice to use in the tutorial you mentioned because it will only produce quantum states with real amplitudes (if the initial state amplitudes are all real). You can avoid complex amplitudes all together. You only need real amplitudes to produce the desired probabilities. However, complex amplitudes would also do it.