Quick aside: I’m running the most updated version of PennyLane (v0.33) and this code won’t work because of device API changes that were made a couple releases ago. If you decide to update (which I recommend that you do!) you just need to change your device to use the old default qubit:
dev = qml.device('default.qubit.legacy', wires = 10)
If I change that and run on v0.33, your code works and I get
Thanks Issacdevlugt. If I understood correctly, I upgraded pennylane to v0.33.1 and only changed “default.qubit” to “default.qubit.legacy”. But now it shows,
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/init.py”, line 337, in device
raise DeviceError(“Device does not exist. Make sure the required plugin is installed.”)
pennylane._device.DeviceError: Device does not exist. Make sure the required plugin is installed.
So after I update the version and change “default.qubit” to “default.qubit.legacy” and run the code, it is showing same error,
pennylane.operation.MatrixUndefinedError
In detail,
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/qnode.py”, line 1027, in call
res = qml.execute(
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/interfaces/execution.py”, line 616, in execute
results = inner_execute(tapes)
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/interfaces/execution.py”, line 249, in inner_execute
return cached_device_execution(tapes)
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/interfaces/execution.py”, line 371, in wrapper
res = list(fn(tuple(execution_tapes.values()), **kwargs))
File “/home/sd/anaconda3/lib/python3.9/contextlib.py”, line 79, in inner
return func(*args, **kwds)
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/_qubit_device.py”, line 460, in batch_execute
res = self.execute(circuit)
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/_qubit_device.py”, line 279, in execute
self.apply(circuit.operations, rotations=self._get_diagonalizing_gates(circuit), **kwargs)
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/devices/default_qubit_legacy.py”, line 296, in apply
self._state = self._apply_operation(self._state, operation)
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/devices/default_qubit_legacy.py”, line 338, in _apply_operation
matrix = self._asarray(self._get_unitary_matrix(operation), dtype=self.C_DTYPE)
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/devices/default_qubit_legacy.py”, line 682, in _get_unitary_matrix
return unitary.matrix()
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/operation.py”, line 775, in matrix
canonical_matrix = self.compute_matrix(*self.parameters, **self.hyperparameters)
File “/home/sd/anaconda3/lib/python3.9/site-packages/pennylane/operation.py”, line 744, in compute_matrix
raise MatrixUndefinedError
pennylane.operation.MatrixUndefinedError