-
Notifications
You must be signed in to change notification settings - Fork 2
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 #59
Conversation
Hey, thanks for the changes! I've given some comments on this and the linked PR. The only change I see is making the acceptable |
Hey, @Sola85 just a heads up - we added some new commits to |
Hi @TheGupta2012, thanks for the feedback! I hadn't realized that pyqasm unrolls some gates into other gates and therefore I thought it didn't make sense to mark non-custom gates as external. With my last commit, it should be possible to mark any gate as external (I've added a test that tests this for the |
I agree, the unrolling of gates with multiple targets is not handled for custom operations. This is because of the assumption that any custom gate will eventually be broken down into simpler gates with either the user supplied definition or the one present in the We can have something like a |
Another thing to note is about the qubit depths. We recently added the support for calculating the Eg, if we are unrolling with an external gate OPENQASM 3.0;
qubit[3] q;
gate custom_1 a {
h a;
x a;
}
custom_1 q[0];
custom_1 q[1]; the final unrolled qasm would look like - OPENQASM 3.0;
qubit[3] q;
custom_1 q[0];
custom_1 q[1]; Inside the
In [16]: import pyqasm
In [17]: qasm_str = """
...: OPENQASM 3.0;
...: qubit[3] q;
...: gate custom_1 a {
...: h a;
...: x a;
...: }
...: custom_1 q[0];
...: custom_1 q[1];"""
In [18]: mod = pyqasm.load(qasm_str)
In [19]: mod.unroll(external_gates = ["custom_1"])
In [20]: mod.unrolled_qasm.splitlines()
Out[20]:
['OPENQASM 3.0;',
'include "stdgates.inc";',
'qubit[3] q;',
'custom_1 q[0];',
'custom_1 q[1];']
In [21]: mod.depth()
Out[21]: 2 This is incorrect as we want to get the depth of the current unrolled program and not unroll it yet again.
This might expand the scope a bit and I think for now you can add a test in |
Co-authored-by: Harshit Gupta <[email protected]>
Sync fork
Changes since my last comment:
I have not yet extended the broadcasting logic to custom gates i.e. something like gate mygate() _gate_q_0, {
h _gate_q_0;
}
qubit[2] q;
mygate() q; still does not work. But I think this is also not related to this PR and could be addressed separately |
Hi @Sola85 , thank you for the updates! Besides some minor suggestions, I think the changes look good. Should be good to merge soon. |
Thanks for working on this @Sola85 , the changes look good! |
Thanks for the feedback and thanks for merging! |
This is my preliminary PR for externally linked gates, as suggested here qBraid/qbraid-qir#167.
This is probably not ready to merge, but I figured it's easier if I get some feedback first. I will follow up with a PR for qbraid-qir shortly. With both changes, external gates work in qbraid-qir, at least for my use-case.
With this change
pyqasm
accepts a list of custom gates, that should not be unrolled into their definition.e.g. with
qasm3_module.unroll(external_gates=["mygate"])
, the following QASM would be unrolled into an AST that contains a "mygate" node, rather than the nodes in the definiton of "mygate".