Skip to content

Feature/Added depth calculation for branching statements#200

Merged
TheGupta2012 merged 18 commits intoqBraid:mainfrom
vinayswamik:feature/update-branching-gate-depths
Jun 6, 2025
Merged

Feature/Added depth calculation for branching statements#200
TheGupta2012 merged 18 commits intoqBraid:mainfrom
vinayswamik:feature/update-branching-gate-depths

Conversation

@vinayswamik
Copy link
Copy Markdown
Collaborator

@vinayswamik vinayswamik commented May 31, 2025

Summary of changes

This PR addresses an issue in QasmVisitor where depth calculations for Gate and Measurement operations inside branching statements were being treated the same as non-conditional operations. As a result, both quantum and classical registers were not reflecting the correct depth, leading to inaccurate circuit-depth.

With this change, we introduce logic to:

  • Detect when we are inside a branching statement (e.g., if or else): we set a flag at the start of QasmVisitor.
  • Suspend immediate depth updates for all basic gates, custom gates, and measurements while inside the branch. Instead, we collect (and deduplicate) a set of all affected depth nodes (both quantum‐ and classical‐bit nodes) during the entire recursive traversal of that branch.
  • Treat the entire branching block as a single depth increase.
  • After exiting the branching block, take the maximum depth among all collected nodes and raise each one to “one step above” that maximum. In effect, this synchronizes every qubit and clbit participating in the conditional arguments to the correct final depth.

Closes #53

@vinayswamik vinayswamik requested a review from TheGupta2012 as a code owner May 31, 2025 07:26
@vinayswamik vinayswamik changed the title Feature/Added branching statements depth calculation Feature/Added depth calculation branching statements May 31, 2025
@vinayswamik vinayswamik changed the title Feature/Added depth calculation branching statements Feature/Added depth calculation for branching statements May 31, 2025
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Member

@TheGupta2012 TheGupta2012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @vinayswamik , thanks for working on this! Giving a preliminary review right now, but the code looks good!

Please add some more tests whenever you get time

@vinayswamik
Copy link
Copy Markdown
Collaborator Author

Hey @vinayswamik , thanks for working on this! Giving a preliminary review right now, but the code looks good!

Please add some more tests whenever you get time

Thanks for the review 👍,
Sure I will add few more test cases and lyk

@vinayswamik vinayswamik requested a review from TheGupta2012 June 1, 2025 04:20
remove the skip test
@TheGupta2012
Copy link
Copy Markdown
Member

Changes lgtm @vinayswamik ! Can you please also add a CHANGELOG.md entry ? It will be good if you can specify an example program there. Post that, we can merge.

Thanks for working on this!

Added new test case for the external gates inside branching statements. New code (line: 974 to 979 under _visit_custom_gate_operation in visitor.py never ran under the previous test suite.
@vinayswamik
Copy link
Copy Markdown
Collaborator Author

Changes lgtm @vinayswamik ! Can you please also add a CHANGELOG.md entry ? It will be good if you can specify an example program there. Post that, we can merge.

Thanks for working on this!

Thanks for your support @TheGupta2012. I have update the CHANGELOG.md and added one new test case to cover external gate depth inside branching statements. Let me know if any changes are needed.

@vinayswamik vinayswamik requested a review from TheGupta2012 June 6, 2025 00:21
Copy link
Copy Markdown
Member

@TheGupta2012 TheGupta2012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to merge

@TheGupta2012 TheGupta2012 merged commit e7b0eb6 into qBraid:main Jun 6, 2025
20 checks passed
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.

[FEATURE] Update the depth calculation to include branching operations with classical registers

3 participants