Skip to content

Commit

Permalink
Add deprecation warning for tuple based initialization of instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
MarquessV committed Dec 14, 2023
1 parent a235834 commit f1bf468
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pyquil/quil.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ def inst(self, *instructions: Union[InstructionDesignator, RSProgram]) -> "Progr
Program { ... }
>>> p.inst(H(i) for i in range(4)) # A generator of instructions
Program { ... }
>>> p.inst(("H", 1)) # A tuple representing an instruction
Program { ... }
>>> p.inst("H 0") # A string representing an instruction
Program { ... }
>>> q = Program()
Expand All @@ -275,6 +273,13 @@ def inst(self, *instructions: Union[InstructionDesignator, RSProgram]) -> "Progr
elif isinstance(instruction, types.GeneratorType):
self.inst(*instruction)
elif isinstance(instruction, tuple):
warnings.warn(
"Adding instructions to a program by specifying them as tuples is deprecated. Consider building "
"the instruction you need using classes from the `pyquil.gates` or `pyquil.quilbase` modules and "
"passing those to Program.inst() instead.",
DeprecationWarning,
stacklevel=2,
)
if len(instruction) == 0:
raise ValueError("tuple should have at least one element")
elif len(instruction) == 1:
Expand Down

0 comments on commit f1bf468

Please sign in to comment.