Support for externally linked gates#182
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 <harshit.11235@gmail.com>
|
Hi @Sola85 ! We have recently released the pre-release version Can you update the code for using that dependency and see if the tests pass? |
|
@TheGupta2012 thanks for letting me know! I've updated the dependency and fixed the pipelines. One of the tests had failed due to |
|
Yea that's a case we'll need to handle separately. I'll open up an issue for that here but otherwise changes are good, thanks a lot!! |
|
Opened issue #188 for following up on |
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
pyqasmdoes not unroll "mygate", but leaves it as a node in the AST.qbraid-qirthen 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.Functionthat 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_operationhad some logic where the gate was applied to multiple subsets of qubitswhich I did not replicate in
_visit_external_gate_operationsince 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