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

Make qasm3.CustomGate accessible from Python space #13187

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

jakelishman
Copy link
Member

Summary

We previously exposed the data attribute STDGATES_INC_GATES, but its contents are all CustomGate, which can't be inspected programmatically from Python space. This makes it so you can query what the gates, their number of parameters, and how to construct them.

Details and comments

From a feature request in #13061.

We previously exposed the data attribute `STDGATES_INC_GATES`, but its
contents are all `CustomGate`, which can't be inspected programmatically
from Python space.  This makes it so you can query _what_ the gates,
their number of parameters, and how to construct them.
@jakelishman jakelishman added Changelog: New Feature Include in the "Added" section of the changelog mod: qasm3 Related to OpenQASM 3 import or export labels Sep 19, 2024
@jakelishman jakelishman added this to the 1.3.0 milestone Sep 19, 2024
@jakelishman jakelishman requested a review from a team as a code owner September 19, 2024 11:27
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core
  • @kevinhartman
  • @mtreinish

Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

Looks straightforward enough :)

module = "qiskit._accelerate.qasm3",
frozen,
name = "CustomGate",
get_all
Copy link
Contributor

Choose a reason for hiding this comment

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

So get_all just adds getters for all attributes? Handy.

Copy link
Member Author

Choose a reason for hiding this comment

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

It does, though I'm kind of trying it out to see if I like it. It feels a bit easy to accidentally encode poor access patterns with it - this PR already isn't ideal, since it directly exposes a Rust String, which means all access to gate.name will need to allocate a new Python str. Unlikely to matter, but when it's not annotated directly on the member, I think it's easier to write non-ideal behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I also see how this could easily lead to slip-ups (for example if someone added a new member and didn't notice the "blanket" getter). In this case I don't think it would be too bad but you can let me know if you want to change it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine to just leave it if you're happy - this is a super simple dataclass-like thing anyway.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 10940047614

Details

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • 9 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.006%) to 88.834%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 9 91.73%
Totals Coverage Status
Change from base Build 10931978471: -0.006%
Covered Lines: 73490
Relevant Lines: 82727

💛 - Coveralls

@jakelishman jakelishman added this pull request to the merge queue Sep 19, 2024
Merged via the queue into Qiskit:main with commit ece25b6 Sep 19, 2024
15 checks passed
@jakelishman jakelishman deleted the qasm3/public-custom-gate branch September 19, 2024 14:41
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: qasm3 Related to OpenQASM 3 import or export
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants