Fix OverflowError in QuantumCircuit.for_loop for negative integers in list indexset #16432
Fix OverflowError in QuantumCircuit.for_loop for negative integers in list indexset #16432at264939-ctrl wants to merge 10 commits into
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 following people are relevant to this code:
|
|
This PR seems to break backwards compatibility, since QPY files created with older versions would assume the stored value is If needed, I can help with that. |
Coverage Report for CI Build 27537541812Coverage decreased (-0.02%) to 87.517%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
f5184cf to
3aa50de
Compare
Thank you I've spent some time investigating the QPY compatibility as you suggested, and you were spot on. I've updated test/qpy_compat/test_qpy.py for_loop Backwards Compatibility (1.x -> Dev): Verified that Qiskit 1.2.4 and 1.3.1 (the Python era) generate these QPY files correctly. My local dev branch with this fix now loads these files without issue. main test_qpy.py I've pushed the updates to test/qpy_compat/test_qpy.py |
|
We expect all responses to PRs to be from humans and not LLMs. You may use an LLM to assist with writing English, but it's not appropriate to have an LLM generate the entire response. |
I use ai because English is not my first language |
c331acd to
0d198ee
Compare
Summary
This PR fixes an
OverflowErrorthat occurs when passing a list containing negative integers as an indexset toQuantumCircuit.for_loop.The Problem:
The Rust backend represented the for_loop indexset list as
Vec<usize>(unsigned). This caused a crash when Python passed negative integers, as they cannot be converted to an unsigned type. PyRange already uses signed integers (isize), making the behavior inconsistent across different iterable forms.The Fix:
ForCollection::List(Vec<usize>)toForCollection::List(Vec<isize>)in crates/circuit/src/operations.rs.Fixes #16412
AI/LLM disclosure