Search⌘ K
AI Features

Simulating an Operation in Python

Explore how to simulate quantum gates and states in Python by applying matrix multiplication to single and multi-qubit systems. Understand how to create superpositions, implement CNOT gates, and scale gates to larger qubit systems using tensor products. This lesson guides you through practical quantum simulation techniques essential for quantum computing.

So far, we’ve learned how to create single and multi-qubit states. We’ve also learned how to represent quantum gates. In this lesson, we’ll put together both pieces and see how we can apply gates to states.

Recall that gates acting on states are simply a representation of matrix multiplication. Both states and gates are matrices. So, multiplying the two is fairly simple, especially when a single qubit is involved. Things get slightly more complicated for multiple qubits and we will get to that in the second half of the lesson.

Applying a quantum gate to a single qubit

First, let’s start off with applying a gate to a single qubit. Mathematically, an arbitrary gate, say GG, when applied to an arbitrary state ϕ|\phi\rangle, can be represented by the operation GϕG|\phi\rangle. In the case where the Pauli-X gate XX is applied to the state 0|0\rangle, we would get the following output:

X0=[0110][10]=[01]X|0\rangle=\begin{bmatrix}0&1\\1&0\end{bmatrix}\begin{bmatrix}1\\0\end{bmatrix}=\begin{bmatrix}0\\1\end{bmatrix} ...