What additional options are available when using REM?#

Overview#

The main options the user has when using REM concern how to specify the inverse confusion matrix that is used to mitigate errors in the raw measurement (or “readout”) results. Currently Mitiq does not implement methods for estimating readout-error confusion matrices (which is a form of measurement noise calibration and therefore a device specific task), so the user must provide enough information to allow Mitiq to construct one. As described below, Mitiq’s options support the differing levels of information a user may have about the readout-error characteristics of their device. After the confusion matrix has been constructed, the remaining steps of standard REM are straightforward (compute the pseudoinverse of the confusion matrix and then apply this to the raw measurement results). For more information on what a confusion matrix is, see What is the theory behind REM?.

Options for specifying the inverse confusion matrix#

Mitiq provides two utility functions for constructing an inverse confusion matrix from user-provided information about a device’s confusion matrix. We describe these functions below and illustrate with toy examples. (Note that everything that follows is circuit-agnostic; it concerns how to represent a device’s noise model in the form required by REM).

Inverse confusion matrix from single-qubit noise model#

The function generate_inverse_confusion_matrix(num_qubits, p0, p1) embodies the simplest noise model possible, where one assumes that noise affects the measurement of each qubit independently and with the same confusion probabilities, specified by \(p_0 = Pr(1|0)\), the probability \(|0\rangle\) gets flipped to \(|1\rangle\) when measured, and \(p_1 = Pr(0|1)\), the probability \(|1\rangle\) gets flipped to \(|0\rangle\). The \(2 \times 2\) confusion matrix \(A_1\) for the \(1\)st qubit (and every other qubit) is then

\[\begin{split} \begin{bmatrix} 1-p_0 & p_1 \\ p_0 & 1-p_1 \end{bmatrix} \end{split}\]

and the joint \(2^n \times 2^n\) confusion matrix \(A\) for all \(n\) qubits is just \(n\) copies of \(A_1\) tensored together: \(A = A_1 \otimes \dots \otimes A_1 = A_1^{\otimes n}\).

To construct an inverse confusion matrix with generate_inverse_confusion_matrix() the user supplies the number of qubits and the single-qubit confusion matrix parameters \(p_0\) and \(p_1\). Here is an example with two qubits.

from functools import reduce

import numpy as np
from mitiq.rem import generate_inverse_confusion_matrix

# Confusion matrix for qubit 1
A1_entries = [
    0.9, 0.2,
    0.1, 0.8
]
A1 = np.array(A1_entries).reshape(2,2)

# Overall 2-qubit confusion matrix (tensor two copies of A1)
A = np.kron(A1, A1)

# Generate inverse confusion matrix.
# For this simple error model the user only has to
# specify the single qubit flip probabilities p0 and p1 
A_pinv = generate_inverse_confusion_matrix(2, p0=0.1, p1=0.2)

print(f"Confusion matrix:\n{A}\n")
print(f"Column-wise sums of confusion matrix:\n{A.sum(axis=0)}\n")
print(f"Inverse confusion matrix:\n{A_pinv}")
Confusion matrix:
[[0.81 0.18 0.18 0.04]
 [0.09 0.72 0.02 0.16]
 [0.09 0.02 0.72 0.16]
 [0.01 0.08 0.08 0.64]]

Column-wise sums of confusion matrix:
[1. 1. 1. 1.]

Inverse confusion matrix:
[[ 1.30612245 -0.32653061 -0.32653061  0.08163265]
 [-0.16326531  1.46938776  0.04081633 -0.36734694]
 [-0.16326531  0.04081633  1.46938776 -0.36734694]
 [ 0.02040816 -0.18367347 -0.18367347  1.65306122]]

Note

In each code example we show an explicit computation of the full \(2^n \times 2^n\) confusion matrix \(A\) from the smaller, local confusion matrices supplied by the user, but this is solely for expository purposes. When applying REM in practice only the pseudoinverse \(A^{+}\) needs to be computed: the user supplies one or more local confusion matrices, and Mitiq’s utility functions can directly compute \(A^{+}\) from these.

Inverse confusion matrix from \(k\) local confusion matrices#

The function generate_tensored_inverse_confusion_matrix(num_qubits, confusion_matrices) can be applied to any \(n\)-qubit confusion matrix \(A\) which is factorized into the tensor product of \(k\) smaller, local confusion matrices (supplied by the user in confusion_matrices), one for each subset in a partition of the \(n\) qubits into \(k\) smaller subsets. The factorization encodes the assumption that there are \(k\) independent/uncorrelated noise processes affecting the \(k\) disjoint subsets of qubits (possibly of different sizes), but within each subset noise may be correlated between qubits in that subset. This model includes the simplest noise model above as the special case where \(k=n\) and each of the \(n\) single-qubit subsets has the same confusion matrix \(A_1\):

\[ A = A^{(1)}_1 \otimes \dots \otimes A^{(n)}_1. \]

For a slightly more nuanced model, one could still assume independent noise across qubits, but specify different \(2 \times 2\) confusion matrices for each qubit:

\[ A = A^{(1)}_1 \otimes \dots \otimes A^{(n)}_n. \]

Here is an example with two qubits.

from mitiq.rem import generate_tensored_inverse_confusion_matrix

# Confusion matrix for qubit 1 (same as above)
A1_entries = [
    0.9, 0.2,
    0.1, 0.8
]
A1 = np.array(A1_entries).reshape(2,2)

# A different confusion matrix for qubit 2
A2_entries = [
    0.7, 0.4,
    0.3, 0.6
]
A2 = np.array(A2_entries).reshape(2,2)

# Overall 2-qubit confusion matrix (A1 tensor A2)
A = np.kron(A1, A2) 

# Generate inverse confusion matrix.
A_pinv = generate_tensored_inverse_confusion_matrix(2, confusion_matrices=[A1, A2]) 

print(f"Confusion matrix:\n{A}\n")
print(f"Column-wise sums of confusion matrix:\n{A.sum(axis=0)}\n")
print(f"Inverse confusion matrix:\n{A_pinv}")
Confusion matrix:
[[0.63 0.36 0.14 0.08]
 [0.27 0.54 0.06 0.12]
 [0.07 0.04 0.56 0.32]
 [0.03 0.06 0.24 0.48]]

Column-wise sums of confusion matrix:
[1. 1. 1. 1.]

Inverse confusion matrix:
[[ 2.28571429 -1.52380952 -0.57142857  0.38095238]
 [-1.14285714  2.66666667  0.28571429 -0.66666667]
 [-0.28571429  0.19047619  2.57142857 -1.71428571]
 [ 0.14285714 -0.33333333 -1.28571429  3.        ]]

More generally, one can provide generate_tensored_inverse_confusion_matrix() with a list of \(k\) confusion matrices of any size (for any \(k\), \(1\leq k \leq n\)), as long as their dimensions when tensored together give an overall confusion matrix of the correct dimension \(2^{n} \times 2^{n}\). For instance, the first confusion matrix might apply to qubits \(1\) and \(2\) while the \(k\)th applies to qubits \(n-2, n-1, n\):

\[ A = A^{(1)}_{1,2} \otimes \dots \otimes A^{(k)}_{n-2, n-1, n}. \]

Here is an example with three qubits. We represent a stochastic noise model in which errors on qubit \(1\) are independent of errors on qubits \(2\) and \(3\), but errors on qubits \(2\) and \(3\) are correlated with each other. So the confusion matrix factorizes into two differently sized sub-matrices \(A = A^{(1)}_1 \otimes A^{(2)}_{2,3}\).

# Confusion matrix for qubit 1 (same as above)
A1_entries = [
    0.9, 0.2,
    0.1, 0.8
]
A1 = np.array(A1_entries).reshape(2,2)

# Generate a random 4x4 confusion matrix (square
# with columns summing to 1) to represent a
# a correlated error model on qubits 2 and 3
matrix = np.random.rand(4,4)
A23 = matrix/(matrix.sum(axis=0)[None,:])

# Overall 3-qubit confusion matrix (A1 tensor A23)
A = np.kron(A1, A23)

# Generate inverse confusion matrix.
A_pinv = generate_tensored_inverse_confusion_matrix(3, [A1, A23])

print(f"Confusion matrix:\n{A}\n")
print(f"Column-wise sums of confusion matrix:\n{A.sum(axis=0)}\n")
print(f"Inverse confusion matrix:\n{A_pinv}")
Confusion matrix:
[[0.4291179  0.20413276 0.18135097 0.24486379 0.09535953 0.04536283
  0.04030021 0.05441418]
 [0.06077237 0.16677098 0.17219499 0.30036937 0.01350497 0.03706022
  0.03826555 0.06674875]
 [0.18344091 0.14746447 0.2340959  0.17699712 0.04076465 0.03276988
  0.05202131 0.03933269]
 [0.22666882 0.38163179 0.31235814 0.17776971 0.05037085 0.08480706
  0.06941292 0.03950438]
 [0.04767977 0.02268142 0.02015011 0.02720709 0.38143813 0.18145134
  0.16120086 0.21765671]
 [0.00675249 0.01853011 0.01913278 0.03337437 0.05401988 0.14824087
  0.15306221 0.266995  ]
 [0.02038232 0.01638494 0.02601066 0.01966635 0.16305859 0.13107953
  0.20808525 0.15733078]
 [0.02518542 0.04240353 0.03470646 0.01975219 0.2014834  0.33922826
  0.27765168 0.15801752]]

Column-wise sums of confusion matrix:
[1. 1. 1. 1. 1. 1. 1. 1.]

Inverse confusion matrix:
[[ 2.9794074  -2.15083235  0.3020619  -0.77048513 -0.74485185  0.53770809
  -0.07551547  0.19262128]
 [ 0.63333565  1.26572592 -7.90205714  4.85670549 -0.15833391 -0.31643148
   1.97551429 -1.21417637]
 [-3.55133706 -2.64528753 10.35002667 -0.94373635  0.88783426  0.66132188
  -2.58750667  0.23593409]
 [ 1.08145116  4.6732511  -1.60717428 -1.99962687 -0.27036279 -1.16831278
   0.40179357  0.49990672]
 [-0.37242592  0.26885404 -0.03775774  0.09631064  3.35183332 -2.4196864
   0.33981963 -0.86679577]
 [-0.07916696 -0.15821574  0.98775714 -0.60708819  0.7125026   1.42394166
  -8.88981429  5.46379368]
 [ 0.44391713  0.33066094 -1.29375333  0.11796704 -3.99525419 -2.97594847
  11.64378    -1.06170339]
 [-0.13518139 -0.58415639  0.20089678  0.24995336  1.21663255  5.25740749
  -1.80807106 -2.24958023]]