Skip to content

Commit

Permalink
Respond to CR
Browse files Browse the repository at this point in the history
  • Loading branch information
laurencap committed Aug 8, 2023
1 parent 95efe25 commit 3540278
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 19 deletions.
6 changes: 0 additions & 6 deletions src/braket/experimental/autoqasm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,12 @@ def _convert_program_as_main(
args (List[Any]): Arguments passed to the program when called.
kwargs (Dict[str, Any]): Keyword arguments passed to the program when called.
"""
program_conversion_context.in_main(True)

# Process the program
aq_transpiler.converted_call(f, args, kwargs, options=options)

# Modify program to add qubit declaration if necessary
_add_qubit_declaration(program_conversion_context)

program_conversion_context.in_main(False)


def _convert_program_as_subroutine(
f: Callable,
Expand All @@ -276,8 +272,6 @@ def _convert_program_as_subroutine(
args (List[Any]): Arguments passed to the program when called.
kwargs (Dict[str, Any]): Keyword arguments passed to the program when called.
"""
program_conversion_context.in_main(False)

oqpy_program = program_conversion_context.get_oqpy_program()

if f not in program_conversion_context.subroutines_processing:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
class ReturnValidator(converter.Base):
def visit_Return(self, node: ast.stmt) -> ast.stmt:
aq_context = program.get_program_conversion_context()
if aq_context.is_in_main and node.value is not None:
warnings.warn("`output` is currently unsupported; `return` statement has no effect.")
if not aq_context.subroutines_processing and node.value is not None:
warnings.warn("Return value from top level function is ignored.")
return node


Expand Down
10 changes: 0 additions & 10 deletions src/braket/experimental/autoqasm/program/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def __init__(self, user_config: Optional[UserConfig] = None):
self.return_variable = None
self._qubits_seen = set()
self._var_idx = 0
self._in_main = False

def make_program(self) -> Program:
"""Makes a Program object using the oqpy program from this conversion context.
Expand All @@ -108,15 +107,6 @@ def qubits(self) -> List[int]:
# Can be memoized or otherwise made more performant
return sorted(list(self._qubits_seen))

@property
def is_in_main(self) -> bool:
"""Whether the main block is currently being processed."""
return self._in_main

def in_main(self, in_main: bool) -> None:
"""Set context for processing the `main` block."""
self._in_main = in_main

def register_qubit(self, qubit: int) -> None:
"""Register a virtual qubit to use in this program."""
self._qubits_seen.add(qubit)
Expand Down
2 changes: 1 addition & 1 deletion test/unit_tests/braket/experimental/autoqasm/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ def test_main_return():
def main() -> int:
return 1

with pytest.warns(UserWarning, match="`output` is currently unsupported"):
with pytest.warns(UserWarning, match="Return value from top level function is ignored"):
main()


Expand Down

0 comments on commit 3540278

Please sign in to comment.