rigetti / pyquil

A Python library for quantum programming using Quil.
http://docs.rigetti.com
Apache License 2.0
1.39k stars 341 forks source link

Utility: apply num-shots loop directly to program Quil #1712

Closed kalzoo closed 5 months ago

kalzoo commented 7 months ago

(this may be better suited for implementation in https://github.com/rigetti/pyquil and then use here)

Currently, a program may be designated to execute with a shot count via program.wrap_in_numshots_loop(shots). This value is then sent as a request parameter alongside the program in the translation request.

There are use cases, though, where the user may prefer to directly control that shot-count loop within their own program, with a pattern like:

DECLARE loop_index INTEGER

@label shot-count-loop-start

# loop contents
SUB loop_index 1
JUMP-WHEN @shot-count-loop-start loop_index

The user's program could be wrapped with this loop using a function roughly like:

class Program:
    def apply_num_shots_loop_to_quil(self, variable: MemoryReference):
        # wrap program in the Quil above

        self.num_shots = 1