# Measuring qubits in QuTiP

How can you measure qubits in QuTiP?

As far as I have seen you can define a Hamiltonian and let it evolve in time. It is also possible to define a quantum circuit, however, measuring and running it is not possible.

Does anyone know how to do this?

A simple circuit could be

H q
CNOT q,q
Measure q, q


QuTiP is not really meant for this I think. As said on the home page :

QuTiP is open-source software for simulating the dynamics of open quantum systems.

Simulating dynamics of open quantum systems by definition means you are interested in the quantum state as a result of your algorithm.

I tried looking at the Notebook examples provided in this Github but could not find measurement examples somewhere. You have a possibility to get expectation values though (see this notebook).

Main purpose of Qutip is to explore dynamics of quantum systems and therefore density matrices are the tool to use. According to this answer on Quantum computing, we can model a measurement operator Pi on a density matrix. In the case of the measurement of a single qubit in the computational basis, you have $$P_0=|0\rangle\langle 0|\qquad P_1=|1\rangle\langle 1|$$

If you want to talk about n qubits where you measure just the first one, then you use the measurement operators

$$P_0=|0\rangle\langle 0|\otimes\mathbb{I}^{\otimes(n-1)}\qquad P_1=|1\rangle\langle 1|\otimes\mathbb{I}^{\otimes(n-1)}$$

Implementation with the Qutip dag method. First we set up a two level quantum system with the basis method use a vector v0 for the zero vector and v1 for one vector.

v0 = qp.basis(2, 0)

Calculate outer product with the dag method this will give a density operator

P0 = v0 * v0.dag()

expand for multiqubit gate

M0 = qp.gate_expand_1toN(P0, self.activeQubits, qubitNum)

Also

v1 = qp.basis(2, 1)

You can find a basic qubit quantum simulator running on Qutip in the SimulaQron software.

SimulaQron crudeSimulator

Here. Scroll down to the stochastic solver, and you'll find an attribute for storing measurements.

It's certainly not the emphasis of the package, as cnada pointed out, but it's there.