-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support for externally linked gates #182
base: main
Are you sure you want to change the base?
Conversation
Hi @Sola85! Thanks for your contributions and it looks like the changes are on the right track.
I'll have to confirm whether this is still required( as we are now fully unrolling the qasm ), but this was the motivation behind the code that you mentioned. This would require you to apply an
Besides this, I'll post any implementation specific comments in the diff. |
Thats what I had assumed the logic was for. I tried a gate like
Sounds good! Then I'll wait for the update. |
Hey, I've updated the pyqasm dependency to point to the latest release i.e. |
I added the same tests that I added in pyqasm (external u3 gate and external custom gates). The tests are currently failing in your pipeline because the pipeline doesn't know about my pyqir PR. Locally they pass. These new tests didn't fit into the existing |
I think the changes on this PR are fine. Should be good to go once |
Co-authored-by: Harshit Gupta <[email protected]>
This is the companion PR to qBraid/pyqasm#59 for externally linked gates, as suggested here #167.
This is probably not ready to merge, but I figured it's easier if I get some feedback first. With both changes, external gates work in qbraid-qir, at least for my use-case.
If both PRs are merged, one can call e.g.
qasm3_to_qir(qasm_str, external_gates=["mygate"])
.Then
pyqasm
does not unroll "mygate", but leaves it as a node in the AST.qbraid-qir
then takes this node and converts it to an externally linked qir function. There are serveral ways this could be done (@christian512 originally suggested that the user passes apyqir.Function
that the external gate should be mapped to, alternatively the user could potentially also just pass the name of the desired qir function that the gate should be mapped to). Instead for now I chose to create the new qir function dynamically based on the arguments of the original gate and with the fixed name__quantum__qis__<GateName>__body
, but this strategy could of course still be changed.With
qasm3_to_qir(qasm_str, external_gates=["mygate"])
, the following QASM would then be mapped to the IR below:The original
_visit_basic_gate_operation
had some logic where the gate was applied to multiple subsets of qubitswhich I did not replicate in
_visit_external_gate_operation
since I did not understand this logic and could not trigger its execution. This might be be something that still requires change.I also did not yet write any tests because most of the existing tests where failing due to import errors of
pyqasm.pyqasm
(I assume you are currently in the process of changing how pyqasm gets imported?). If the rest of this PR is good, I can look into this again and add tests for the external gates.Closes #167