# A question about quantum circuit simulation on PC

In classical logic circuit consisting of AND, OR and others, common gates can be realized by electrnic signal. Each time cycle can run a function unit like the picture below.

Now I have read many paper and try to understand how to simulate quantum circuits on classical computer. They just tell me the circuits can be changed by "HT circuit (Hadmard+ Toffoli)". However, they don't tell me how to simulate a Hadmard gate and how to simulate the entangled state after Hadmard gate.

Is that means we can just translate the Quantum circuit to something just like a traditional circuit and run each function unit in a time cycle?

• Hi and welcome to Quantum Computing SE. Could you please add a link to any paper you are refering to in question in order to provide you with clearer answer? Currently, your question seem too broad. Do you want to simulate quantum computer on classical one? – Martin Vesely Apr 21 at 15:56
• yes, I mean, I just try to understand how the quantum circuit simulation work on classical computer, and arxiv.org/pdf/0811.0898.pdf this paper told me all the circuits can be simplified by HT circuits, and OFC I know Toffoli,CNOT,NOT Gates can be simulated by classical computer, but i don't understand how is that possible for classical computer to simulate Hadamard, because I know know how the classical computer do entanglement? and I guess it should be simulated 2^n times to replace the entanglement, i dont know if it is true. Can u help me? Thx – Henry_Fordham Apr 21 at 23:13

There are more ways to simulation of a quantum computer on classical one. For example, you can introduce different noise models to simulate quantum fluctuations. However, I will give you an example of simulator I implemented in MatLab. In this simulator I assume no noise, i.e. ideal quantum computer is simulated and returned results follow a theory.

The basics idea behind the simulator is to use Deutsch model of qunatum computing. This means that each quantum gate is described by unitary matrix $$U$$ of type $$N \,\text{x}\, N$$ and quantum state by complex unit vector $$|\psi\rangle$$ (i.e. $$|\psi\rangle \in\mathbb{C}^N|\,|\psi\rangle\,| = 1$$). Note that $$N = 2^n$$ where $$n$$ is a number of qubits involved.

Now, lets look at matrix representation of Hadamard gate you are looking for:

$$H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}.$$

There is many gates in quantum computing, see this list for their matrix representation.

Acting of quantum gate $$U$$ on quantum state $$|\psi\rangle$$ is described by matrix multiplication, i.e. $$U|\psi\rangle$$.

For example, lets have a qubit in state $$|0\rangle = \begin{pmatrix}1\\0\end{pmatrix}$$ and apply Hadamard gate:

$$H|0\rangle = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \begin{pmatrix}1\\0\end{pmatrix} = \frac{1}{\sqrt{2}} \begin{pmatrix}1\\1\end{pmatrix}$$

So, now your qubit is in superposition of states $$|0\rangle$$ and $$|1\rangle$$. Note that in your question, you are talking about entangled state after Hadamard. This gate does not produce entangled state but superposition as I mentioned above.

To produce entangled state, you need controlled gate, for example CNOT (controlled NOT) acting on two qubits. This gate is descibed by matrix $$\text{CNOT} = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0\\ \end{pmatrix}$$

The gate negate second qubit (so-called target qubit) in case the first qubit (control qubit) is in state $$|1\rangle$$ otherwise it does nothing.

Here is an example of simple circuit (note: the figure was taken from Wiki):

.

Lets now have a look on how simulate the circuit with approach introduced above. Firstly Hadamard gate is applied on first qubit and nothing on second qubit. The nothing means there is a identity operator described by unit matrix $$I$$. This step of algorithm is expressed as

$$H \otimes I = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \otimes \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} =\frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 0 & 1 & 0\\ 0 & 1 & 0 & 1\\ 1 & 0 & -1 & 0\\ 0 & 1 & 0 & -1\\ \end{pmatrix}$$

Note that the symbol $$\otimes$$ means tensor product.

Second step in the circuit is CNOT gate. To get matrix description of whole circuit all steps have to be multiplied, i.e. the circuit is depicted by matrix $$\text{CNOT} (H \otimes I)$$.

To get final state of the cirucit after application on input, we have to multiply the input state with matrix describing the circuit. The input is state $$|00\rangle = |0\rangle \otimes |0\rangle = \begin{pmatrix}1 \\0\\0\\0\end{pmatrix}$$, i.e. both input qubits are in state $$|0\rangle$$. Hence we have

$$\text{CNOT}(H \otimes I)|00\rangle = \frac{1}{\sqrt{2}} \begin{pmatrix} 1\\0\\0\\1 \end{pmatrix} = \frac{1}{\sqrt{2}} \begin{pmatrix} 1\\0\\0\\0 \end{pmatrix}+\frac{1}{\sqrt{2}} \begin{pmatrix} 0\\0\\0\\1 \end{pmatrix}= \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle).$$

After measurement, the output state will be either $$|00\rangle$$ or $$|11\rangle$$, both with probability $$\frac{1}{2}$$ because $$\Big(\frac{1}{\sqrt{2}}\Big)^2 = \frac{1}{2}$$.