跳转至

NoiseError

QuICT.core.noise.NoiseGate

NoiseGate(qubits: int, gates: List[Tuple[BasicGate, List[int]]])
Source code in QuICT/core/noise/noise_error.py
def __init__(self, qubits: int, gates: List[Tuple[BasicGate, List[int]]]):
    self._qubits = qubits
    self._gate = self._build_gate(gates) if isinstance(gates, list) else gates

QuICT.core.noise.QuantumNoiseError

QuantumNoiseError(ops: List[Tuple[NoiseGate, float]])

The based class for quantum noise error.

Example

quantum_error = QuantumNoiseError([(error_matrix1, 0.4), (error_matrix2, 0.6)])

Parameters:

  • ops (List[Tuple(error_matrix) –

    np.ndarray, prob: float)]): The noise error operators, the sum of the probabilities should be 1.

Source code in QuICT/core/noise/noise_error.py
def __init__(self, ops: List[Tuple[NoiseGate, float]]):
    assert isinstance(ops, list), TypeError("QuantumNoiseError.ops", "list", type(ops))

    # Initial NoiseGate and probability
    self._operators = ops
    self._qubits = self._operators[0][0].qubit_number
    self._type = NoiseChannel.unitary

operators property

operators

The noise error's matrix.

qubits property

qubits

The number of qubits.

type property writable

type

The type of noise error.

compose

compose(other)

generate composed noise error with self and other.

Source code in QuICT/core/noise/noise_error.py
def compose(self, other):
    """ generate composed noise error with self and other. """
    assert isinstance(other, QuantumNoiseError), TypeError(
        "QuantumNoiseError.compose", "QuantumNoiseError", type(other)
    )

    if self.qubits >= other.qubits:
        left_operator, right_operator = self.operators, other.operators
    else:
        left_operator, right_operator = other.operators, self.operators

    composed_ops = []
    for noise_gate, prob in left_operator:
        for other_noise_gate, other_prob in right_operator:
            _new_gate = noise_gate.copy()
            _new_gate.compose(other_noise_gate)
            composed_ops.append((_new_gate, prob * other_prob))

    return QuantumNoiseError(composed_ops)

prob_mapping_operator

prob_mapping_operator(prob: float) -> CompositeGate

Return the related noise error's matrix with given probability. The given probability should within [0, 1].

Source code in QuICT/core/noise/noise_error.py
def prob_mapping_operator(self, prob: float) -> CompositeGate:
    """ Return the related noise error's matrix with given probability.
    The given probability should within [0, 1].
    """
    for ngate, error_prob in self._operators:
        if prob <= error_prob:
            return ngate.gates

        prob -= error_prob

    return None

tensor

tensor(other)

generate tensor noise error with self and other.

Source code in QuICT/core/noise/noise_error.py
def tensor(self, other):
    """ generate tensor noise error with self and other. """
    assert isinstance(other, QuantumNoiseError), TypeError(
        "QuantumNoiseError.tensor", "QuantumNoiseError", type(other)
    )

    tensor_ops = []
    for noise_gate, prob in self.operators:
        for other_noise_gate, other_prob in other.operators:
            _new_gate = noise_gate.copy()
            _new_gate.tensor(other_noise_gate)
            tensor_ops.append((_new_gate, prob * other_prob))

    return QuantumNoiseError(tensor_ops)

to_matrix

to_matrix() -> list

generate kraus operator with given gate's matrix.

Source code in QuICT/core/noise/noise_error.py
def to_matrix(self) -> list:
    """ generate kraus operator with given gate's matrix. """
    all_matrix = []
    for ngate, prob in self.operators:
        matrix = ngate.matrix()
        all_matrix.append(np.sqrt(prob) * matrix)

    return all_matrix

QuICT.core.noise.PauliError

PauliError(ops: List[Tuple[str, float]], num_qubits: int = 1)

Bases: QuantumNoiseError

Pauli Error; Including Bit Flip and Phase Flip

Example

PauliError([('i', 0.3), ('x', 0.7)])

Parameters:

  • ops (List[Tuple[str, float]]) –

    The operators for pauli error.

  • num_qubits (int, default: 1 ) –

    The number of target qubits. Defaults to 1.

Source code in QuICT/core/noise/noise_error.py
def __init__(self, ops: List[Tuple[str, float]], num_qubits: int = 1):
    if not isinstance(ops, (list, tuple)):
        raise TypeError("PauliError.ops", "[list, tuple]", type(ops))

    # Building noise error operators List[(pauli_matrix, prob)].
    operators, sum_prob = [], 0
    for op, prob in ops:
        sum_prob += prob
        if prob < 0 or prob > 1:
            raise ValueError("PauliError.ops.prob", "[0, 1]", prob)

        op = op.ljust(num_qubits, 'i')
        if len(op) > num_qubits:
            raise PauliNoiseUnmatchedError("Pauli Error get wrong input.")

        gates = []
        for idx, g in enumerate(op):
            if g not in list(self._BASED_GATE.keys()):
                raise ValueError("PauliError.ops", "[i, x, y, z]", g)

            gates.append((self._BASED_GATE[g], [idx]))

        operators.append((NoiseGate(num_qubits, gates), prob))

    # Initial PauilError
    super().__init__(operators)
    self._origin_ops = ops
    self.type = NoiseChannel.pauil

QuICT.core.noise.BitflipError

BitflipError(prob: float)

Bases: PauliError

Special Case for PauilError, with fixed Pauil Operator: [('x', prob), ('i', 1 - prob)]

Parameters:

  • prob (float) –

    The probability to flip the qubit.

Source code in QuICT/core/noise/noise_error.py
def __init__(self, prob: float):
    ops = [('i', 1 - prob), ('x', prob)]

    super().__init__(ops)

QuICT.core.noise.PhaseflipError

PhaseflipError(prob: float)

Bases: PauliError

Special Case for PauilError, with fixed Pauil Operator: [('z', prob), ('i', 1 - prob)]

Parameters:

  • prob (float) –

    The probability of fliping the phase.

Source code in QuICT/core/noise/noise_error.py
def __init__(self, prob: float):
    ops = [('i', 1 - prob), ('z', prob)]

    super().__init__(ops)

QuICT.core.noise.PhaseBitflipError

PhaseBitflipError(prob: float)

Bases: PauliError

Special Case for PauilError, with fixed Pauil Operator: [('y', prob), ('i', 1 - prob)]

Parameters:

  • prob (float) –

    The probability of fliping the qubit and phase.

Source code in QuICT/core/noise/noise_error.py
def __init__(self, prob: float):
    ops = [('i', 1 - prob), ('y', prob)]

    super().__init__(ops)

QuICT.core.noise.DepolarizingError

DepolarizingError(prob: float, num_qubits: int = 1)

Bases: PauliError

The Depolarizing Error

Parameters:

  • prob (float) –

    The probability of depolarizing.

  • num_qubits (int, default: 1 ) –

    The number of qubits have depolarizing error. Defaults to 1.

Source code in QuICT/core/noise/noise_error.py
def __init__(self, prob: float, num_qubits: int = 1):
    if not isinstance(prob, float):
        raise TypeError("DepolarizingError.prob", "float", type(prob))

    if not isinstance(num_qubits, int):
        raise TypeError("DepolarizingError.number_qubits", "int", type(prob))

    assert num_qubits >= 1, ValueError("DepolarizingError.num_qubits", ">= 1", num_qubits)
    num_ops = 4 ** num_qubits
    max_prob = num_ops / (num_ops - 1)
    if prob < 0 or prob > max_prob:
        raise ValueError("DepolarizingError.prob", f"[0, {max_prob}]", prob)

    probs = [1 - prob / max_prob] + [prob / num_ops] * (num_ops - 1)
    ops = [''.join(i) for i in product(self._BASED_GATE.keys(), repeat=num_qubits)]

    super().__init__(list(zip(ops, probs)), num_qubits)
    self.type = NoiseChannel.depolarizing

QuICT.core.noise.DampingError

DampingError(amplitude_prob: float, phase_prob: float, dissipation_state: float = 0.0)

Bases: QuantumNoiseError

Amplitude Damping, Phase Damping and Amp-Phase Damping

a = amp, b = phase, p = state prob

A0 = sqrt(1 - p1) * [[1, 0], [0, sqrt(1 - a - b)]]

A1 = sqrt(1 - p1) * [[0, sqrt(a)], [0, 0]]

A2 = sqrt(1 - p1) * [[0, 0], [0, sqrt(b)]]

B0 = sqrt(p1) * [[sqrt(1 - a - b), 0], [0, 1]]

B1 = sqrt(p1) * [[0, 0], [sqrt(a), 0]]

B2 = sqrt(p1) * [[sqrt(b), 0], [0, 0]]

Parameters:

  • amplitude_prob (float) –

    The probability for damping amplitude.

  • phase_prob (float) –

    The probability for damping phase.

  • dissipation_state (float, default: 0.0 ) –

    The dissipation states. Defaults to 0.0.

Source code in QuICT/core/noise/noise_error.py
def __init__(self, amplitude_prob: float, phase_prob: float, dissipation_state: float = 0.0):
    assert amplitude_prob >= 0 and amplitude_prob <= 1, ValueError(
        "DampingError.amplitude_prob", "[0, 1]", amplitude_prob
    )
    assert phase_prob >= 0 and phase_prob <= 1, ValueError("DampingError.phase_prob", "[0, 1]", phase_prob)
    assert dissipation_state >= 0 and dissipation_state <= 1, ValueError(
        "DampingError.dissipation_state", "[0, 1]", dissipation_state
    )

    if amplitude_prob + phase_prob > 1:
        raise DamplingNoiseMixedProbExceedError("the sum of amplitude and phase damping prob <= 1.")

    self.amplitude_prob = amplitude_prob
    self.phase_prob = phase_prob
    self.dissipation_state = dissipation_state

    ops = self._create_kraus_ops()
    super().__init__(ops)
    self._origin_ops = ops
    self.type = NoiseChannel.damping

to_matrix

to_matrix() -> list

generate kraus operator with given gate's matrix.

Source code in QuICT/core/noise/noise_error.py
def to_matrix(self) -> list:
    """ generate kraus operator with given gate's matrix. """
    all_matrix = []
    for ngate, _ in self.operators:
        matrix = ngate.matrix()
        all_matrix.append(matrix)

    return all_matrix