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

ObservablesArray docstring improvement #13423

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

Conversation

gadial
Copy link
Contributor

@gadial gadial commented Nov 12, 2024

Summary

Expands the docstring of ObservablesArray.tolist to make it clear it might return a scalar in the case the observables array is of dimension 0.

Fixes #13402.

Details and comments

ObservablesArray.tolist is based on numpy's tolist method which returns a list with nesting level equal to the dimension of the numpy array being converted. When an observable array is initialized using a single observable (as opposed to a list containing a single observable) the internal representation of the array will be as a dimension 0 numpy array, resulting on a somewhat confusing return value:

>>> from qiskit.primitives.containers.observables_array import ObservablesArray
>>> oa = ObservablesArray.coerce(["Z"])
>>> print(type(oa.tolist()))
<class 'list'>
>>> oa = ObservablesArray.coerce("Z")
>>> print(type(oa.tolist()))
<class 'dict'>

This PR clarifies the issue in the method's docstring.

@gadial gadial requested review from a team as code owners November 12, 2024 09:36
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

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

@coveralls
Copy link

Pull Request Test Coverage Report for Build 11794527861

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 6 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.002%) to 88.933%

Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/unitary_synthesis.rs 1 92.2%
crates/qasm2/src/lex.rs 5 92.23%
Totals Coverage Status
Change from base Build 11784569909: -0.002%
Covered Lines: 79063
Relevant Lines: 88902

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ObservablesArray tolist() doesn't return list
3 participants