コード例 #1
0
    def while_do(self, classical_reg, q_program):
        """
        While a classical register at index classical_reg is 1, loop q_program

        Equivalent to the following construction:

        .. code::

            WHILE [c]:
               instr...
            =>
              LABEL @START
              JUMP-UNLESS @END [c]
              instr...
              JUMP @START
              LABEL @END

        :param int classical_reg: The classical register to check
        :param Program q_program: The Quil program to loop.
        :return: The Quil Program with the loop instructions added.
        :rtype: Program
        """
        label_start = LabelPlaceholder("START")
        label_end = LabelPlaceholder("END")
        self.inst(JumpTarget(label_start))
        self.inst(JumpUnless(target=label_end, condition=classical_reg))
        self.inst(q_program)
        self.inst(Jump(label_start))
        self.inst(JumpTarget(label_end))
        return self
コード例 #2
0
ファイル: test_parser.py プロジェクト: vishalbelsare/pyquil
def test_jumps():
    parse_equals("LABEL @test_1", JumpTarget(Label("test_1")))
    parse_equals("JUMP @test_1", Jump(Label("test_1")))
    parse_equals("JUMP-WHEN @test_1 ro[0]",
                 JumpWhen(Label("test_1"), MemoryReference("ro", 0)))
    parse_equals("JUMP-UNLESS @test_1 ro[1]",
                 JumpUnless(Label("test_1"), MemoryReference("ro", 1)))
コード例 #3
0
ファイル: parser.py プロジェクト: vishalbelsare/pyquil
 def jump_unless(self, label, address):
     return JumpUnless(label, address)
コード例 #4
0
def test_jumps():
    parse_equals("LABEL @test_1", JumpTarget(Label("test_1")))
    parse_equals("JUMP @test_1", Jump(Label("test_1")))
    parse_equals("JUMP-WHEN @test_1 ro[0]", JumpWhen(Label("test_1"), Addr(0)))
    parse_equals("JUMP-UNLESS @test_1 ro[1]",
                 JumpUnless(Label("test_1"), Addr(1)))
コード例 #5
0
ファイル: PyQuilListener.py プロジェクト: greenstick/pyquil
 def exitJumpUnless(self, ctx):
     # type: (QuilParser.JumpUnlessContext) -> None
     self.result.append(JumpUnless(_label(ctx.label()), _addr(ctx.addr())))
コード例 #6
0
ファイル: test_parser.py プロジェクト: xoxoaseka/pyquil
def test_jumps():
    _test("LABEL @test_1", JumpTarget(Label("test_1")))
    _test("JUMP @test_1", Jump(Label("test_1")))
    _test("JUMP-WHEN @test_1 [0]", JumpWhen(Label("test_1"), Addr(0)))
    _test("JUMP-UNLESS @test_1 [1]", JumpUnless(Label("test_1"), Addr(1)))