-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
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.
One or more of the following people are relevant to this code:
|
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Pull Request Test Coverage Report for Build 10940047614Details
💛 - Coveralls |
Summary
We previously exposed the data attribute
STDGATES_INC_GATES
, but its contents are allCustomGate
, 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.