Closed eddddddy closed 2 years ago
I am not sure if we can change the current behaviour, given that we would lose information about trainability:
>>> np.array(0.3, requires_grad=False) * qml.PauliX(0)
tensor(<Hamiltonian: terms=1, wires=[0]>, dtype=object, requires_grad=False)
FYI, you can obtain the Hamiltonian from the tensor by calling unwrap
:
>>> h = np.array(0.3) * qml.PauliX(0)
>>> h.unwrap()
(0.3) [X0]
@josh146 what do you think?
Right, OK. I guess from this and the other issue as well, it's clear that qml.Hamiltonian
is not really intended to handle framework-specific tensors.
However, this looks to be handled by the new operator arithmetic. Just wondering, is the new operator arithmetic going to replace qml.Hamiltonian
somewhere down the line?
However, this looks to be handled by the new operator arithmetic. Just wondering, is the new operator arithmetic going to replace
qml.Hamiltonian
somewhere down the line?
Yes! We will be deprecating the qml.Hamiltonian
soon.
@eddddddy can I close this issue?
Sure, you can go ahead and close this issue.
Expected behavior
A
qml.Hamiltonian
object is constructed correctly for the product of a Python scalar with an observable:We would expect the product of a framework-specific scalar tensor with an observable to also work:
Actual behavior
Instead, the latter code produces the following output:
This is a "scalar" tensor, where the scalar is the Hamiltonian object itself.
Additional information
No response
Source code
No response
Tracebacks
No response
System information
Existing GitHub issues