Closed tnemoz closed 1 year ago
When using the device default.mixed, a QNode defined on the torch interface returning using the qml.state() function should return a torch tensor.
default.mixed
torch
qml.state()
numpy
No response
import pennylane as qml import torch dev_qubit = qml.device("default.qubit", wires=1) @qml.qnode(dev_qubit, interface="torch") def circuit0(x): qml.RX(x, wires=0) return qml.state() @qml.qnode(dev_qubit, interface="torch") def circuit1(): qml.PauliZ(wires=0) return qml.state() print(circuit0(1)) print(circuit1()) print("=" * 50) dev_mixed = qml.device("default.mixed", wires=1) @qml.qnode(dev_mixed, interface="torch") def circuit2(x): qml.RX(x, wires=0) return qml.state() @qml.qnode(dev_mixed, interface="torch") def circuit3(): qml.PauliZ(wires=0) return qml.state() print(circuit2(1)) print(circuit2(torch.tensor(1))) print(circuit3(), type(circuit3())) print(circuit2(torch.tensor(1)) - circuit3()) # The following throws an error print(circuit3() - circuit2(torch.tensor(1)))
Traceback (most recent call last): File "/home/tristan/bigfiles/UnitaryHack/pennylane/issue.py", line 38, in <module> print(circuit3() - circuit2(torch.tensor(1))) TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'Tensor'
Name: PennyLane Version: 0.31.0.dev0 Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc. Home-page: https://github.com/XanaduAI/pennylane Author: Author-email: License: Apache License 2.0 Location: /home/tristan/bigfiles/UnitaryHack/venv/lib/python3.10/site-packages Editable project location: /home/tristan/bigfiles/UnitaryHack/pennylane Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml Required-by: PennyLane-Lightning Platform info: Linux-5.10.180-1-MANJARO-x86_64-with-glibc2.37 Python version: 3.10.10 Numpy version: 1.23.5 Scipy version: 1.10.1 Installed devices: - default.gaussian (PennyLane-0.31.0.dev0) - default.mixed (PennyLane-0.31.0.dev0) - default.qubit (PennyLane-0.31.0.dev0) - default.qubit.autograd (PennyLane-0.31.0.dev0) - default.qubit.jax (PennyLane-0.31.0.dev0) - default.qubit.tf (PennyLane-0.31.0.dev0) - default.qubit.torch (PennyLane-0.31.0.dev0) - default.qutrit (PennyLane-0.31.0.dev0) - null.qubit (PennyLane-0.31.0.dev0) - lightning.qubit (PennyLane-Lightning-0.30.0)
Hey @tnemoz, thanks for reporting that. I can replicate the behaviour on v0.30. We'll look into it!
Expected behavior
When using the device
default.mixed
, a QNode defined on thetorch
interface returning using theqml.state()
function should return atorch
tensor.Actual behavior
numpy
array. This makes it hard to run operations on these states.Additional information
No response
Source code
Tracebacks
System information
Existing GitHub issues