Simulating Quantum States in Python

In this chapter, we'll see how we can represent and simulate quantum states in Python.

For this chapter, we shall use NumPy to create and manipulate arrays and matrices. While it certainly helps to be familiar with NumPy, you should be able to follow these tutorials even without much experience with the library. We shall soon shift to proper libraries dedicated to quantum computing, but it helps to familiarize yourself with what goes on under the hood before using library functions. This chapter and its code examples will also form the basis of creating our very own quantum computing simulator at the end.

Representing the computational basis states

Recall that a quantum state is a vector in 2-D complex space. A vector can be easily represented in Python using lists. As stated earlier, we’ll be using NumPy for this.

Below is an example of the states 0=|0\rangle= [10]\begin{bmatrix} 1\\ 0 \end{bmatrix}, and 1=|1\rangle= [01]\begin{bmatrix} 0\\ 1 \end{bmatrix}.

Get hands-on with 1200+ tech skills courses.