You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use a pennylane circuit inside a torch model, which needs to be (deep)copied. If I use the default.qubit device, everything works fine, but when I switch to a lightning device (lightning.qubit / lightning.gpu), an exception is thrown.
I provide a minimal example to reproduce below.
Expected behavior: (What you expect to happen)
I hope to be able to copy (pickle) models regardless of the device they're running on.
If not, then default.qubit and lightning.qubit should at least show the same behavior (or maybe fail with an explanation, if it is indeed intended to not clone models)
Actual behavior: (What actually happens)
I get an error message, stating "TypeError: cannot pickle 'pennylane_lightning.lightning_gpu_ops.DevPool' object" (or respectively the same for pennylane_lightning.lightning_qubit_ops.StateVectorC128 )
Reproduces how often: (What percentage of the time does it reproduce?)
Every time, on different machines
System information: (post the output of import pennylane as qml; qml.about())
I've prepared this example which I hope helps to reproduce the issue:
import pennylane as qml
import torch
from copy import deepcopy
n_qubits = 2
n_layers = 6
weight_shapes = {"weights": (n_layers, n_qubits)}
# default.qubit works fine
# lightning.qubit also fails
dev = qml.device("lightning.gpu", wires=n_qubits)
@qml.qnode(dev)
def qnode(inputs, weights):
qml.AngleEmbedding(inputs, wires=range(n_qubits))
qml.BasicEntanglerLayers(weights, wires=range(n_qubits))
return [qml.expval(qml.PauliZ(wires=i)) for i in range(n_qubits)]
class Model(torch.nn.Module):
def __init__(self):
super().__init__()
self.qlayer_1 = qml.qnn.TorchLayer(qnode, weight_shapes)
def forward(self, x):
x = self.qlayer_1(x)
return x
model = Model()
model2 = deepcopy(model)
This is the stacktrace:
Traceback (most recent call last):
File "/mnt/d/Code/report.py", line 32, in <module>
model2 = deepcopy(model)
^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 146, in deepcopy
y = copier(x, memo)
^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 297, in _reconstruct
value = deepcopy(value, memo)
^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 146, in deepcopy
y = copier(x, memo)
^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 146, in deepcopy
y = copier(x, memo)
^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 146, in deepcopy
y = copier(x, memo)
^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/copy.py", line 161, in deepcopy
rv = reductor(4)
^^^^^^^^^^^
TypeError: cannot pickle 'pennylane_lightning.lightning_gpu_ops.DevPool' object
The text was updated successfully, but these errors were encountered:
Hi @TheRisenPhoenix
Thanks for the report on this. The object in question is generally tied to specific local instances of GPUs on the system you are running, so we do not have serialisation rules in place for it. However, we can take a look at what seems sensible here and update you when we have a resolution.
Issue description
I use a pennylane circuit inside a torch model, which needs to be (deep)copied.
If I use the default.qubit device, everything works fine, but when I switch to a lightning device (
lightning.qubit
/lightning.gpu
), an exception is thrown.I provide a minimal example to reproduce below.
Expected behavior: (What you expect to happen)
I hope to be able to copy (pickle) models regardless of the device they're running on.
If not, then
default.qubit
andlightning.qubit
should at least show the same behavior (or maybe fail with an explanation, if it is indeed intended to not clone models)Actual behavior: (What actually happens)
I get an error message, stating "
TypeError: cannot pickle 'pennylane_lightning.lightning_gpu_ops.DevPool' object
" (or respectively the same forpennylane_lightning.lightning_qubit_ops.StateVectorC128
)Reproduces how often: (What percentage of the time does it reproduce?)
Every time, on different machines
System information: (post the output of
import pennylane as qml; qml.about()
)Source code and tracebacks
I've prepared this example which I hope helps to reproduce the issue:
This is the stacktrace:
The text was updated successfully, but these errors were encountered: