# States and operators

Having seen some of the typical maths you need in part I and part II we’ll turn now to some Python showing how to simulate quantum systems.

I’ll use below the QuTip Python library but there are other very nice libs out there. Also, if Python is not your cup of tea you can also take a look at this list of QC simulators here, the Liquid F# lib in particular.

## States

Creating qubits, bras and kets goes typically likes this:

which returns the $|0\rangle$ state in a 4-dimensional space:

$\begin{pmatrix}1.0 \\ 0.0\\0.0\\0.0 \end{pmatrix}$

The tangled EPR state is hence

$\begin{pmatrix}0.707 \\ 0.0\\0.0\\0.707 \end{pmatrix}$

We saw earlier that qubits can be represented on a Bloch sphere and the library gives you easy access to visualizations:

The sigmax, sigmay, sigmaz above are the Pauli spin matrices. Turning the states into a density matrix can be done with the ket2dm command:

$\begin{pmatrix}0.5 & 0.0 & 0.0 & 0.5\\ 0.0 & 0.0 & 0.0 & 0.0\\0.0 & 0.0 & 0.0 & 0.0\\0.5 & 0.0 & 0.0 & 0.5 \end{pmatrix}$

Remember that this is nothing but turning an arbitrary ket $|\psi\rangle$ into a matrix $|\psi\rangle\langle\psi|$.

Tensor products are obtained using the tensor method. For example, creating the tensor product of $\sigma_x\otimes\sigma_y$:

$\begin{pmatrix}0.0 & 0.0 & 0.0 & -1.0j\\ 0.0 & 0.0 & 1.0j & 0.0\\0.0 & -1.0j & 0.0 & 0.0\\1.0j & 0.0 & 0.0 & 0.0 \end{pmatrix}$

so, $(\sigma_x\otimes\sigma_y)(|1\rangle\otimes|0\rangle)$ is hence

$\begin{pmatrix}0.0 \\ 1.0j\\0.0\\0.0 \end{pmatrix}$.

## Operators

Operators are created via the Qobj

and applied via multiplication on a state

$\begin{pmatrix}5.0j \\ -5.0j \end{pmatrix}$.

Eigenstates and eigenvalues are fetched via the eigenstates method on the operator

$\begin{pmatrix}-0.707j \\ -0.707j \end{pmatrix}$.