-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add support executing circuits with a SamplerV2 instance #1470
Conversation
After skimming around this seems like the easiest way without making huge changes |
This looks reasonable to me. I would consider taking A downside to this suggestion is then the user has to pass both the backend and the sampler. The code could try to use Did you test a parallel experiment? Maybe It would be nice to have a test assuming the qiskit-ibm-runtime and qiskit-aer samplers work similarly enough. |
@wshanks I tested with the t1 notebook here https://github.com/qiskit-community/qiskit-device-benchmarking/blob/main/notebooks/bell_tphi.ipynb and it worked fine. |
d3df96a
to
06b0bdf
Compare
I changed this up a bit. There's now a flag to use backend.run since that will be the outlier and we will have to retire it completely soon. You can pass in a sampler ... didn't resolve what @wshanks was worried about with the backend getting pulled from the sampler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this is merged, there should be release note added for how to work with the sampler. I am trying to summarize the supported paths after this PR:
backend.run
-- if you passbackend_run=True
to an experiment'srun()
method, the experiment will run as it has in the past. You could also passbackend_run=True
to the experiment's__init__
but most experiments don't dosuper().__init__(**kwargs)
so thebackend_run
would not get passed up toBaseExperiment.__init__
. We could treatbackend_run
withexperiment_options
but the usefulness ofbackend.run
diminishes greatly very soon so it is probably not worth much effort.qiskit_ibm_runtime.SamplerV2
-- one can pass aqiskit_ibm_runtime.SamplerV2
to an experiment'srun()
method. That sampler will get used to run the jobs (as long asbackend_run=True
was not also used).- Default case -- if a
backend
was already set on the experiment and it is called without passing a backend or sampler, aqiskit_ibm_runtime.SamplerV2
is created on the fly and some options are translated into sampler options for it. Then it is used to run the jobs. - Alternative sampler implementation -- there is no way to pass an alternative sampler implementation. The current code will ignore it and generate a new
qiskit_ibm_runtime.SamplerV2
to execute with instead.
if not self._backend_run: | ||
if sampler is None: | ||
# instantiate a sampler from the backend | ||
sampler = Sampler(self.backend) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I was expecting a check for qiskit_ibm_runtime.IBMBackend
and giving an error otherwise. I see though that qiskit-ibm-runtime does that check itself and re-routes down a local path if it is passed a backend that is not a qiskit_ibm_runtime.IBMBackend`. I have not played with that. I suppose it works well enough? Aer also has its own primitive implementations that might be more efficient so the tests probably should be switched to those some time.
* Patch ExperimentData.completion_times to handle Job.time_per_step not existing * Pass noise_model run option through to Sampler * Add support for level 1 data to Sampler execution * Handle case where the Sampler strips circuit metadata from results * Mark some test backends as simulators so the sampler does not try to validate circuits * Change some tests to be more consistent about shots since the Sampler can not handle the requested number of shots differing from the shots in the actual results. * Support level 2 bitstrings in MockIQBackend * Fix PulseBackend returning data as numpy array instead of a list * Pass run options through to backend in T2HahnBackend * Do not set block_for_results timeout to 0 when TEST_TIMEOUT is 0 (TEST_TIMEOUT=0 indicates no timeout, not immediate timeout). * Monkey-patch BackendSamplerV2's run circuits function in the tests so that it does not strip circuit metadata that the test backends need to generate results. * Fix inconsistency between bitstring format and number of qubits in restless test. * Handle case where job class does not have error_message
These changes could be merged into #1470 (PR could be redirected to that branch). For now I am just opening a PR to see how the tests run in CI.
Tested on qiskit-monitoring, and it works great for all of qiskit-monitoring usages! |
I updated the PR description because that is what is used for the commit message when we merge in this repo. |
This change adds a
sampler
argument toBaseExperiment.run()
which causes thatBaseSamplerV2
instance to be used to run the experiment's circuits. Additionally, if nosampler
is passed,BaseExperiment.run()
defaults to instantiating aqiskit_ibm_runtime.SamplerV2
object and running the circuits with that.qiskit_ibm_runtime.SamplerV2
can execute using IBM Quantum's sampler primitive and can also fall back to callingbackend.run
for backends that are not representing IBM Quantum devices. Abackend_run
parameter is also added toBaseExperiment.run()
which causes the oldbackend.run()
execution path to be used. For sampler execution, the job results are translated back into the format expected frombackend.run
so that the remaining analysis code can be used unchanged. Some additional changes have been made to account for differences betweenbackend.run
job result classes and primitive job result classes.