qiskit-machine-learning icon indicating copy to clipboard operation
qiskit-machine-learning copied to clipboard

EstimatorQNN/SamplerQNN with BaseEstimatorV2/BaseSamplerV2

Open ksk0629 opened this issue 1 year ago • 2 comments

Is there any way to use BaseEstimatorV2/BaseSamplerV2 with EstimatorQNN/SamplerQNN at the moment?

ksk0629 avatar Oct 18 '24 01:10 ksk0629

Hi @ksk0629, it depends.

  • In simulations (e.g. Qiskit Aer) you can already use V2 primitives by importing the correct class from Qiskit like from qiskit.primitives.base import BaseEstimatorV2 and passing an instance of it in EstimatorQNN(estimator=...). Similarly, you can do this for the Sampler.

  • If you want to run on a real IBM backend, EstimatorQNN or SamplerQNN are not supported at the moment with V2 primitives (https://github.com/Qiskit/qiskit-ibm-runtime/issues/1857). However, Qiskit Machine Learning v.0.8 will support V2 primitives, with initial release expected at the end of October 2024, see https://github.com/qiskit-community/qiskit-machine-learning/milestone/4.

Does this answer your question?

edoaltamura avatar Oct 18 '24 11:10 edoaltamura

Hi @edoaltamura, I appreciate your answer!

I am sorry that I am not able to provide the error at the moment, but I think qiskit_aer.primitives.EstimatorV2, which inherits from BaseEstimatorV2, is incompatible with EstimatorQNN. It is no problem to give it to EstimatorQNN as the estimator parameter. However, when you start to fit the EstiamtorQNN an error happens on the run (or _run) function. To the best of my recollection, it was about the number of parameters and indeed was different according to the implementation.

But,

However, Qiskit Machine Learning v.0.8 will support V2 primitives, with initial release expected at the end of October 2024, see https://github.com/qiskit-community/qiskit-machine-learning/milestone/4.

This is quite exciting news indeed. I appreciate you informing the article :)

ksk0629 avatar Oct 18 '24 11:10 ksk0629

Just curious and maybe here is not the right place to ask this, but how is v0.8.0 going?

ksk0629 avatar Nov 05 '24 23:11 ksk0629

Hi @ksk0629, you can check our fork branch. It is still getting tested for V2 primitives, and for 0.8.0, our plan is to support both V1 and V2 primitives, and deprecate V1 in the following updates. Currently, it is almost finalised, but, we need to prepare it before the release.

Hope this helps.

The delay is caused by the deprecation of qiskit-algorithms library.

OkuyanBoga avatar Nov 07 '24 16:11 OkuyanBoga

Hi @OkuyanBoga, thank you for sharing your fork branch with me and additional information. Understood. I'm looking forward to using the new version :)

ksk0629 avatar Nov 08 '24 14:11 ksk0629

Just a note that https://github.com/qiskit-community/qiskit-machine-learning/pull/843 will close this issue and should resolve the problem. Looking forward to hearing your feedback on the V2 primitive update @ksk0629!

edoaltamura avatar Nov 08 '24 17:11 edoaltamura

Hi @ksk0629, I hope the new release helps.

If you find any issue, or even want to fix those or if you want to add new functionality, please feel free to submit an issue or a pull request, we are open to any contribution. :)

OkuyanBoga avatar Nov 12 '24 13:11 OkuyanBoga