# How to prepare mixed states on a quantum computer?

I am a little bit confused by density matrix notation in quantum algorithms. While I am pretty confident with working with pure states, I never had the need to work with algorithm using density matrices. I am aware we can have/create a quantum register proportional to a density matrix by tracing out some qubits on a bigger states, but I don't have any intuition to how this can be done in practice on a quantum computer.

It is simple with just an Hadamard gate (for n being a power of 2) to prepare the following state:

$$|\psi\rangle = \frac{1}{\sqrt{n}} \sum_i^n |i\rangle$$ The density matrix version of this state is: $$\sigma= \sum_{i,y}^{n,n} |i\rangle\langle y|$$

But instead, I would like to know how to prepare a quantum register in the following state: $$\rho = \frac{1}{n}\sum_{i}^{n} |i\rangle\langle i|$$

Unfortunately, I have no intuition how I can think this state in a quantum register, as I am too used to work with pure state. The density matrix should incorporate our (classical) ignorance about a quantum system, but why should I ignore the outcome of discarding (i.e. measuring) a bigger state that gives me the totally mixed state on a quantum computer?

Rephrased in other words my question is: what is the pure state state of $$\rho$$? We know it must exist, because density matrices of pure states have the property that $$\rho^2 = \rho$$ page 20 of preskill's lecture notes. Intuitively, is $$\psi$$, but it is not, as $$\sigma \neq \rho$$.

• But the $\rho$ that you’ve given does not satisfy $\rho^2=\rho$. – DaftWullie Feb 19 at 6:42

Easiest way to prepare a mixed state is to decompose it into a sum of pure states that are easy to construct, and then classically make a random selection.

Sure, it's now in some pure state, but from the point of view of someone who doesn't know which that is, it's in a mixed state.

As far as I can tell, there's no good reason ever to work with mixed states that aren't Bell pair halves or something else entangled. Pure states are simpler, and a mixed state is essentially just a piece of a pure state. If you don't care about the thing the pure state's entangled with, why not just make a random selection?

• I rephrased better the question, now it should be clearer. – leimer0rozzh Feb 19 at 3:53

Given an arbitrary state $$\rho$$ in a space $$H_A$$, you can always find a pure state $$\newcommand{\tr}{\operatorname{Tr}}\newcommand{\ket}[1]{|#1\rangle}\newcommand{\ketbra}[1]{|#1\rangle\!\langle #1|}\ket\psi$$ on some $$H_A\otimes H_B$$ such that $$\rho=\tr_B(\ketbra\psi)$$. Any such $$\ket\psi$$ is called a purification of $$\rho$$. If the eigendecomposition of your $$\rho$$ reads $$\rho=\sum_k p_k\ketbra{\psi_k}$$, any pure of the form $$\ket\psi = \sum_k \sqrt{p_k} \ket{\psi_k}\otimes\ket{u_k},$$ for any set of orthonormal vectors $$\ket{u_k}$$, is a viable purification.

To actually generate experimentally such a $$\rho$$, two straightforward ways are

1. Actually run the experiment using the different $$\ket{\psi_k}$$ as input, rather than $$\rho$$. You can then mix the experimental outcomes according to the weights $$p_k$$. This will give you identical answers as if you used $$\rho$$.
2. Use a purification $$\ket\psi$$ as input for the experiment, but only operate and measure a part of the system (what we denoted with $$H_A$$ above).

The density matrix should incorporate our (classical) ignorance about a quantum system, but why should I ignore the outcome of discarding (i.e. measuring) a bigger state that gives me the totally mixed state on a quantum computer?

This depends on why you want to use a non-pure state to begin with.