Open antalszava opened 2 years ago
Use tapes to automatically detect implicitly defined user dtypes To achieve this, having a tape.shape attribute defined would help (WIP in https://github.com/PennyLaneAI/pennylane/pull/2044).
Thinking about this more, I'm starting to really like the idea that tapes always have an associated dtype
. Whether it is implicit, or explicitly set by the user.
We can think of the dtype as metadata associated with the tape
Expected behavior
User-specified dtypes on the device are not considered in a wide variety of cases. The ones detailed below are just specific ones found by chance, a more systematic think-through of cases is required.
A couple of examples for specific use cases to consider: various
diff_method
types, every interface, potentially external plugins.Actual behavior
The dtypes that users define on the device are preserved throughout the whole circuit execution and the result of a QNode adheres to that dtype.
Additional information
Use tapes to automatically detect implicitly defined user dtypes
QuantumTape
objects may contain parameters that already have a specific dtype set. If the user didn't define a custom dtype and the dtype of the parameters differ from the internal dtype used by the device, it would be desirable to use the dtype implicitly defined on the tape by inspecting the gate parameter objects.To achieve this, having a
tape.shape
attribute defined would help (WIP in #2044).Sampling
Sampling certain observables may result in integer outputs. However, devices don't yet allow specifying an integer typed dtype. Introducing that and ensuring that computations work as expected would be key.
Using backprop devices
The dtype doesn't seem to be copied when swapping the devices in the QNode.
Changing https://github.com/PennyLaneAI/pennylane/blob/0814da9b27211dc010ae49942b947993c14f1601/pennylane/qnode.py#L403 to look like:
could solve this issue. Note that an additional integer dtype could also be used here.
Source code
No response
Tracebacks
No response
System information
Existing GitHub issues