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

VQC inside session #770

Open
dhirajmadan1 opened this issue Feb 19, 2024 · 5 comments
Open

VQC inside session #770

dhirajmadan1 opened this issue Feb 19, 2024 · 5 comments
Labels
Hardware runtime 💻 Running jobs on IBM quantum devices status: need information Further information is requested type: discussion 🗣️ General discussions and explanations

Comments

@dhirajmadan1
Copy link

dhirajmadan1 commented Feb 19, 2024

What should we add?

How to train/ test a VQC model using qiskit runtime sessions?
I tried encapsulating under session as below.
But it seems to be running on simulator even though a real backend is selected.

service = QiskitRuntimeService(channel="ibm_quantum", token=qAccesKey)
backend = least_busy(service.backends(simulator=False, operational=True, min_num_qubits=args.dim))

with Session(service = service, backend = backend):
        vqc = VQC(feature_map=feature_map,
                           ansatz=ansatz,
                           optimizer=NFT(maxiter=args.blk),
                           callback=callback_graph,
                        )
        vqc.fit(train_data, train_labels)
@dhirajmadan1 dhirajmadan1 added the type: feature request 💡 New feature or request label Feb 19, 2024
@woodsp-ibm
Copy link
Member

woodsp-ibm commented Feb 20, 2024

VQC has a sampler parameter

sampler (BaseSampler | None) – an optional Sampler primitive instance to be used by the underlying SamplerQNN neural network. If None is passed then an instance of the reference Sampler will be used.

With None passed (default) as it states it uses the reference Sampler primitive from Qiskit. To use a real backend you need to instantiate and explicitly pass a runtime Sampler. As your code is above the Session is unused since that is only meaningful when used with the runtime primitives.

@woodsp-ibm woodsp-ibm added type: discussion 🗣️ General discussions and explanations and removed type: feature request 💡 New feature or request labels Feb 20, 2024
@dhirajmadan1
Copy link
Author

Thanks a lot @woodsp-ibm . I have made the above change i.e. adding a sampler. Now I am getting this exception:-
qiskit_machine_learning.exceptions.QiskitMachineLearningError: 'Sampler job failed.'

@woodsp-ibm
Copy link
Member

woodsp-ibm commented Feb 28, 2024

Its not a lot to go on. It should work. Maybe add your updated code here just in case. You can also look at the jobs in your account and see if there is any further error information listed there.

@edoaltamura
Copy link
Collaborator

@dhirajmadan1 does the issue persist when running VQC in a Session? I think your implementation as you wrote above should work. Please, feel free to describe more of the context of your problem, if necessary, so that we can further assist you.

@edoaltamura edoaltamura added the status: need information Further information is requested label Jul 29, 2024
@edoaltamura edoaltamura added the Hardware runtime 💻 Running jobs on IBM quantum devices label Aug 7, 2024
@edoaltamura
Copy link
Collaborator

@dhirajmadan1, just a note that #843 is coming up with added support for V2 primitives. Once the PR is merged and the feature live in the upcoming 0.8.0 version, you may want to update the package and re-run your example.

We look forward to receiving your feedback on your run with Session mode.

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 status: need information Further information is requested type: discussion 🗣️ General discussions and explanations
Projects
None yet
Development

No branches or pull requests

3 participants