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

FusedGate.asmatrix breaks if gate appended is gates.Unitary created from a cupy ndarray #928

Closed
renatomello opened this issue Jun 8, 2023 · 3 comments · Fixed by #950 or qiboteam/qibojit#125
Assignees
Labels
bug Something isn't working
Milestone

Comments

@renatomello
Copy link
Contributor

renatomello commented Jun 8, 2023

Minimal code

from qibojit.backends import CupyBackend

from qibo import gates, matrices
from qibo.backends import NumpyBackend
from qibo.gates.special import FusedGate

nqubits = 1
I = matrices.I

for backend in [NumpyBackend, CupyBackend]:
    backend = backend()
    I = backend.cast(I, dtype=I.dtype)
    gate = FusedGate(*range(nqubits))
    gate.append(gates.Unitary(I, *range(nqubits)))
    gate = gate.asmatrix(backend)
    print(type(gate))
@renatomello renatomello added the bug Something isn't working label Jun 8, 2023
@renatomello renatomello added this to the Qibo 0.1.15 milestone Jun 8, 2023
@renatomello
Copy link
Contributor Author

renatomello commented Jun 13, 2023

There is a second issue that is probably related, which is FusedGate.asmatrix(backend) returns a numpy.ndarray when backend=CupyBackend(). E.g.

from qibo import gates
from qibojit.backends import CupyBackend
from qibo.gates.special import FusedGate

backend = CupyBackend()

gate = FusedGate(1)
gate.append(gates.I(0))
gate = gate.asmatrix(backend)
print(type(gate))

@renatomello
Copy link
Contributor Author

renatomello commented Jun 22, 2023

@scarrazza the issue seems to come from the fact that the cupy backend does not have a matrices class (e.g. NumpyMatrices and TensorflowMatrices). In fact, any matrix coming from

CupyBackend().matrices

is of type numpy.ndarray instead of cupy.ndarray.

@scarrazza
Copy link
Member

Thanks @renatomello, @andrea-pasquale could you please have look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants