8000 New methods in `ObservablesArray`: `sparse_observables_array` and `sparse_observables_array_slice` by yaelbh · Pull Request #14344 · Qiskit/qiskit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

New methods in ObservablesArray: sparse_observables_array and sparse_observables_array_slice #14344

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

Merged
merged 43 commits into from
May 20, 2025

Conversation

yaelbh
Copy link
Contributor
@yaelbh yaelbh commented May 11, 2025

Summary

This is the last PR for completion of #14129.

Details and comments

In addition to the new methods, I changed the type hints of __getitem__ and enhanced its tests. The type hints are still not fully accurate, since they don't cover tuple[()] (as in arr[()]), but I don't want to make them more cumbersome.

yaelbh and others added 27 commits April 30, 2025 09:47
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
@yaelbh yaelbh requested review from a team as code owners May 11, 2025 13:14
@qiskit-bot
Copy link
Collaborator

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

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

@yaelbh yaelbh requested a review from ihincks May 11, 2025 17:54
Copy link
Contributor
@ihincks ihincks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yaelbh !!

yaelbh and others added 7 commits May 12, 2025 07:11
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
@yaelbh yaelbh changed the title New methods in ObservablesArray: get_sparse_observable and sparse_observables_array New methods in ObservablesArray: sparse_observables_array and sparse_observables_array_slice May 12, 2025
@yaelbh yaelbh requested a review from ihincks May 12, 2025 17:42
ihincks
ihincks previously approved these changes May 12, 2025
@yaelbh yaelbh requested a review from ihincks May 15, 2025 15:44
obs = self.copy() if copy else self
return obs._array

IndexType = Union[int, slice, None] # pylint: disable=used-before-assignment
Copy link
Contributor
@ihincks ihincks May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently in the namespace of the ObservablesArray (as ObservablesArray.IndexType). I would move it to the module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by moving it to the class?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that was a typo, fixed. I mean moving it out of the class, into the module.

@yaelbh yaelbh enabled auto-merge May 20, 2025 20:12
@yaelbh yaelbh added this pull request to the merge queue May 20, 2025
Merged via the queue into Qiskit:main with commit 31c12d8 May 20, 2025
24 checks passed
velocityraptor7085 pushed a commit to velocityraptor7085/qiskit that referenced this pull request May 22, 2025
…arse_observables_array_slice` (Qiskit#14344)

* added SparseObservable to ObservableLike

* wrote apply_layout

* wrote test_equivalent

* more layout tests

* black

* lint

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* create the zero observable outside of a loop

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* don't import unused List

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* setting validate=False in a reliable creation of an ObervablesArray object

* black

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* fixing doc string

* defer apply_layout checks to SparseObservable

* lint

* wrote get_sparse_observable

* wrote sparse_observables_array

* typo

* removed Ellipsis type because of CI failure

* release notes

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update releasenotes/notes/observables-array-7d7544b3bb3fbaa3.yaml

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update releasenotes/notes/observables-array-7d7544b3bb3fbaa3.yaml

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* renamed function

* black

* fixes

* shorten method name to 'slice'

* disable an erroneous lint error

* moving IndexType outside of obs-array class

---------

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@ibm.com>
@eliarbel eliarbel added the Changelog: New Feature Include in the "Added" section of the changelog label Jun 3, 2025
rahaman-quantum pushed a commit to rahaman-quantum/qiskit that referenced this pull request Jun 20, 2025
…arse_observables_array_slice` (Qiskit#14344)

* added SparseObservable to ObservableLike

* wrote apply_layout

* wrote test_equivalent

* more layout tests

* black

* lint

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* create the zero observable outside of a loop

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* don't import unused List

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* setting validate=False in a reliable creation of an ObervablesArray object

* black

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* fixing doc string

* defer apply_layout checks to SparseObservable

* lint

* wrote get_sparse_observable

* wrote sparse_observables_array

* typo

* removed Ellipsis type because of CI failure

* release notes

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update qiskit/primitives/containers/observables_array.py

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update releasenotes/notes/observables-array-7d7544b3bb3fbaa3.yaml

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* Update releasenotes/notes/observables-array-7d7544b3bb3fbaa3.yaml

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>

* renamed function

* black

* fixes

* shorten method name to 'slice'

* disable an erroneous lint error

* moving IndexType outside of obs-array class

---------

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0