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

[question] How to use qiskit-machine-learning with real ibm backends? #890

Open
KonradKorus opened this issue Jan 2, 2025 · 2 comments
Open
Labels
Hardware runtime 💻 Running jobs on IBM quantum devices type: question 🙋 Question about the code or its uses

Comments

@KonradKorus
Copy link

Hello,

I am using EstimatorQNN and NeuralNetworkClassifier for image recognition on quantum computers, following the tutorial here. I am trying to find a way to run this setup on a real IBM backend (not locally on a simulator). However, after spending several hours, I haven't found a clear solution.

My question is: Is there a way to use this approach on a real backend? If so, how can I pass training data to the backend, given that it runs in the cloud and not on my local machine?

From what I understand, I could transpile the circuit, but then I face issues with passing training data into the circuit (so I’m not even sure if it will run on the backend). Additionally, I have read that it might be possible to send multiple jobs to the backend, but this approach doesn’t seem to support backpropagation.

I hope you can help clarify this (or at least confirm if it’s not feasible so I can stop pursuing this approach 😄).

@edoaltamura edoaltamura added type: question 🙋 Question about the code or its uses Hardware runtime 💻 Running jobs on IBM quantum devices labels Feb 3, 2025
@edoaltamura
Copy link
Collaborator

Hi @KonradKorus, we do support hardware backends since v.0.8. The difference with the tutorial you're following is in the kind of Estimator primitive to pass in:

# we decompose the circuit for the QNN to avoid additional data copying
qnn = EstimatorQNN(
    circuit=circuit.decompose(),
    observables=observable,
    input_params=feature_map.parameters,
    weight_params=ansatz.parameters,
    estimator=estimator,  <--- This needs to be an qiskit-ibm-runtime primitive, and not StatevectorEstimator
)

At the top of the tutorial you'll need to replace

from qiskit.primitives import StatevectorEstimator as Estimator
estimator = Estimator()

with

from qiskit_ibm_runtime import QiskitRuntimeService, EstimatorV2 as Estimator
backend = <your real hardware backend>
estimator = Estimator(mode=backend)

You can find more info at the Qiskit IBM Runtime link here.

Note that if you want to run Estimator inside a Session, you'll need to embed the training loop in a Session environment yourself. Let us know if you need more help.

@edoaltamura
Copy link
Collaborator

You can also find more examples in the migration guide to help with real backends - you may replace GenericBackendV2 with your (real) backend from IBM Qiskit Runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hardware runtime 💻 Running jobs on IBM quantum devices type: question 🙋 Question about the code or its uses
Projects
None yet
Development

No branches or pull requests

2 participants