From 1f46cd6f97557a2a61123bd943ffd41ad9106b19 Mon Sep 17 00:00:00 2001 From: Renato Mello Date: Thu, 18 May 2023 12:53:58 +0400 Subject: [PATCH] reapply changes to `DepolarizingChannel` --- src/qibo/gates/channels.py | 25 +++++++------------------ tests/test_gates_channels.py | 2 +- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/qibo/gates/channels.py b/src/qibo/gates/channels.py index 3826bb9d9c..6c999bcf83 100644 --- a/src/qibo/gates/channels.py +++ b/src/qibo/gates/channels.py @@ -439,7 +439,7 @@ def __init__(self, qubits: Tuple[int, list, tuple], operators: list): self.init_kwargs = dict(operators) -class DepolarizingChannel(Channel): +class DepolarizingChannel(PauliNoiseChannel): """:math:`n`-qubit Depolarizing quantum error channel, .. math:: @@ -464,7 +464,6 @@ def __init__(self, qubits, lam: float = 0): if isinstance(qubits, int) is True: qubits = (qubits,) - super().__init__() num_qubits = len(qubits) num_terms = 4**num_qubits max_param = num_terms / (num_terms - 1) @@ -474,6 +473,12 @@ def __init__(self, qubits, lam: float = 0): f"Depolarizing parameter must be in between 0 and {max_param}.", ) + pauli_noise_params = list(product(["I", "X", "Y", "Z"], repeat=num_qubits))[1::] + pauli_noise_params = zip( + pauli_noise_params, [lam / num_terms] * (num_terms - 1) + ) + super().__init__(qubits, pauli_noise_params) + self.name = "DepolarizingChannel" self.draw_label = "D" self.target_qubits = qubits @@ -484,22 +489,6 @@ def __init__(self, qubits, lam: float = 0): def apply_density_matrix(self, backend, state, nqubits): return backend.depolarizing_error_density_matrix(self, state, nqubits) - def apply(self, backend, state, nqubits): - num_qubits = len(self.target_qubits) - num_terms = 4**num_qubits - prob_pauli = self.init_kwargs["lam"] / num_terms - probs = (num_terms - 1) * [prob_pauli] - gates = [] - for pauli_list in list(product([I, X, Y, Z], repeat=num_qubits))[1::]: - fgate = FusedGate(*self.target_qubits) - for j, pauli in enumerate(pauli_list): - fgate.append(pauli(j)) - gates.append(fgate) - self.gates = tuple(gates) - self.coefficients = tuple(probs) - - return backend.apply_channel(self, state, nqubits) - class ThermalRelaxationChannel(KrausChannel): """Single-qubit thermal relaxation error channel. diff --git a/tests/test_gates_channels.py b/tests/test_gates_channels.py index ef58f5a9c7..7a0ce63513 100644 --- a/tests/test_gates_channels.py +++ b/tests/test_gates_channels.py @@ -207,7 +207,7 @@ def test_pauli_noise_channel(backend): test_representation = np.diag([a0, a1, a2, a3]) liouville = gates.PauliNoiseChannel(0, list(zip(basis, pnp))).to_pauli_liouville( - True, backend + normalize=True, backend=backend ) norm = backend.calculate_norm(backend.to_numpy(liouville) - test_representation)