Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.04k stars 2.32k forks source link

VQC model load and predict on real backend #11332

Closed Herutriana44 closed 9 months ago

Herutriana44 commented 9 months ago

Environment

Issue

i have quantum machine learning deployment project. but i'm so confused for load VQC model and predict on real backend. bellow is one of my code from my this project

from qiskit.utils import algorithm_globals
from qiskit_machine_learning.algorithms import VQC
import qiskit
from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Estimator, Session
algorithm_globals.random_seed = 42

IBM_API = "MY_IBM_API"
service = QiskitRuntimeService(token=IBM_API, channel="ibm_quantum")
backend = service.backend("ibm_perth")
estimator = Estimator(session=Session(service=service, backend=backend))
sampler = Sampler(session=Session(service=service, backend=backend))

template_name_model = "allergen_vqc_model"
vqc = VQC.load(template_name_model)
a = vqc.predict([[0.21412, 0.5125214124]])
print(a)

any suggestion?

adekusar-drl commented 9 months ago

I think you should create an issue here: https://github.com/qiskit-community/qiskit-machine-learning as it is related to qiskit machine learning.

Honestly, I don't get the question. But if you have a trained model and you are running inference on quantum hardware, then this is the way to go:

from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Session
from qiskit_machine_learning.algorithms import VQC

IBM_API = "MY_IBM_API"
service = QiskitRuntimeService(token=IBM_API, channel="ibm_quantum")
backend = service.backend("ibm_perth")
sampler = Sampler(session=Session(service=service, backend=backend))

vqc = VQC.load("saved_model")
vqc.neural_network.sampler = sampler

X = ...
vqc.predict(X)
Herutriana44 commented 9 months ago

I think you should create an issue here: https://github.com/qiskit-community/qiskit-machine-learning as it is related to qiskit machine learning.

Honestly, I don't get the question. But if you have a trained model and you are running inference on quantum hardware, then this is the way to go:

from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Session
from qiskit_machine_learning.algorithms import VQC

IBM_API = "MY_IBM_API"
service = QiskitRuntimeService(token=IBM_API, channel="ibm_quantum")
backend = service.backend("ibm_perth")
sampler = Sampler(session=Session(service=service, backend=backend))

vqc = VQC.load("saved_model")
vqc.neural_network.sampler = sampler

X = ...
vqc.predict(X)

Thanks, I Will try this

jakelishman commented 9 months ago

Thanks both. I'll close this now because it's best to continue any further necessary discussion on the Machine Learning repo, but please feel free to raise more issues here if they're part of Qiskit core.