Skip to content

Commit

Permalink
Merge pull request #903 from qiboteam/depol_channel
Browse files Browse the repository at this point in the history
Revert changes to `DepolarizingChannel`
  • Loading branch information
renatomello authored May 19, 2023
2 parents 2f6532d + 1f46cd6 commit f8dac7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
25 changes: 7 additions & 18 deletions src/qibo/gates/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gates_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit f8dac7a

Please sign in to comment.