Skip to content
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

QASM support for singly-controlled ControlledGates. #215

Merged
merged 3 commits into from
Jan 25, 2024
Merged

Conversation

mtweiden
Copy link
Contributor

This PR adds support for outputting qasm of singly-controlled "standard" gates. Standard gates are those that have a defined qasm_name property.

Resolves #214

@mtweiden mtweiden requested a review from edyounis January 17, 2024 20:21
@edyounis
Copy link
Member

edyounis commented Jan 17, 2024

Thanks for being quick with this fix! A couple of changes: I would override Gate.qasm_name or add an attribute to the class _qasm_name. This is because you are not changing how the entire qasm line gets printed.

Looking at the decoding, the cu1, cu2, cu3, cswap, c3x, and c4x are all the standard qasm2 identitifers that are handled this way. Does your implementation catch the cswap, c3x, and c4x?

I do like that your implementation handles multiple controls on gates nicely, but I worry this will also create a situation where we can encode something we can decode, e.g. ControlledGate(XGate(), 5). As annoying and limiting as this sounds, I think we should just check for the standard qasm ids, and print a helpful (or annoying but more specific) error in other cases.

Thanks again for putting this up!

@mtweiden
Copy link
Contributor Author

This new version overrides the Gate.qasm_name property. There's a check now to ensure that only standard OpenQASM2.0 identifiers (or at least those in bqskit.ir.lang.qasm2.visitor.py) can be encoded.

@edyounis edyounis merged commit 9463f52 into main Jan 25, 2024
13 of 17 checks passed
@edyounis edyounis deleted the controlled-qasm branch January 25, 2024 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is it possible to get the QASM string representation of a BQSKit circuit?
2 participants