-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tensorflow for when device returns float 32 results (#5446)
**Context:** When testing the new lightning device, we discovered that TensorFlow would error if the parameters were float64, the device returned float32, and classical operations modified the parameter: ``` dev = qml.device('lightning.qubit', wires=2, c_dtype=np.complex64) @qml.qnode(dev, diff_method="parameter-shift") def circuit(x): qml.RX(tf.cos(x), wires=0) return qml.expval(qml.Z(0)) x = tf.Variable(0.1, dtype=tf.float64) with tf.GradientTape() as tape: y = circuit(x) tape.gradient(y, x) ``` ``` InvalidArgumentError: cannot compute Mul as input #1(zero-based) was expected to be a float tensor but is a double tensor [Op:Mul] name: ``` The problem is that the output were results were `float32` precision, so the vjp would be `float32`. But `float32` vjp cannot be combined with `tf.cos`'s `float64` vjp. The reverse problem (`float64` results but `float32` data) seems to be fine. **Description of the Change:** If the input data are `float64` or `complex128`, we promote the results to the type of the parameters. [sc-58966] --------- Co-authored-by: Mudit Pandey <[email protected]>
- Loading branch information
Showing
3 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters