Closed xaviervasques closed 2 weeks ago
Hi @xaviervasques, thanks for raising this issue. It appears because V2 primitives are not supported in Qiskit Machine Learning 0.7.2 ( see https://github.com/qiskit-community/qiskit-machine-learning/issues/742 and https://github.com/qiskit-community/qiskit-machine-learning/issues/786) but are the only type that Qiskit IBM Runtime supports for running jobs on real backends.
The upcoming 0.8.0 version includes support for V2 primitives, so this error should disappear after you run with upgraded Qiskit Machine Learning (pip install -U qiskit-machine-learning
). We expect the 0.8.0 version to come out at the end of October 2024.
{Sampler,Estimator}V2
and call .run(...)
the arguments must be structured as a Primitive Unified Bloc (PUB) which is of type tuple
, or a list of PUBs (list[tuple]
). This structure is different from that of the V1 primitives and leads to the error above (TypeError: run() takes 2 positional arguments but 3 were given
) when V1-like arguments are used in V2 primitives. .run(...)
is triggered in your code when you call SamplerQNN(...).fit(...)
.from qiskit.primitives import Sampler
you are implicitly using V1 Base primitives, which do not have the additional functionality to be run on hardware directly and also returns an argument mismatch error from SamplerQNN(...).fit(...)
. Qiskit IBM Runtime has derived primitives that do just that, however, V1 primitives can no longer run on real backends.We should expect your experiment to run on hardware with the upcoming 0.8.0 version and V2 primitive support. Until then, you may run simulations of SamplerQNN
in local testing mode with Qiskit Aer backends and the V1 primitives as
from qiskit_ibm_runtime import EstimatorV1 as Estimator, SamplerV1 as Sampler
sampler = Sampler(backend)
sampler_qnn = SamplerQNN(
circuit=qc,
input_params=input_params,
weight_params=weight_params,
interpret=parity,
output_shape=2, # Number of classes
sampler=sampler
)
With this setup, you will be able to switch to submitting to the real device just by changing the definitions of backend
and restoring from qiskit_ibm_runtime import EstimatorV2 as Estimator, SamplerV2 as Sampler
as you originally had. I hope this helps!
Thank you Edoardo. I will wait for the 0.8.0, hope it is coming soon :)
Yes indeed, we are looking forward to it! The feature will be in the main branch as soon as the PR is merged, but live from pip install --update
once 0.8.0 is released.
Looking forward to the 0.8.0.
Environment
What is happening?
Hello,
I am trying to run a SamplerQNN but since new version of qiskit I am not able to run it on real hardware (on local machine it works).
I have the following code that I run with my local machine and that works perfectly:
When I want to run it on real hardware, I did the following modifications and doesn't work:
I get the following error message:
If I change
from qiskit_ibm_runtime import QiskitRuntimeService, EstimatorV2 as Estimator, SamplerV2 as Sampler
to
from qiskit.primitives import Sampler
I have the following error message:
Can you please help me ?
Thank you in advance
How can we reproduce the issue?
I provided the code above
What should happen?
The output should be something like:
Any suggestions?
No response