Skip to content
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

Merged
merged 2 commits into from
Jul 30, 2024

Conversation

t-imamichi
Copy link
Member

Summary

StatevectorSampler cannot handle both control flow and c_if because Statevector cannot.
But, it ignores c_if by mistake. This PR makes StatevectorSampler raise an error if a circuit with c_if is passed.
A unit test of StatevectorSampler used c_if accidentally. So, this PR also fixes the case without passing c_if to StatevectorSampler.

Fixed #12281

Details and comments

@t-imamichi t-imamichi requested review from a team as code owners July 29, 2024 14:33
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core
  • @ajavadia
  • @levbishop
  • @t-imamichi

@t-imamichi t-imamichi added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: primitives Related to the Primitives module labels Jul 29, 2024
@coveralls
Copy link

coveralls commented Jul 29, 2024

Pull Request Test Coverage Report for Build 10159455208

Warning: 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

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 40 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.007%) to 89.757%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 92.62%
qiskit/primitives/containers/bit_array.py 8 96.26%
qiskit/transpiler/passes/routing/star_prerouting.py 10 93.75%
crates/qasm2/src/parse.rs 18 96.69%
Totals Coverage Status
Change from base Build 10145491847: -0.007%
Covered Lines: 66950
Relevant Lines: 74590

💛 - Coveralls

Copy link
Contributor

@ElePT ElePT left a 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.

Comment on lines 603 to 611
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)
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Contributor

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 👍

Copy link
Contributor

@ElePT ElePT left a 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

Copy link
Contributor

@ihincks ihincks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

@ElePT ElePT added this to the 1.2.0 milestone Jul 30, 2024
@ElePT ElePT added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Jul 30, 2024
@ElePT ElePT added this pull request to the merge queue Jul 30, 2024
Merged via the queue into Qiskit:main with commit 239a669 Jul 30, 2024
15 checks passed
mergify bot pushed a commit that referenced this pull request Jul 30, 2024
…passed (#12842)

* fix StatevectorSampler with c_if

* add comment

(cherry picked from commit 239a669)
@ElePT
Copy link
Contributor

ElePT commented Jul 30, 2024

@Mergifyio backport stable/1.1

@t-imamichi t-imamichi deleted the sampler-c_if branch July 30, 2024 12:04
@t-imamichi
Copy link
Member Author

Thanks. It makes sense to backport to 1.1

github-merge-queue bot pushed a commit that referenced this pull request Jul 30, 2024
…passed (#12842) (#12851)

* fix StatevectorSampler with c_if

* add comment

(cherry picked from commit 239a669)

Co-authored-by: Takashi Imamichi <[email protected]>
Procatv pushed a commit to Procatv/qiskit-terra-catherines that referenced this pull request Aug 1, 2024
…passed (Qiskit#12842)

* fix StatevectorSampler with c_if

* add comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: primitives Related to the Primitives module stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

midcircuit measurement issue with StatevectorSampler
5 participants