Skip to content

Commit

Permalink
Explicitly disallow nested verbatim blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
rmshaffer committed Sep 11, 2023
1 parent 6181c09 commit 222c3cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/braket/experimental/autoqasm/program/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,12 @@ def verbatim_block(self) -> None:
"""Sets the program conversion context into a verbatim block context.
Raises:
errors.VerbatimBlockNotAllowed: If the target device does not support verbatim blocks.
errors.VerbatimBlockNotAllowed: If a verbatim block is not allowed at this point in
the program; for example, if the target device does not support verbatim blocks.
"""
if self._in_verbatim:
raise errors.VerbatimBlockNotAllowed("Verbatim blocks cannot be nested.")

device = self.get_target_device()
if (
device
Expand Down
11 changes: 11 additions & 0 deletions test/unit_tests/braket/experimental/autoqasm/test_pragmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def program_func() -> None:
assert program_func().to_ir() == expected


def test_nested_verbatim_box() -> None:
@aq.main
def program_func() -> None:
with aq.verbatim():
with aq.verbatim():
h(0)

with pytest.raises(errors.VerbatimBlockNotAllowed):
program_func()


def test_verbatim_box_invalid_target_qubit() -> None:
@aq.main
def program_func() -> None:
Expand Down

0 comments on commit 222c3cc

Please sign in to comment.