Skip to content

Improve error reporting for pyqasm#171

Merged
TheGupta2012 merged 16 commits intomainfrom
fix-errors
Apr 21, 2025
Merged

Improve error reporting for pyqasm#171
TheGupta2012 merged 16 commits intomainfrom
fix-errors

Conversation

@TheGupta2012
Copy link
Copy Markdown
Member

@TheGupta2012 TheGupta2012 commented Apr 11, 2025

Summary of changes

  • Improve the error messages across the repository and reduce traceback size
  • Added a flag expand_traceback to validate and unroll commands. Set to False by default, it collapses the traceback to only display the last error msg. If set to True, full traceback displayed
  • Added exact lines for QASM errors, eg. -
import pyqasm
qasm = """
OPENQASM 3.0;
include "stdgates.inc";

def test(qubit[2] q2, int[32] b) -> bool{
    h q2[0];
    cx q2[0], q2[1];
    return true;
}
qubit[10] q;
bool b = test(a, 5);

"""
program = pyqasm.loads(qasm)
program.unroll(expand_traceback=0)

Output -

ERROR:pyqasm: Error at line 11, column 9 in QASM file

 >>>>>> test(a, 5)

pyqasm.exceptions.ValidationError: Expecting qubit argument for 'q2'. Qubit register 'a' not found for function 'test'
Usage: test ( qubit[2] q2 , int[32] b )

@TheGupta2012 TheGupta2012 marked this pull request as ready for review April 14, 2025 10:16
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 14, 2025

Codecov Report

Attention: Patch coverage is 97.24138% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pyqasm/exceptions.py 80.95% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@TheGupta2012 TheGupta2012 requested a review from ryanhill1 April 15, 2025 09:52
@TheGupta2012 TheGupta2012 requested a review from ryanhill1 April 17, 2025 09:39
ryanhill1
ryanhill1 previously approved these changes Apr 17, 2025
ryanhill1
ryanhill1 previously approved these changes Apr 18, 2025
@TheGupta2012 TheGupta2012 merged commit 86a15a0 into main Apr 21, 2025
@TheGupta2012 TheGupta2012 deleted the fix-errors branch May 26, 2025 06:46
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