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
Provide a mechanism for defining simulator-only implementations of callables designed to be intrinsic for code generation #1483
Comments
The linked PR is one possible approach, but we can use this issue to discuss alternatives! |
I'm a bit concerned that just one attribute makes distinction kind-of implicit. When we have two implementations for two different profiles, we see that there're two implementations. Would it be more explicit if we have to implementations - one spelled out and one intrinsic, and decorate those for use in different cases? |
I can see this to be helpful beyond code generation. Maybe the attribute could be |
The reason I lean toward keeping them in one has to do with how we compile. If I have two definitions of a callable with the same name in the same scope, it produces a duplicate definition error. The way that works with |
I debated on the naming in the naming quite a bit in the linked PR... I used |
Another option that is possible but would require some more work in updating the parser is to have it not be attribute based at all but rather extend the existing operation MyGate(q : Qubit) : Unit {
body intrinsic;
} and additionally support: operation MyGate(q : Qubit) : Unit {
body intrinsic {
// Put simulator-only implementation here.
}
} While that might be a neat syntactic trick, I don't think it's as descriptive as having an attribute which at least provides a string for the user to search for in docs. |
A few more points that have come up in discussion over the last week:
Given these two, I want to focus in on finding a good attribute name. Here's some we have brainstormed so far, would love to hear some more!
|
I don't have more suggestions. I think all of them are very descriptive, but |
@swernli I don't mind the attribute, but I will quibble with this... commenting out the I like FWIW I also like the idea of just reusing the |
Today, a user can provide an implementation (or decomposition) for an operation that they want to simulate and get that same implementation at code generation time (assuming it follows the restrictions for their chosen target) OR they can define the callable as
body intrinsic
and have it generated as an extern that must be supported by the chosen codegen target. If the user chooses the latter, they get their desired codegen behavior but cannot simulate their program, while the former works for simulation but may prevent QIR codegen or include undesired decomposition.Given that, it has come up across several discussions that it would be convenient to have a mechanism whereby users could denote a callable as intrinsic for the purpose of codegen but still provide an implementation that gets used during simulation. What form this takes and how it is used in the language are up for discussion, though one possible approach could be a specialized attribute that denotes a callable that should be treated this way.
The text was updated successfully, but these errors were encountered: