Skip to content

Implementing visit_while_loop #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 16, 2025

Conversation

bhagyasreey
Copy link
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

codecov-commenter commented Jun 12, 2025

Codecov Report

Attention: 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
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
Contributor Author

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

@TheGupta2012
Copy link
Member

Hi, could you look into the tests failure please?

@bhagyasreey
Copy link
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
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