Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert changes to DepolarizingChannel #903

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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