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

quantum_fisher transform on non-default.qubit devices #5423

Merged
merged 2 commits into from
Mar 20, 2024

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Mar 20, 2024

Context:

The qml.qinfo.quantum_fisher transform was failing on non-defualt.qubit devices:

import pennylane as qml
from pennylane import numpy as np

from sklearn import datasets as ds

NUM_WIRES = 4

def get_circuit(data, parameters):
    qml.IQPEmbedding(data, wires=range(NUM_WIRES), n_repeats=1)
    for i in range(NUM_WIRES):
        qml.RX(parameters[i], wires=i)
    for j in range(NUM_WIRES-1):
        qml.CNOT(wires=[j, j+1])
    return qml.expval(qml.PauliZ(0))

# use different devices here, i.e. lightning.qubit, default.qubit, lightning.kokkos
dev = qml.device("default.mixed", wires=NUM_WIRES)

def qfim(X_train, parameters):
    circuit = qml.QNode(get_circuit, dev)
    data = np.array(X_train[0], requires_grad=False)
    return qml.qinfo.transforms.quantum_fisher(circuit)(data, parameters)

X = ds.load_iris().data
parameters = np.random.random(size=NUM_WIRES, requires_grad=True)
print(qfim(X, parameters))

Description of the Change:

Use the metric_tensor instead of the adjoint_metric_tensor if the device is not default.qubit.

Benefits:

quantum_fisher works with more devices.

Possible Drawbacks:

Related GitHub Issues:

Fixes #5381 [sc-58882]

Copy link

codecov bot commented Mar 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.63%. Comparing base (186faaf) to head (ce37e29).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5423      +/-   ##
==========================================
- Coverage   99.63%   99.63%   -0.01%     
==========================================
  Files         399      399              
  Lines       37112    36825     -287     
==========================================
- Hits        36977    36689     -288     
- Misses        135      136       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@astralcai astralcai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@albi3ro albi3ro merged commit 23f1a7a into master Mar 20, 2024
40 checks passed
@albi3ro albi3ro deleted the quantum-fisher-fix branch March 20, 2024 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Quantum Fisher with Different Devices
3 participants