Skip to content

Conversation

@TheGupta2012
Copy link
Member

@TheGupta2012 TheGupta2012 commented Jul 16, 2025

Fixes #230

Summary of changes

  • Introduced a new ScopeManager class to handle variable scopes and contexts, including methods for pushing/popping scopes, checking variable visibility, and updating variable values. (src/pyqasm/scope_manager.py)
  • Updated the QasmVisitor class to use the ScopeManager for all scope-related operations, replacing its internal scope and context management logic. (src/pyqasm/visitor.py) [1] [2] [3]
  • Fix alias bug
  • Refactor scoping methods

@codecov-commenter
Copy link

codecov-commenter commented Jul 17, 2025

Codecov Report

Attention: Patch coverage is 91.46919% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pyqasm/scope.py 85.95% 17 Missing ⚠️
src/pyqasm/visitor.py 98.64% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a dedicated ScopeManager to centralize variable scope and context handling, and refactors the existing QasmVisitor to delegate all scope operations to it. Key changes include:

  • Addition of ScopeManager class with push/pop scope and context methods.
  • Refactoring of QasmVisitor, transformer.py, and subroutines.py to replace in-class scope logic with calls to ScopeManager.
  • Updates to Variable model, tests, module instantiation, and changelog to support the new scoping system.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/pyqasm/scope.py New ScopeManager class for managing variable scopes/contexts.
src/pyqasm/visitor.py Replaced inline scope logic with ScopeManager calls.
src/pyqasm/transformer.py Updated to use ScopeManager in transform_function_qubits.
src/pyqasm/subroutines.py Refactored subroutine argument checks to use ScopeManager.
src/pyqasm/elements.py Extended Variable dataclass with shadow, is_alias, is_qubit.
src/pyqasm/expressions.py Switched to scope_manager methods for scope checks.
src/pyqasm/modules/base.py Now instantiates QasmVisitor with a ScopeManager.
src/pyqasm/init.py Documented LoopLimitExceededError in autosummary.
CHANGELOG.md Added entry for scoping refactor.
tests/qasm3/test_alias.py Updated expected error message after scope refactor.
tests/qasm3/subroutines/test_subroutines.py Renamed test parameters and added a skipped test for qubit renaming.
Comments suppressed due to low confidence (3)

src/pyqasm/elements.py:95

  • The docstring refers to is_register, but the attribute was renamed to is_qubit. Update the docstring to match the new attribute name.
        is_register (bool): Flag indicating if the variable is a register.

tests/qasm3/subroutines/test_subroutines.py:303

  • [nitpick] This test is marked as skipped, creating a coverage gap for the qubit renaming behavior. Instead of skipping, consider fixing the underlying bug or adding a TODO and tracking in an issue so the test can run against the intended behavior.
@pytest.mark.skip(reason="Bug: qubit in function scope conflicts with global scope")

src/pyqasm/init.py:48

  • The autosummary lists LoopLimitExceededError but it is not imported in this module; add from pyqasm.exceptions import LoopLimitExceededError or remove it from the summary to prevent documentation build errors.
   LoopLimitExceededError

@TheGupta2012 TheGupta2012 merged commit 30e03f2 into main Jul 18, 2025
1 check 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] Introduce a ScopeManager in pyqasm

3 participants