Remove a validation check of circuits for BaseSampler (follow-up of #8678)#8708
Conversation
|
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
1c2ea6d to
7403204
Compare
7403204 to
195aefd
Compare
Pull Request Test Coverage Report for Build 3135998431
💛 - Coveralls |
nonhermitian
left a comment
There was a problem hiding this comment.
I still think this has issues (see my one comment). I think the only check that one can make at this stage is to raise only if there is no classical bits at all. That way at least you know that there is nothing to measure into, guaranteeing a empty dict output
| def _preprocess_circuit(circuit: QuantumCircuit): | ||
| circuit = init_circuit(circuit) | ||
| q_c_mapping = final_measurement_mapping(circuit) | ||
| if set(range(circuit.num_clbits)) != set(q_c_mapping.values()): |
There was a problem hiding this comment.
This looks like it is still going to raise if the number of clbits is not equal to the number of final measurements. That is to say that if I wrote to all my bits via mid-circuit measurements then this would be triggered.
There was a problem hiding this comment.
This is part of the reference implementation based on quantum_info.Statevector. It requires final measurements. Statevector does not support mid-circuit measurements.
There was a problem hiding this comment.
I updated the title of this PR to mention BaseSampler
There was a problem hiding this comment.
But then you are blocking real-world use cases for a simulation method that does not scale. Does not seem like a fruitful direction to me.
There was a problem hiding this comment.
The reference implementation was designed to be as simple as possible. Runtime primitives and Aer primitives are more appropriate for scaling, e.g., Qiskit/qiskit-aer#1531
This is similar to the relationship of BasicAer and Aer simulator. The reference implementation of primitives corresponds to BasicAer and Aer primitives corresponds to Aer simulator.
There was a problem hiding this comment.
That is another way to think about it; Just overload all in Runtime. In some sense that is what would probably need to be done because a state vector simulator is quite far removed from a real hardware sampling routine
There was a problem hiding this comment.
There is a PR #8668 working on backend-based Sampler. It is closer to real hardware sampling. Once it's merged, we can discuss whether we need the reference implementation.
There was a problem hiding this comment.
This check is only part of the reference implementation of Sampler and not part of BaseSampler. So, other Sampler implementations does use this check. Other implementations are supposed to inherit only BaseSampler.
There was a problem hiding this comment.
The reference implementation Sampler needs this check. So, I have to put it in BaseSampler (abstract class) or Sampler (reference implementation). I moved it from Sampler to BaseSampler in #8668. I want to revert it in this PR. If this PR is not merged, the check stays in BaseSampler and raises an error for all implementations not only the reference impl but also qiskit-ibm-runtime.
|
For the record, I do not think there is a completely automated way to determine what measurements an end-user considers as part of the final output distributions. Dynamic circuits make this impossible in general. |
|
Does Sampler need to support mid-circuit measurements in the first place? I thought mid-circuit measurement could not be supported the various error-mitigation methods. But I am not aware of any discussions around this, and I don't know the range of circuits Sampler can take (i.e. should Sampler support dynamic circuits?). |
|
I would say absolutely, otherwise how is it a "primitive"? One can correct some mid-circuit measurements provided the results of those measurements are aggregated. Several of us would like this, and I am re-tooling M3 to allow for it. However, the single-shot results cannot be; it would have to be corrected in HW. |
Sampler (follow-up of #8678)BaseSampler (follow-up of #8678)
This PR moves the check of classical bits and final measurement mapping from |
|
I resolved conflicts to merge main. |
# Conflicts: # qiskit/primitives/base_sampler.py
bdea96e to
3fc20ae
Compare
There was a problem hiding this comment.
I think it's good. Can I merge this? @nonhermitian
# Conflicts: # qiskit/primitives/base_sampler.py
|
I fixed the conflict. |
|
This PR conflicts with #8760. So, I fixed a test with a note. |
ikkoham
left a comment
There was a problem hiding this comment.
At least, this PR is better than before since the validation in BaseSampler is removed.
If it's not sufficient, let's fix it after RC release.
Summary
#8678 introduced some validation check of circuits for
BaseSampler.But, @nonhermitian suggested relaxing a check to support mid-circuit measurements in the future.
See the thread for details. #8678 (comment)
Follow-up #8678
Details and comments
The check of measurements is moved from
BaseSamplertoSampler(the reference impl) becauseSamplerrequires it. This is the revert of a change of #8678.