Repeated parameters in qml.gradient.quantum_fisher

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)

Hi @joeybarreto , welcome to the Forum!

Thank you for question. We’re experiencing a high volume of questions at the moment. I’ll respond as soon as I can.

1 Like

Hi @joeybarreto ,

qml.gradient.quantum_fisher uses qml.adjoint_metric_tensor under the hood in this case. The output dimensions are (tape.num_params, tape.num_params). So if you have four gates with one parameter each (even if they’re the same parameter) the output will have shape 4x4.

You could try using qml.transforms.merge_rotations or qml.transforms.single_qubit_fusion. Why don’t you check the documentation and let me know if this is what you were looking for.

I hope this helps!

Thanks @CatalinaAlbornoz - the example might have been too simple, in reality I have a sequence of non-commuting rotations so their angles can’t be combined. I was mainly wondering whether it was supposed to do the chain rule under the hood in case of repeated parameters like qml.grad, but it seems this is not the case.