Skip to content

Narrow QPY 18 SPARSE_OBSERVABLE bit terms from uint16_t to uint8_t - #16800

Merged
gadial merged 8 commits into
Qiskit:mainfrom
Mohamedma96:paulielempack-bitterm-u8
Aug 25, 2026
Merged

Narrow QPY 18 SPARSE_OBSERVABLE bit terms from uint16_t to uint8_t#16800
gadial merged 8 commits into
Qiskit:mainfrom
Mohamedma96:paulielempack-bitterm-u8

Conversation

@Mohamedma96

@Mohamedma96 Mohamedma96 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

QPY 18 now stores the bit terms of a SPARSE_OBSERVABLE payload as (uint8_t) instead of (uint16_t).
SparseObservable operators is now one byte smaller per bit term, with no loss of information.

The change is backwards compatible: v17 and earlier payloads load exactly as before, and qpy.dump(..., version=17) still emits the older encoding.

Tests

test/python/qpy/test_v18.py::TestV18SparseObservable covers an evolution gate whose observable
uses every BitTerm variant and one over a mixed SparseObservable/SparsePauliOp list, each
round-tripped at v17 and v18 so both widths are exercised.

Note

This PR also depends on the bug fix PR: #16788
After merging the fix more test cases can be added.

AI/LLM disclosure

  • I didn't use LLM tooling, or only used it privately.
  • I used the following tool to help write this PR description:
  • I used the following tool to generate or modify code:

… bytes to 1 byte

Signed-off-by: mohamedmahameed <mohamed.mahameed@ibm.com>
Signed-off-by: mohamedmahameed <mohamed.mahameed@ibm.com>
@Mohamedma96
Mohamedma96 requested a review from a team as a code owner August 19, 2026 12:44
@Mohamedma96
Mohamedma96 requested a review from gadial August 19, 2026 12:44
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Aug 19, 2026
@qiskit-bot

Copy link
Copy Markdown
Collaborator

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:

  • @Qiskit/terra-core
  • @mtreinish

@ShellyGarion ShellyGarion removed the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Aug 19, 2026
@ShellyGarion ShellyGarion added the mod: qpy Related to QPY serialization label Aug 19, 2026
@ShellyGarion ShellyGarion added this to the 2.6.0 milestone Aug 20, 2026
gadial
gadial previously approved these changes Aug 24, 2026

@gadial gadial left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread crates/qpy/src/formats.rs Outdated
/// representation is always `u8` and this parser absorbs the difference, so nothing downstream has
/// to care which version produced the payload.
#[binrw::parser(reader, endian)]
fn read_bitterms(version: u8, count: u64) -> BinResult<Vec<u8>> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good way to deal with this.

Comment thread crates/qpy/src/circuit_writer.rs Outdated

let data = match gate_type {
CircuitInstructionType::PauliEvolutionGate => Some(serialize(
// The evolution payload needs the target QPY version: the width of the observable's bit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need to elaborate on this here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed unnecessary comment

Signed-off-by: mohamedmahameed <mohamed.mahameed@ibm.com>
gadial
gadial previously approved these changes Aug 24, 2026
@gadial
gadial added this pull request to the merge queue Aug 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Aug 24, 2026
@gadial
gadial enabled auto-merge August 25, 2026 09:49
@gadial
gadial added this pull request to the merge queue Aug 25, 2026
Merged via the queue into Qiskit:main with commit 87b988a Aug 25, 2026
55 of 57 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Done in Qiskit 2.6 Aug 25, 2026
@ShellyGarion ShellyGarion added the Changelog: Changed Add a "Changed" entry in the GitHub Release changelog. label Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Changed Add a "Changed" entry in the GitHub Release changelog. mod: qpy Related to QPY serialization

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants