-
Notifications
You must be signed in to change notification settings - Fork 3k
QPY: Bug fix in Rust implementation of SparsePauliObservableElemPack
#16788
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -506,21 +506,21 @@ pub struct SparsePauliOpListElemPack { | |
| #[derive(Debug)] | ||
| pub struct SparsePauliObservableElemPack { | ||
| pub num_qubits: u32, | ||
| #[bw(calc = coeff_data.len() as u64)] | ||
| #[bw(calc = (coeff_data.len() * std::mem::size_of::<f64>()) as u64)] | ||
| pub coeff_data_size: u64, | ||
| #[bw(calc = bitterm_data.len() as u64)] | ||
| #[bw(calc = (bitterm_data.len() * std::mem::size_of::<u16>()) as u64)] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's something I'm not understanding, I thought this would correspond to the size of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bug in the original python implementation, and is actually one of the things we're gonna fix in QPY18, you can see it on the list at #15524. Even more, this bug was found as part of the fix... The python code used |
||
| pub bitterm_data_size: u64, | ||
| #[bw(calc = inds_data.len() as u64)] | ||
| #[bw(calc = (inds_data.len() * std::mem::size_of::<u32>()) as u64)] | ||
| pub inds_data_size: u64, | ||
| #[bw(calc = bounds_data.len() as u64)] | ||
| #[bw(calc = (bounds_data.len() * std::mem::size_of::<u64>()) as u64)] | ||
| pub bounds_data_size: u64, | ||
| #[br(count = coeff_data_size)] | ||
| #[br(count = coeff_data_size / std::mem::size_of::<f64>() as u64)] | ||
| pub coeff_data: Vec<f64>, // complex numbers stored in format [re1, im1, re2, im2,...] | ||
| #[br(count = bitterm_data_size)] | ||
| #[br(count = bitterm_data_size / std::mem::size_of::<u16>() as u64)] | ||
| pub bitterm_data: Vec<u16>, | ||
| #[br(count = inds_data_size)] | ||
| #[br(count = inds_data_size / std::mem::size_of::<u32>() as u64)] | ||
| pub inds_data: Vec<u32>, | ||
| #[br(count = bounds_data_size)] | ||
| #[br(count = bounds_data_size / std::mem::size_of::<u64>() as u64)] | ||
| pub bounds_data: Vec<u64>, | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| fixes: | ||
| - | | ||
| Fixed a bug with the QPY serialization and deserialization of instructions | ||
| containing :class:`.SparseObservable` data. | ||
| Fixed `#16722 <https://github.com/Qiskit/qiskit/issues/16722>`__. |
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.
Aren't the coeffs
Complex64? Or why isf64the correct size?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.
Look at
_write_elem_sparsein the python code (the source of the format, in this case). coeffs are stored usingSo each coeff is stored using two consecutive
f64values comprising the originalComplex64.In the rust code we do the same, on
pack_sparse_pauli_op: