Skip to content
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

Update BitArray.get_counts() to support zero classical registers #12317

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

atharva-satpute
Copy link
Contributor

@atharva-satpute atharva-satpute commented May 1, 2024

Summary

Fixes #12062
Added support for zero classical registers in BitArray.get_counts(), BitArray.get_int_counts() and BitArray.get_bitstring()

Details and comments

  1. With this change, if BitArray is initialised with zero classical registers it will return {'': <count>} for get_counts() and {0: <count>} for get_int_counts()
  2. Noticed a case where loc is not None and arr is a number (arr = self._array[loc]), this would throw a TypeError on line, to handle this converted arr to np.array and along with this, checking arr.size == 0 in case get_bitstring()

@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label May 1, 2024
@atharva-satpute atharva-satpute marked this pull request as ready for review May 1, 2024 10:10
@atharva-satpute atharva-satpute requested review from a team as code owners May 1, 2024 10:10
@qiskit-bot
Copy link
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 the following people are requested to review this:

  • @Qiskit/terra-core
  • @ajavadia
  • @levbishop
  • @t-imamichi

@coveralls
Copy link

coveralls commented May 1, 2024

Pull Request Test Coverage Report for Build 8979374846

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • 781 unchanged lines in 42 files lost coverage.
  • Overall coverage increased (+0.1%) to 89.638%

Files with Coverage Reduction New Missed Lines %
qiskit/converters/circuit_to_gate.py 1 97.44%
qiskit/circuit/classical/expr/constructors.py 1 91.82%
qiskit/primitives/backend_estimator_v2.py 1 98.29%
qiskit/circuit/controlflow/control_flow.py 1 92.86%
qiskit/transpiler/passes/layout/apply_layout.py 1 98.25%
qiskit/primitives/statevector_sampler.py 1 99.08%
qiskit/circuit/store.py 1 94.44%
crates/accelerate/src/sabre/mod.rs 1 75.0%
qiskit/converters/circuit_to_instruction.py 1 98.28%
qiskit/circuit/classical/expr/expr.py 1 93.51%
Totals Coverage Status
Change from base Build 8910124709: 0.1%
Covered Lines: 62256
Relevant Lines: 69453

💛 - Coveralls

@t-imamichi t-imamichi self-requested a review May 1, 2024 13:11
@t-imamichi t-imamichi assigned ihincks and unassigned ihincks May 1, 2024
@t-imamichi t-imamichi requested a review from ihincks May 1, 2024 13:11
@atharva-satpute atharva-satpute force-pushed the getcount_empty_classical_reg branch 2 times, most recently from 511b5c7 to 1324a5d Compare May 1, 2024 13:51
@ihincks ihincks added the mod: primitives Related to the Primitives module label May 1, 2024
@ihincks
Copy link
Contributor

ihincks commented May 2, 2024

Thanks for taking this on @atharva-satpute . I think we will also need to make sure that from_bitstrings, from_int also support the num_bits=0 case, because I suspect that they don't right now.

@atharva-satpute
Copy link
Contributor Author

Sure

@ewinston ewinston self-assigned this May 15, 2024
@ewinston
Copy link
Contributor

@ihincks It seems BitString doesn't support from_bitstrings or from_int. The only reference I see to from_bitstrings is in the documentation of the DataBin class.

However, @atharva-satpute , I think it should probably support from_mapping({'', 1024})

@atharva-satpute
Copy link
Contributor Author

What would from_mapping() method do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PR PRs from contributors that are not 'members' of the Qiskit repo mod: primitives Related to the Primitives module
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

BitArray.get_counts() fails given an empty classical register
5 participants