mimiqcircuits.operations.readouterr¶
Readout error model.
Classes
|
Classical readout error on one bit, applied after a measurement. |
- class ReadoutErr(p0, p1=None)[source]¶
Bases:
OperationClassical readout error on one bit, applied after a measurement.
The operation flips the recorded bit at random: a 0 is reported as 1 with probability \(p_0\) and a 1 is reported as 0 with probability \(p_1\). This is the confusion matrix
\[\begin{split}\begin{pmatrix} P(0 | 0) & P(1 | 0) \\ P(0 | 1) & P(1 | 1) \end{pmatrix} = \begin{pmatrix} 1 - p_0 & p_0 \\ p_1 & 1 - p_1 \end{pmatrix},\end{split}\]where \(P(r | t)\) is the probability of reporting \(r\) when the true outcome is \(t\). The operation targets one classical bit and no qubits.
- Parameters:
p0 – Probability of reporting 1 when the outcome is 0, in \([0, 1]\). It may also be a 2×2 confusion matrix (numpy, sympy or symengine) as above, with
p1omitted; its entries must be numeric, in \([0, 1]\), with rows adding up to 1.p1 – Probability of reporting 0 when the outcome is 1, in \([0, 1]\).
A symbolic
p0orp1is not range checked.- Raises:
TypeError – If
p1is omitted andp0is not a matrix, or the matrix has symbolic entries.ValueError – If the matrix is not 2×2, has entries outside \([0, 1]\) or rows not adding up to 1, or if
p0orp1is outside \([0, 1]\).
Examples
>>> from mimiqcircuits import * >>> # 2% chance to read 1 instead of 0, 3% to read 0 instead of 1 >>> ReadoutErr(0.02, 0.03) RErr(0.02,0.03)
>>> # the same error from its confusion matrix >>> import numpy as np >>> ReadoutErr(np.array([[0.98, 0.02], ... [0.03, 0.97]])) RErr(0.02,0.03)
>>> # apply it to bit 0, where a measurement result is stored >>> c = Circuit() >>> c.push(Measure(), 0, 0) 1-qubit, 1-bit circuit with 1 instruction: └── M @ q[0], c[0] >>> c.push(ReadoutErr(0.01, 0.02), 0) 1-qubit, 1-bit circuit with 2 instructions: ├── M @ q[0], c[0] └── RErr(0.01, 0.02) @ c[0]
See also
NoiseModel.add_readout_noise(), which adds readout errors after measurements.- evaluate(d={})[source]¶
Return a copy with symbols in
p0andp1substituted by values.- Parameters:
d (dict) – Map from symbols to the values to substitute.
- Returns:
A new operation; a probability becomes a float once no symbol is left in it.
- Return type:
- Raises:
ValueError – If a substituted probability is outside \([0, 1]\).
- matrix()[source]¶
Return the confusion matrix
[[1 - p0, p0], [p1, 1 - p1]].- Returns:
The 2×2 confusion matrix.
- Return type:
symengine.Matrix
Examples
>>> from mimiqcircuits import * >>> ReadoutErr(0.25, 0.5).matrix() [0.75, 0.25] [0.5, 0.5]
- property parnames¶
Names of the operation’s parameters, as a tuple of strings.
Read-only: assigning to it raises
ValueError.