qiboteam / qibo

A framework for quantum computing
https://qibo.science
Apache License 2.0
287 stars 58 forks source link

Apply channel for Clifford circuits with `cupy` #1404

Closed AlejandroSopena closed 2 months ago

AlejandroSopena commented 2 months ago

This PR fixes a TypeError when using noise channels in Clifford circuits and running them with the CliffordBackend on GPU. It can be reproduced with the following code extracted from test_backends_clifford.py:

import numpy as np
from qibo import gates
from qibo.backends import CliffordBackend
from qibo.quantum_info import random_clifford
from qibo.noise import NoiseModel, PauliError

backend = CliffordBackend('cupy')

nqubits = 3

c = random_clifford(nqubits, density_matrix=True, backend=backend)

noise = NoiseModel()
noisy_gates = np.random.choice(c.queue, size=1, replace=False)
noise.add(PauliError([("X", 0.3)]), noisy_gates[0].__class__)

c.add(gates.M(*range(nqubits)))

c = noise.apply(c)

result = backend.execute_circuit(c)
codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.99%. Comparing base (d8cc501) to head (3f471a7).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1404 +/- ## ======================================= Coverage 99.99% 99.99% ======================================= Files 78 78 Lines 11192 11193 +1 ======================================= + Hits 11191 11192 +1 Misses 1 1 ``` | [Flag](https://app.codecov.io/gh/qiboteam/qibo/pull/1404/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/qiboteam/qibo/pull/1404/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam) | `99.99% <100.00%> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiboteam#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.