In the following circuit, I have 2 qubits each of which evolve under 2 gates. There are only 2 parameters, and each is used twice. As expected, the gradient has length 2, but the quantum fisher info matrix (QFIM) is 4x4, which is incorrect. Am I calling it incorrectly, or does it have a built-in assumption that each gate uses a distinct angle? If so, how hard would it be to lift this assumption?
Code:
import pennylane as qml
import numpy as np
from pennylane import numpy as pnp
Nq = 2
np.random.seed(42)
dev = qml.device('default.qubit', wires=Nq)
@qml.qnode(dev)
def circuit(angles):
qml.RX(angles[0], wires=0)
qml.RY(angles[1], wires=1)
qml.RY(angles[0], wires=0)
qml.RZ(angles[1], wires=1)
return qml.expval(qml.PauliZ(0))
angles = 2*np.pi*np.random.uniform(size=(2,))
angles = pnp.array(angles, requires_grad=True)
grad = qml.grad(circuit)(angles)
print("grad =", grad)
qfim = qml.gradients.quantum_fisher(circuit)(angles)
print(qfim.shape)
Output:
grad = [-7.42291120e-01 1.34574491e-18]
(4, 4)
qml.about():
Name: PennyLane
Version: 0.38.1
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: [/Users/joey/miniconda3/envs/lanl/lib/python3.12/site-packages](https://file+.vscode-resource.vscode-cdn.net/Users/joey/miniconda3/envs/lanl/lib/python3.12/site-packages)
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, toml, typing-extensions
Required-by: PennyLane_Lightning
Platform info: macOS-14.4.1-arm64-arm-64bit
Python version: 3.12.3
Numpy version: 1.26.4
Scipy version: 1.13.1
Installed devices: - lightning.qubit (PennyLane_Lightning-0.38.0) - default.clifford (PennyLane-0.38.1) - default.gaussian (PennyLane-0.38.1) - default.mixed (PennyLane-0.38.1) - default.qubit (PennyLane-0.38.1) - default.qubit.autograd (PennyLane-0.38.1) - default.qubit.jax (PennyLane-0.38.1) - default.qubit.legacy (PennyLane-0.38.1) - default.qubit.tf (PennyLane-0.38.1) - default.qubit.torch (PennyLane-0.38.1) - default.qutrit (PennyLane-0.38.1) - default.qutrit.mixed (PennyLane-0.38.1) - default.tensor (PennyLane-0.38.1) - null.qubit (PennyLane-0.38.1)