Skip to content

Fix: Error in circuit visualization of decomposable gates#210

Merged
ryanhill1 merged 3 commits intoqBraid:mainfrom
vinayswamik:bug/resolving-bugs
Jun 19, 2025
Merged

Fix: Error in circuit visualization of decomposable gates#210
ryanhill1 merged 3 commits intoqBraid:mainfrom
vinayswamik:bug/resolving-bugs

Conversation

@vinayswamik
Copy link
Copy Markdown
Collaborator

Fixes #209

Summary of changes

  • This fix makes axes handling more robust by first checking whether axis is a numpy array and, if so, converting it into a flat list of Axes objects.
  • If axis is a single instance, it’s wrapped in a list to ensure consistency. Finally, if axis is already a list of Axes, it’s left unchanged.
  • This guarantees that downstream code always works with a proper list of Axes objects, regardless of the number of subplots.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@TheGupta2012
Copy link
Copy Markdown
Member

Thanks for fixing this @vinayswamik ! While testing out the code I see that the gates are unrolled by default -

from pyqasm import loads
from pyqasm.printer import mpl_draw

qasm = """
    OPENQASM 3.0;
    qubit[2] q1;
    qreg q[3];
    creg c[3];
    ccx q[0], q[1], q1[0];
    crx (0.1) q[0], q[1];
    rccx q[0], q[1], q1[0];
    cz q[0], q[1];
    """
circ = loads(qasm)
mpl_draw(circ, filename = 'test.png')

image

Can you see why this is happening? Ideally we should represent the gates as is, unless an unroll is called internally

@vinayswamik
Copy link
Copy Markdown
Collaborator Author

vinayswamik commented Jun 18, 2025

The reason is program.unroll() is calling in the beginning of mpl_draw function.

@TheGupta2012
Copy link
Copy Markdown
Member

Hmm, ideally it should be validate as we don't wanna change the representation unless the user triggers an unroll command.

@vinayswamik
Copy link
Copy Markdown
Collaborator Author

Hmm, ideally it should be validate as we don't wanna change the representation unless the user triggers an unroll command.

That's true. actually we can open it as new issue.
lmk or else we can start refactor from here.

@TheGupta2012
Copy link
Copy Markdown
Member

Let's move that into a separate issue as current changes look fine to me

@TheGupta2012
Copy link
Copy Markdown
Member

Can you also add a CHANGELOG entry? I know we tend to forget that (including myself!) but trying to make that into a habit here. Should be good to merge post that.

@ryanhill1
Copy link
Copy Markdown
Member

ryanhill1 commented Jun 19, 2025

Regarding changelog reminders, we can also port over this workflow from qBraid-SDK: https://github.com/qBraid/qBraid/blob/main/.github/workflows/pr-compliance.yml

@vinayswamik vinayswamik force-pushed the bug/resolving-bugs branch 2 times, most recently from aafee7c to 8415c0c Compare June 19, 2025 18:14
- Added import for numpy to handle axes flattening.
- Updated axes handling to support both numpy arrays and plt.Axes instances, ensuring compatibility with different subplot configurations.
- Introduced a new test case `test_draw_qasm3_decomposable_gate` to validate the drawing of a decomposable gate in QASM 3.0.
@ryanhill1 ryanhill1 merged commit d7a5659 into qBraid:main Jun 19, 2025
20 checks passed
@vinayswamik vinayswamik deleted the bug/resolving-bugs branch June 22, 2025 17:45
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.

[BUG] Error in circuit visualization with decomposable gates

4 participants