qiskit-experiments icon indicating copy to clipboard operation
qiskit-experiments copied to clipboard

WIP: Add the sampler

Open dcmckayibm opened this issue 1 year ago • 3 comments

Summary

Add sampler option

Details and comments

Some details that should be in this section include:

  • Why this change was necessary
  • What alternative solutions were considered and why the current solution was chosen
  • What tests and documentation have been added/updated
  • What do users and developers need to know about this change

Note that this entire PR description field will be used as the commit message upon merge, so please keep it updated along with the PR. Secondary discussions, such as intermediate testing and bug statuses that do not affect the final PR, should be in the PR comments.

PR checklist (delete when all criteria are met)

  • [ ] I have read the contributing guide CONTRIBUTING.md.
  • [ ] I have added the tests to cover my changes.
  • [ ] I have updated the documentation accordingly.
  • [ ] I have added a release note file using reno if this change needs to be documented in the release notes.

dcmckayibm avatar Sep 21 '24 19:09 dcmckayibm

After skimming around this seems like the easiest way without making huge changes

dcmckayibm avatar Sep 21 '24 19:09 dcmckayibm

This looks reasonable to me. I would consider taking sampler as an argument though. That way a user can pass a different sampler if necessary, for example the SamplerV2 from Aer. It would also let the user set options on the sampler before passing it in, since the sampler has a complicated options structure that is hard to map onto the flat run_options format that was used for backend.run.

A downside to this suggestion is then the user has to pass both the backend and the sampler. The code could try to use sampler._backend for the backend. That exists for the qiskit-ibm-runtime and qiskit-aer samplers so covers all current cases that I know of, but _backend is not specified in the SamplerV2 base class so I would fall back to the backend argument if hasattr(sampler, "_backend") is false.

Did you test a parallel experiment? Maybe join_data does the right thing? It is not efficient since it is joining the registers and then marginalizing them instead of using the already margninalized results that the sampler returns but that is fine for now.

It would be nice to have a test assuming the qiskit-ibm-runtime and qiskit-aer samplers work similarly enough.

wshanks avatar Sep 22 '24 12:09 wshanks

@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.

dcmckayibm avatar Sep 24 '24 07:09 dcmckayibm

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.

dcmckayibm avatar Oct 07 '24 07:10 dcmckayibm

Tested on qiskit-monitoring, and it works great for all of qiskit-monitoring usages!

dekelmeirom avatar Oct 17 '24 10:10 dekelmeirom

I updated the PR description because that is what is used for the commit message when we merge in this repo.

wshanks avatar Oct 24 '24 19:10 wshanks