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

[Bug] Evolution data does not match terminal leaves #6514

Open
albi3ro opened this issue Nov 4, 2024 · 0 comments
Open

[Bug] Evolution data does not match terminal leaves #6514

albi3ro opened this issue Nov 4, 2024 · 0 comments
Labels
bug 🐛 Something isn't working

Comments

@albi3ro
Copy link
Contributor

albi3ro commented Nov 4, 2024

For an Evolution operator where the generator has data, like op = qml.evolve(0.5 * qml.X(0), 1.2), the terminal leaves

>>> qml.pytrees.flatten(op)[0]
[0.5, 1.2]
>>> op.data
(1.2,)

While on its own, this violation of expectations seems relatively harmless, it causes errors when used with bind_new_parameters.

User examples include:

@qml.qnode(qml.device('default.qubit'), diff_method="parameter-shift")
def c(x):
    qml.evolve(0.5 * qml.X(0), x)
    return qml.expval(qml.Z(0))
qml.grad(c)(qml.numpy.array(0.5))
File [/pennylane/ops/functions/bind_new_parameters.py:221](/pennylane/ops/functions/bind_new_parameters.py#line=220), in bind_new_parameters_sprod(op, params)
    218 @bind_new_parameters.register
    219 def bind_new_parameters_sprod(op: SProd, params: Sequence[TensorLike]):
    220     # Separate dispatch for `SProd` since its constructor has a different interface
--> 221     new_scalar = params[0]
    222     params = params[1:]
    223     new_base = bind_new_parameters(op.base, params)

IndexError: tuple index out of range

The above failure could be fixed by simply adding a registration to bind_new_parameters for the special Evolution behavior.

But we end up in a situation where not all numerical data can be updated and changed by bind_new_parameters. For example, bind_new_parameters is often used to convert all numerical data to numpy so it can be used with devices that can't handle interface data. If the coefficient is not considered by bind_new_parameters, we might send interface data to a device that can't handle it.

The coefficient of the generator could also be trainable. If we simply ignore the coefficient of the generator, we might not properly calculate any derivatives for it.

@albi3ro albi3ro added the bug 🐛 Something isn't working label Nov 4, 2024
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
Development

No branches or pull requests

1 participant