In qiskit, the error correction using least squares is apparently in qiskit-ignis/qiskit/ignis/mitigation/measurement/filters.py, source code from github and reads:

# Apply the correction
    for data_idx, _ in enumerate(raw_data2):

        if method == 'pseudo_inverse':
            raw_data2[data_idx] = np.dot(
                pinv_cal_mat, raw_data2[data_idx])

        elif method == 'least_squares':
            nshots = sum(raw_data2[data_idx])

            def fun(x):
                return sum(
                    (raw_data2[data_idx] - np.dot(self._cal_matrix, x))**2)
            x0 = np.random.rand(len(self._state_labels)) # ********
            x0 = x0 / sum(x0)                            # ********
            cons = ({'type': 'eq', 'fun': lambda x: nshots - sum(x)})
            bnds = tuple((0, nshots) for x in x0)
            res = minimize(fun, x0, method='SLSQP',
                           constraints=cons, bounds=bnds, tol=1e-6)
            raw_data2[data_idx] = res.x

            raise QiskitError("Unrecognized method.")

I'm not too skilled in python and I would not like to change my qiskit's base installation. I have marked with * the two lines that seems to me strange.

My question is: in this error correction, one does least squares to minimize the function $F=|c_{\rm exp} - Mc_{\rm corr}|^2$, where $c_{\rm exp}, c_{\rm corr}$ are the experimental and corrected counts, respectively and $M$ is the "correction matrix".

As it is common, minimize requires a fair guess x0 in order to find the answer of $F$. I don't understand why the built-in function sets x0 as a random vector. Ok, I can buy that the method "does not know which previous circuit was ran", but in theory if one knows the circuit, one should choose x0 based on this information, right?


1 Answer 1


So yeah it is not the best choice. My guess is the individual who programmed it did not think about the physics of the problem. In short, it is best to use the raw input data as the starting point when measurement errors are small. In practice this gives you much faster convergence.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.