Skip to content

Implementing visit_while_loop#206

Merged
TheGupta2012 merged 22 commits intoqBraid:mainfrom
bhagyasreey:add-while-loop-support
Jun 16, 2025
Merged

Implementing visit_while_loop#206
TheGupta2012 merged 22 commits intoqBraid:mainfrom
bhagyasreey:add-while-loop-support

Conversation

@bhagyasreey
Copy link
Copy Markdown
Contributor

@bhagyasreey bhagyasreey commented Jun 12, 2025

Fixes #7

Summary of changes

  1. _visit_while_loop Method
  • Implements logic to simulate execution of a while loop during AST traversal.
  • Supports break and continue control flow inside the loop body.
  • Uses a counter (loop_counter) to prevent infinite loops via a max_iterations threshold.
  • Evaluates the loop condition using Qasm3ExprEvaluator.evaluate_expression(...).
  1. LoopControlSignal Handling
  • Custom mechanism to simulate break and continue:
  • These are raised by statement visitors like visit_break and visit_continue.
  1. Loop Safety Mechanism
  • Hardcoded max_iterations (e.g., 1024) to avoid infinite loops.
  • Raises a custom exception like LoopLimitExceededError if the loop exceeds the limit.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 12, 2025

Codecov Report

❌ Patch coverage is 96.25000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pyqasm/analyzer.py 80.00% 3 Missing ⚠️

📢 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.

Hi @bhagyasreey , thanks for the work! I've reviewed and provided some suggestions for the code, could you please take a look?

@bhagyasreey
Copy link
Copy Markdown
Contributor Author

@TheGupta2012 could you please check the changes. Thank you.

@TheGupta2012
Copy link
Copy Markdown
Member

Hi, could you look into the tests failure please?

@bhagyasreey
Copy link
Copy Markdown
Contributor Author

I fixed the issue. Could you please check it now.

@TheGupta2012 TheGupta2012 self-requested a review June 16, 2025 06:26
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.

LGTM

@TheGupta2012 TheGupta2012 merged commit 8b04215 into qBraid:main Jun 16, 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] Add support for while statements

3 participants