Skip to content

Conversation

@TheGupta2012
Copy link
Member

@TheGupta2012 TheGupta2012 commented Oct 29, 2025

Summary of changes

  • Added qasm3_ast.DelayInstruction to the list of recognized AST nodes in the QASM2 module initializer, enabling parsing and handling of delay instructions.

@AndreiCod | #274

  • For the delay instructions in OPENQASM 2;, following syntax can be used -
OPENQASM 2.0;
qreg q[2];
delay[10.0ns] q[0];

I would recommend switching to qasm3 as delay is not supported natively in the grammar of qasm2.

  • Note :
    • opaque is not supported in the openqasm3 parser and since the AST of pyqasm is based off of it, the parsing of the opaque instructions fail. Moreover, opaque delay results in a parsing error as delay is a reserved keyword in the openqasm3 parser.
    • One alternative to supporting opaque instructions is the external_gates kwarg which we provide in the unroll method.
    • You can define the gate skeleton , e.g. -
gate external_gate (param0, param1) qubit0, qubit1 { } // empty body 

and specify the name in the external_gates list. This will instruct the pyqasm unroller to skip the gate unrolling and just validate the parameters and arguments against the provided gate definition. Full example -

from pyqasm import loads

qasm_str = """
OPENQASM 2.0;
gate custom_ext_gate(p0) q0 { } 
qreg q[2];
custom_ext_gate(0) q[0];
"""

module = loads(qasm_str)
module.unroll(external_gates = ['custom_ext_gate'])
print(module)

"""OPENQASM 2.0;
qreg q[2];
custom_ext_gate(0) q[0];"""

@TheGupta2012
Copy link
Member Author

@copilot add a brief changelog entry according to the changelog format

Copy link

Copilot AI commented Oct 29, 2025

@TheGupta2012 I've opened a new pull request, #276, to work on those changes. Once the pull request is ready, I'll request review from you.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TheGupta2012
Copy link
Member Author

Closing this as the delay change introduces a syntactically incorrect delay[<<time>>] <<qubit>>; instruction which wasn't supported in the qasm2 grammar

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.

3 participants