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

Gate.parameters as a single backend array #1466

Open
BrunoLiegiBastonLiegi opened this issue Sep 30, 2024 · 1 comment
Open

Gate.parameters as a single backend array #1466

BrunoLiegiBastonLiegi opened this issue Sep 30, 2024 · 1 comment

Comments

@BrunoLiegiBastonLiegi
Copy link
Contributor

BrunoLiegiBastonLiegi commented Sep 30, 2024

Currently the parameters of a ParametrizedGate are returned as a tuple which is perfectly fine when you set them as simple floats

from qibo import gates

rz = gates.RZ(0, 0.)
u3 = gates.U3(0, 1., 2., 3.)
print(rz.parameters)
# this is (0.,)
print(u3.parameters)
# this is (1., 2., 3.)

However, in some cases, you might want them to be arrays of a particular backend (for instance this is needed for backpropagation through pytorch), and you can set the parameters manually:

import numpy as np

rz.parameters = np.array([0.])
u3.parameters = np.array([1., 2., 3.])

if you try to recover them, though, you'll find them split and returned as a tuple again:

print(rz.parameters)
# this is (array([0]),) 
print(u3.parameters)
# this is (array([1.]), array([2.]), array([3.]))

which begs for further unneeded machinery to restore the native representation.
Furthermore, for the sake of not riskying to brake the trace that torch, tensorflow and jax do, it would be better to cut to the bone any operation that is performed on the parameters that is not really needed in the parameters property (as well as in the Circuit.get/set_parameters).

@alecandido
Copy link
Member

qiboteam/qibo-core#22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants