Skip to content

Commit

Permalink
Remove HALT from valid protoquil and supported quil instructions (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Davis authored Feb 25, 2020
1 parent 17c6fb2 commit d45246d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Changelog

- Fixed the QCS access request link in the README (@amyfbrown, gh-1171).
- Fix the SDK download link and instructions in the docs (@amyfbrown, gh-1173).
- Removed HALT from valid Protoquil / supported Quil. (@kilimanjaro, gh-1176).

[v2.17](https://github.com/rigetti/pyquil/compare/v2.16.0...v2.17.0) (January 30, 2020)
---------------------------------------------------------------------------------------
Expand Down
13 changes: 4 additions & 9 deletions pyquil/quil.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
JumpUnless,
JumpWhen,
Declare,
Halt,
Reset,
ResetQubit,
DefPermutationGate,
Expand Down Expand Up @@ -609,8 +608,7 @@ def is_supported_on_qpu(self) -> bool:
"""
Whether the program can be compiled to the hardware to execute on a QPU. These Quil
programs are more restricted than Protoquil: for instance, RESET must be before any
gates or MEASUREs, MEASURE on a qubit must be after any gates on that qubit, and
no instructions can occur after HALT.
gates or MEASUREs, and MEASURE on a qubit must be after any gates on that qubit.
:return: True if the Program is supported Quil, False otherwise
"""
Expand Down Expand Up @@ -1109,7 +1107,7 @@ def validate_protoquil(program: Program) -> None:
:param program: The Quil program to validate.
"""
valid_instruction_types = tuple([Pragma, Declare, Halt, Gate, Reset, ResetQubit, Measurement])
valid_instruction_types = tuple([Pragma, Declare, Gate, Reset, ResetQubit, Measurement])
for instr in program.instructions:
if not isinstance(instr, valid_instruction_types):
# Instructions like MOVE, NOT, JUMP, JUMP-UNLESS will fail here
Expand All @@ -1120,18 +1118,15 @@ def validate_supported_quil(program: Program) -> None:
"""
Ensure that a program is supported Quil which can run on any QPU, otherwise raise a ValueError.
We support a global RESET before any gates, and MEASUREs on each qubit after any gates
on that qubit. PRAGMAs and DECLAREs are always allowed, and a final HALT instruction is allowed.
on that qubit. PRAGMAs and DECLAREs are always allowed.
:param program: The Quil program to validate.
"""
gates_seen = False
measured_qubits: Set[int] = set()
for i, instr in enumerate(program.instructions):
for instr in program.instructions:
if isinstance(instr, Pragma) or isinstance(instr, Declare):
continue
elif isinstance(instr, Halt):
if i != len(program.instructions) - 1:
raise ValueError(f"Cannot have instructions after HALT")
elif isinstance(instr, Gate):
gates_seen = True
if any(q.index in measured_qubits for q in instr.qubits):
Expand Down
2 changes: 0 additions & 2 deletions pyquil/tests/test_quil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,6 @@ def test_validate_supported_quil_suite():
CZ 2 3
MEASURE 2 ro[2]
MEASURE 3 ro[3]
HALT
"""
)
)
Expand All @@ -1252,7 +1251,6 @@ def test_validate_supported_quil_suite():
MEASURE 2 ro[2]
X 3
MEASURE 3 ro[3]
HALT
"""
)
)
Expand Down

0 comments on commit d45246d

Please sign in to comment.