-
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
Add dedicated functions for memory marginalization #8051
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d796ba3
Add dedicated functions for memory marginalization
mtreinish ea86c35
Fix rustfmt
mtreinish f234efe
Add missing test file
mtreinish c4924f3
Fix typos
mtreinish e8930c1
Remove unused import
mtreinish b088de1
Merge remote-tracking branch 'origin/main' into marginal-memory
mtreinish a0ca25c
Increate default parallel_threshold to 1000
mtreinish e709ce8
Add support for different measurement levels
mtreinish b718200
Merge remote-tracking branch 'origin/main' into marginal-memory
mtreinish 7c2be93
Update docstring
mtreinish 141ca7b
Add release note
mtreinish 20b4c60
Expand unit tests
mtreinish 6bc9e6c
Fix rustfmt
mtreinish 85cb99c
Apply suggestions from code review
mtreinish a9262c2
Merge remote-tracking branch 'origin/main' into marginal-memory
mtreinish 5c81510
Use a lookup table instead of a match statement
mtreinish 7229634
Merge branch 'main' into marginal-memory
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
features: | ||
- | | ||
Added a new function :func:`~.marginal_memory` which is used to marginalize | ||
shot memory arrays. Provided with the shot memory array and the indices | ||
of interest the function will return a maginized shot memory array. This | ||
function differs from the memory support in the :func:`~.marginal_counts` | ||
method which only works on the ``memory`` field in a :class:`~.Results` | ||
object. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// This code is part of Qiskit. | ||
// | ||
// (C) Copyright IBM 2022 | ||
// | ||
// This code is licensed under the Apache License, Version 2.0. You may | ||
// obtain a copy of this license in the LICENSE.txt file in the root directory | ||
// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Any modifications or derivative works of this code must retain this | ||
// copyright notice, and modified files need to carry a notice indicating | ||
// that they have been altered from the originals. | ||
|
||
lazy_static! { | ||
static ref HEX_TO_BIN_LUT: [&'static str; 256] = { | ||
let mut lookup = [""; 256]; | ||
lookup[b'0' as usize] = "0000"; | ||
lookup[b'1' as usize] = "0001"; | ||
lookup[b'2' as usize] = "0010"; | ||
lookup[b'3' as usize] = "0011"; | ||
lookup[b'4' as usize] = "0100"; | ||
lookup[b'5' as usize] = "0101"; | ||
lookup[b'6' as usize] = "0110"; | ||
lookup[b'7' as usize] = "0111"; | ||
lookup[b'8' as usize] = "1000"; | ||
lookup[b'9' as usize] = "1001"; | ||
lookup[b'A' as usize] = "1010"; | ||
lookup[b'B' as usize] = "1011"; | ||
lookup[b'C' as usize] = "1100"; | ||
lookup[b'D' as usize] = "1101"; | ||
lookup[b'E' as usize] = "1110"; | ||
lookup[b'F' as usize] = "1111"; | ||
lookup[b'a' as usize] = "1010"; | ||
lookup[b'b' as usize] = "1011"; | ||
lookup[b'c' as usize] = "1100"; | ||
lookup[b'd' as usize] = "1101"; | ||
lookup[b'e' as usize] = "1110"; | ||
lookup[b'f' as usize] = "1111"; | ||
lookup | ||
}; | ||
} | ||
|
||
#[inline] | ||
pub fn hex_to_bin(hex: &str) -> String { | ||
hex[2..] | ||
.chars() | ||
.map(|c| HEX_TO_BIN_LUT[c as usize]) | ||
.collect() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is just a curiosity. Is the list of integer more efficient in memory footprint than binary ndarray? Given we use memory information to run restless analysis in qiskit experiment, it should take memory efficient representation to run a parallel experiment in 100Q+ device.
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.
Do you mean like storing the shot memory as a 2d array where each row has n elements for each bit or something else? The list of ints here will be more memory efficient than that in the rust side because I'm using a
Vec<BigUint>
(whch is just a Vec of digits internally) and it will not be fixed with for each shot. The python side I expect would be similar since the Python integer class is very similar to BigUint (a byte array of digits). (although list isn't necessarily as contiguous as aVec<T>
/ndarray
). I think it would be best to test this though to be sure and settle on a common way to represent large results values in a non-string type.As an aside I only used a list here because numpy doesn't have support for arbitrary large integers (outside of using a
object
dtype, which ends up just being a pointer to the python heap, for python ints) and I was worried about theThere 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. Sounds like current implementation is reasonable (I just worried about storing 2**100 for "10000...0", in binary array it's just 100 binary element).