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 make_data_bin() to return DataBin proper #12219

Merged
merged 15 commits into from
May 2, 2024

Conversation

ihincks
Copy link
Contributor

@ihincks ihincks commented Apr 19, 2024

Summary

This PR updates DataBin with the intention of making it easier to construct directly, avoiding the make_data_bin class.

I have concerns that this breaks the class because it drops support for positional arguments in the constructor, but am opening up the PR anyways. There's also no way to properly infer shape at instance construction time, but there is (as previously implemented) at dynamic type construction time.

Details and comments

This PR attempts to keep legacy support for a bunch of behaviour that is technically private, but that has become widespread due to lack of a way to achieve certain basic tasks (like find namespace names) in a simple way.

@ihincks ihincks added the mod: primitives Related to the Primitives module label Apr 19, 2024
@ihincks ihincks added this to the 1.1.0 milestone Apr 19, 2024
@ihincks ihincks requested review from a team as code owners April 19, 2024 03:34
@qiskit-bot
Copy link
Collaborator

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 Apr 19, 2024

Pull Request Test Coverage Report for Build 8923416015

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

  • 57 of 62 (91.94%) changed or added relevant lines in 6 files are covered.
  • 550 unchanged lines in 16 files lost coverage.
  • Overall coverage increased (+0.05%) to 89.551%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/primitives/base/base_estimator.py 1 2 50.0%
qiskit/primitives/containers/data_bin.py 49 53 92.45%
Files with Coverage Reduction New Missed Lines %
qiskit/converters/circuit_to_gate.py 1 97.44%
qiskit/circuit/controlflow/control_flow.py 1 92.86%
crates/qasm2/src/lex.rs 1 93.13%
qiskit/converters/circuit_to_instruction.py 1 98.28%
qiskit/circuit/library/blueprintcircuit.py 3 95.16%
qiskit/circuit/_classical_resource_map.py 6 90.67%
crates/qasm2/src/parse.rs 6 97.61%
qiskit/qasm3/ast.py 11 95.45%
qiskit/quantum_info/operators/operator.py 14 95.05%
qiskit/qasm3/exporter.py 17 95.87%
Totals Coverage Status
Change from base Build 8903133563: 0.05%
Covered Lines: 61615
Relevant Lines: 68804

💛 - Coveralls

@t-imamichi
Copy link
Member

t-imamichi commented Apr 19, 2024

Thank you for overhauling DataBin. It gets simpler now.
Do you plan to add mapping methods keys, values, items, etc. in #12129 ?
It can be done easily by calling self.__dict__.keys() for example.
If necessary, you can copy the tests from #12129. I don't mind closing #12129.

@ihincks
Copy link
Contributor Author

ihincks commented Apr 23, 2024

Yes, I plan to include the methods added in #12129. I'm hoping to merge 12129 first because it doesn't have any of the concerns that are mentioned in the summary of this PR.

Copy link
Member

@chriseclectic chriseclectic left a comment

Choose a reason for hiding this comment

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

Couple questions

qiskit/primitives/containers/data_bin.py Outdated Show resolved Hide resolved
shape = ",".join(map(str, cls._SHAPE))
return f"{name}<{shape}>"
class DataBin(metaclass=DataBinMeta):
"""Namespace for storing data.
Copy link
Member

@chriseclectic chriseclectic Apr 25, 2024

Choose a reason for hiding this comment

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

Should this inherit from Mapping now? Also its now both a namespace and a mapping container (just needs an iter to complete the mapping abc i think)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The iter already exists from a different PR. I'd like to control our own namespace, so I think I'm happy to be a mapping only via protocol.

qiskit/primitives/containers/data_bin.py Outdated Show resolved Hide resolved
qiskit/primitives/containers/data_bin.py Outdated Show resolved Hide resolved
@t-imamichi
Copy link
Member

Thank you for overhauling data bin. It looks good overall. Could you write a reno?

@t-imamichi
Copy link
Member

I noticed that we can simplify the code slightly. I wrote a suggestion ihincks#2.

@ihincks ihincks enabled auto-merge May 2, 2024 11:59
Copy link
Member

@t-imamichi t-imamichi left a comment

Choose a reason for hiding this comment

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

LGTM

@ihincks ihincks added this pull request to the merge queue May 2, 2024
Merged via the queue into Qiskit:main with commit 8ba7974 May 2, 2024
15 checks passed
@ihincks ihincks deleted the primitives/update-data_bin-type branch May 2, 2024 18:25
@sbrandhsn sbrandhsn added the Changelog: New Feature Include in the "Added" section of the changelog label May 8, 2024
ElePT pushed a commit to ElePT/qiskit that referenced this pull request May 31, 2024
* Update make_data_bin() to return DataBin proper

* Remove metaclass

I checked all of our repos and it's not used by anything

* fix implementations

* remove make_data_bin usage

* make the DataBin follow the Shaped protocol

* add it back to containers module (removed by accident)

* get implemntatinos to assign shape

* improve the repr

* add reno

* fix reno formatting

* improve error string

* use views instead of sequences

* fix tests

---------

Co-authored-by: Takashi Imamichi <imamichi@jp.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 mod: primitives Related to the Primitives module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants