-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix StatevectorSampler
to raise an error if a circuit with c_if is passed
#12842
Conversation
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 10159455208Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
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.
The fix looks reasonable to me.
qc2 = QuantumCircuit(5, 5) | ||
qc2.compose(qc, [0, 2, 3], [2, 4], inplace=True) | ||
cregs = [creg.name for creg in qc2.cregs] | ||
qc3 = QuantumCircuit.copy_empty_like(qc2) | ||
qc3.ry(np.pi / 4, 2) | ||
qc3.cx(2, 1) | ||
qc3.cx(0, 1) | ||
qc3.h(0) | ||
qc3.measure(0, 2) | ||
qc3.measure(1, 4) |
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.
it looks like qc2 is not used, so maybe qc3
can replace qc2
directly?
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.
I used copy_empty_like to copy the aliased registers.
I updated the circuit and comments to clarify it.
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.
If there is more straightforward way to make aliased registers, I would like to use it. This case does not look so intuitive.
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.
got it, I am not so familiar with aliased registers either, but the comment already makes it much clearer 👍
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.
LGTM, I think we can try to get the fix into 1.2, and potentially backport to 1.1? what do you think @t-imamichi
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.
Thanks :)
@Mergifyio backport stable/1.1 |
Thanks. It makes sense to backport to 1.1 |
…passed (#12842) (#12851) * fix StatevectorSampler with c_if * add comment (cherry picked from commit 239a669) Co-authored-by: Takashi Imamichi <[email protected]>
…passed (Qiskit#12842) * fix StatevectorSampler with c_if * add comment
Summary
StatevectorSampler
cannot handle both control flow and c_if becauseStatevector
cannot.But, it ignores
c_if
by mistake. This PR makesStatevectorSampler
raise an error if a circuit with c_if is passed.A unit test of
StatevectorSampler
usedc_if
accidentally. So, this PR also fixes the case without passing c_if toStatevectorSampler
.Fixed #12281
Details and comments