Hello PennyLane!
I want to use the lightning.qubit
device in PennyLane to run a parametric quantum circuit with two qubits and compute the quantum Fisher information. However, when I try to do this, I get a WireError
stating that my circuit contains a wire (wire-2) that is not found on the device. Strangely, the same code runs without issues on default.qubit
.
Thank you in advance for the advices.
import numpy as np
import pennylane as qml
from pennylane import numpy as pnp
pnp.random.seed(42)
# System parameters
num_nodes = 2
num_qubits_per_node = 1
total_qubits = num_nodes * num_qubits_per_node
#dev = qml.device('default.qubit', wires=total_qubits)
dev = qml.device("lightning.qubit", wires=range(total_qubits))
@qml.qnode(dev)
def circuit(param):
layers = len(param[:, 0, 0])
n_wires = len(param[0, :, 0])
n_params_rot = len(param[0, 0, :])
# Applying repeated trainable layers consisting parametized rotations and entangling gates
for i in range(layers):
range_value = (i % (n_wires - 1)) + 1
qml.StronglyEntanglingLayers(param[i, :, :].reshape(1, n_wires, n_params_rot), wires=range(total_qubits), ranges=None)
return qml.state()
wires=total_qubits
layers=2
rng = pnp.random.default_rng()
params_shape = qml.StronglyEntanglingLayers.shape(n_layers=layers,n_wires=wires)
params = rng.random(size=params_shape)
params = pnp.array(params, requires_grad=True)
qml.gradients.quantum_fisher(circuit)(params)
This is the error message I got:
---------------------------------------------------------------------------
WireError Traceback (most recent call last)
<ipython-input-52-0f12bc5f17c5> in <cell line: 0>()
----> 1 qml.gradients.quantum_fisher(circuit)(params)
11 frames
/usr/local/lib/python3.11/dist-packages/pennylane/devices/preprocess.py in validate_device_wires(tape, wires, name)
146
147 if extra_wires := set(tape.wires) - set(wires):
--> 148 raise WireError(
149 f"Cannot run circuit(s) on {name} as they contain wires "
150 f"not found on the device: {extra_wires}"
WireError: Cannot run circuit(s) on lightning.qubit as they contain wires not found on the device: {2}
The qml version I used:
Name: PennyLane
Version: 0.40.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Location: /usr/local/lib/python3.11/dist-packages
Requires: appdirs, autograd, autoray, cachetools, diastatic-malt, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, tomlkit, typing-extensions
Required-by: PennyLane_Lightning
Platform info: Linux-6.1.85+-x86_64-with-glibc2.35
Python version: 3.11.11
Numpy version: 1.26.4
Scipy version: 1.13.1
Installed devices:
- default.clifford (PennyLane-0.40.0)
- default.gaussian (PennyLane-0.40.0)
- default.mixed (PennyLane-0.40.0)
- default.qubit (PennyLane-0.40.0)
- default.qutrit (PennyLane-0.40.0)
- default.qutrit.mixed (PennyLane-0.40.0)
- default.tensor (PennyLane-0.40.0)
- null.qubit (PennyLane-0.40.0)
- reference.qubit (PennyLane-0.40.0)
- lightning.qubit (PennyLane_Lightning-0.40.0)