跳转至

ReadoutError

QuICT.core.noise.ReadoutError

ReadoutError(prob: Union[List, ndarray])

The Readout error class

Example

p(n|m) describe the probability of getting the noise outcome n with the truly measured result m. \n The ReadoutError for 1 qubit: \n

\[ P = \begin{bmatrix} p(0|0) & p(1|0) \\ p(0|1) & p(1|1) \\ \end{bmatrix} = \begin{bmatrix} 0.8 & 0.2 \\ 0.3 & 0.7 \\ \end{bmatrix} \]

The ReadoutError for 2 qubit:

\[ P = \begin{bmatrix} p(00|00) & p(01|00) & p(10|00) & p(11|00) \\ p(00|01) & p(01|01) & p(10|01) & p(11|01) \\ p(00|10) & p(01|10) & p(10|10) & p(11|10) \\ p(00|11) & p(01|11) & p(10|11) & p(11|11) \\ \end{bmatrix} \]
Important

The sum of each rows in the prob should equal to 1.

Parameters:

  • prob ((List, ndarray)) –

    The probability of outcome assignment

Source code in QuICT/core/noise/readout_error.py
def __init__(self, prob: Union[List, np.ndarray]):
    self._prob = self._probability_check(prob)
    self._qubits = int(np.log2(self._prob.shape[0]))
    self._type = NoiseChannel.readout

apply_to_qubits

apply_to_qubits(measured_result: int) -> int

Apply current Readout Noise to this measured result.

Parameters:

  • measured_result (int) –

    The given measured result.

Returns:

  • int ( int ) –

    the noise result

Source code in QuICT/core/noise/readout_error.py
def apply_to_qubits(self, measured_result: int) -> int:
    """ Apply current Readout Noise to this measured result.

    Args:
        measured_result (int): The given measured result.

    Returns:
        int: the noise result
    """
    prob = np.random.random()
    related_prob_error = self._prob[measured_result]
    for idx, error_prob in enumerate(related_prob_error):
        if prob <= error_prob:
            return idx

        prob -= error_prob

compose

compose(other)

Compose the Readout Noise with other Readout Noise.

\[ P_{comp} = P \cdot P_{o} \]
Source code in QuICT/core/noise/readout_error.py
def compose(self, other):
    """ Compose the Readout Noise with other Readout Noise.

    $$
        P_{comp} = P \cdot P_{o}
    $$

    """
    assert isinstance(other, ReadoutError)

    left_prob, right_prob = self.prob, other.prob
    if self.qubits > other.qubits:
        right_prob = other.expand(self.qubits - other.qubits).prob
    elif self.qubits < other.qubits:
        left_prob = self.expand(other.qubits - self.qubits).prob

    compose_prob = dot(left_prob, right_prob)
    return ReadoutError(compose_prob)

expand

expand(extend_qubits: int, change_itself: bool = False)

Expand noise with size of extend_qubits.

\[ P_{exp} = P \otimes I_n \]

where n is the extend qubit number.

Source code in QuICT/core/noise/readout_error.py
def expand(self, extend_qubits: int, change_itself: bool = False):
    r""" Expand noise with size of extend_qubits.

    $$
        P_{exp} = P \otimes I_n
    $$

    where n is the extend qubit number.
    """
    extra_identity = np.identity(2 ** extend_qubits)
    expand_prob = tensor(self.prob, extra_identity)

    if change_itself:
        self._prob = expand_prob
        self._qubits += extend_qubits
    else:
        return ReadoutError(expand_prob)

is_identity

is_identity() -> bool

Whether self.prob is identity matrix.

Source code in QuICT/core/noise/readout_error.py
def is_identity(self) -> bool:
    """ Whether self.prob is identity matrix. """
    id_matrix = np.identity(2 ** self._qubits)
    if np.allclose(self._prob, id_matrix, rtol=1e-6):
        return True

    return False

power

power(n: int)

Power the Readout Noise with n.

\[ P_{pow} = P^n \]
Source code in QuICT/core/noise/readout_error.py
def power(self, n: int):
    """ Power the Readout Noise with n.

    $$
        P_{pow} = P^n
    $$

    """
    assert isinstance(n, int)

    based_prob = copy.deepcopy(self.prob)
    for _ in range(1, n):
        based_prob = dot(based_prob, self.prob)

    return ReadoutError(based_prob)

tensor

tensor(other)

Tensor the Readout Noise with other Readout Noise.

\[ P_{ten} = P \otimes P_{o} \]
Source code in QuICT/core/noise/readout_error.py
def tensor(self, other):
    """ Tensor the Readout Noise with other Readout Noise.

    $$
        P_{ten} = P \otimes P_{o}
    $$

    """
    assert isinstance(other, ReadoutError)

    tensor_prob = tensor(self.prob, other.prob)
    return ReadoutError(tensor_prob)