Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cotransform of quantum_fisher #6350

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@

<h3>Bug fixes 🐛</h3>

* `quantum_fisher` now respects the classical Jacobian of QNodes.
[(#6350)](https://github.com/PennyLaneAI/pennylane/pull/6350)

* `qml.map_wires` can now be applied to a batch of tapes.
[(#6295)](https://github.com/PennyLaneAI/pennylane/pull/6295)

Expand Down
3 changes: 2 additions & 1 deletion pennylane/gradients/fisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pennylane import transform
from pennylane.devices import DefaultQubit
from pennylane.gradients import adjoint_metric_tensor
from pennylane.gradients.metric_tensor import _contract_metric_tensor_with_cjac
from pennylane.typing import PostprocessingFn


Expand Down Expand Up @@ -280,7 +281,7 @@ def wrapper(*args, **kwargs):
return wrapper


@partial(transform, is_informative=True)
@partial(transform, classical_cotransform=_contract_metric_tensor_with_cjac, is_informative=True)
def quantum_fisher(
tape: qml.tape.QuantumScript, device, *args, **kwargs
) -> tuple[qml.tape.QuantumScriptBatch, PostprocessingFn]:
Expand Down
5 changes: 3 additions & 2 deletions tests/gradients/core/test_fisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,17 @@ def circ(params):
),
)
def test_quantum_fisher_info(self, dev):
"""Integration test of quantum fisher information matrix CFIM. This is just calling ``qml.metric_tensor`` or ``qml.adjoint_metric_tensor`` and multiplying by a factor of 4"""
"""Integration test of quantum fisher information matrix CFIM. This is just calling
``qml.metric_tensor`` or ``qml.adjoint_metric_tensor`` and multiplying by a factor of 4"""

n_wires = 2

rng = pnp.random.default_rng(200)
dev_hard = qml.device("default.qubit", wires=n_wires + 1, shots=1000, seed=rng)

def qfunc(params):
qml.RX(params[0], wires=0)
qml.RX(params[1], wires=0)
qml.RX(params[0] / 3, wires=0)
qml.CNOT(wires=(0, 1))
return qml.probs(wires=[0, 1])

Expand Down
Loading