Fix marginal counts for mixed-width hex Counts#16200
Open
snoopuppy582 wants to merge 1 commit into
Open
Conversation
|
|
Author
|
sign |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #16190.
Summary
This updates count marginalization to infer the classical-bit width from the longest cleaned count key, then treats shorter keys as left-zero-padded while marginalizing. This fixes
Countsobjects created from hexadecimal input withoutmemory_slots, where the stored bitstrings can have mixed widths such as"0"and"11".The same width handling is applied to the accelerated marginal-distribution path so higher-bit indices do not panic on mixed-width keys.
Details and comments
marginal_counts(Counts({"0x0": 50, "0x3": 30}), [0])now returns{"0": 50, "1": 30}.marginal_distribution(..., [1])now handles the same input instead of panicking in the Rust helper.Testing
python -X utf8 -m unittest test.python.result.test_counts.TestCounts.test_marginal_counts_mixed_width_hex_without_memory_slots test.python.result.test_counts.TestCounts.test_marginal_distribution_mixed_width_hex_without_memory_slotspython -X utf8 -m unittest test.python.result.test_countspython -X utf8 -m unittest test.python.result.test_result.TestResultOperations.test_marginal_counts test.python.result.test_result.TestResultOperations.test_marginal_distribution test.python.result.test_result.TestResultOperations.test_marginal_counts_result test.python.result.test_result.TestResultOperations.test_marginal_counts_with_dict test.python.result.test_result.TestResultOperationsFailed.test_marginal_counts_no_cregspython -X utf8 -m unittest discover -s test/python/result -p 'test_*.py'cargo test -p qiskit-accelerate --libcargo fmt --checkblack --check qiskit/result/utils.py test/python/result/test_counts.pyruff check qiskit/result/utils.py test/python/result/test_counts.pyreno lintAI/LLM disclosure