Open joeybarreto opened 3 months ago
Hi @joeybarreto , thank you for reporting this! We're looking into it and will get back to you soon.
Hi @joeybarreto,
tl;dr: Simplest fix: Add a wire to your device (see below for working code based on your MWE)
I'll outline the function structure here to make the bug understandable:
quantum_fisher
uses the functions adjoint_metric_tensor
and metric_tensor
under the hood. However, adjoint_metric_tensor
currently is only supported on some devices, which unfortunately does not include DefaultMixed
.metric_tensor
uses two techniques to obtain the QFI, one for the block diagonal, where the blocks of parameters are defined by commuting sets of gates, and one for the block off-diagonal.Now the structure for your code is as follows: adjoint_metric_tensor
does not work because of the device choice.
For a single layer of parametrized/differentiable operations, only the covariance-based method needs to be used (the QFI only has one block, so it is entirely block diagonal). For a second layer, the Hadamard test is needed, starting to cause the bug you report. Finally, the bug itself is caused by the device not having an auxiliary wire available, which is needed for Hadamard tests.
You have a number of options here:
approx="block_diag"
to quantum_fisher
. This will not require the additional wire, but it is an approximation only (note that it also is much cheaper in terms of circuit executions).adjoint_metric_tensor
.I hope this helps! Let me know if you still encounter problems!
And here is the working example based on your MWE:
import pennylane as qml
from pennylane import numpy as np
def circuit(params):
qml.RX(params[0], wires=0)
qml.RX(params[1], wires=1)
qml.AmplitudeDamping(0.1, wires=0)
qml.AmplitudeDamping(0.1, wires=1)
qml.RX(params[0], wires=0)
qml.RX(params[1], wires=1)
return qml.expval(qml.PauliZ(0))
dev = qml.device("default.mixed", wires=3) # <<< Increased wire count to accomodate aux wire
parameters = 2*np.pi*np.random.random(size=2, requires_grad=True)
qml.qinfo.transforms.quantum_fisher(qml.QNode(circuit, dev))(parameters)
Alternatively, using the approximate QFI:
dev = qml.device("default.mixed", wires=2) # <<< No aux wire this time
parameters = 2*np.pi*np.random.random(size=2, requires_grad=True)
qml.qinfo.transforms.quantum_fisher(qml.QNode(circuit, dev), approx="block-diag")(parameters) # <<< Pick approximation
Expected behavior
Execution without failure (i.e. the QFIM is returned)
Actual behavior
WireError: Did not find some of the wires <Wires = [2]> on device with wires <Wires = [0, 1]>.
Additional information
Removing the second layer of $RX$ gates removes the error, so something is going wrong when noise channels are applied mid-circuit as opposed to at the end of the circuit. This is a minimum working example of the error, after some troubleshooting (I would imagine even with 1 qubit it would still error).
Source code
Tracebacks
System information
Existing GitHub issues