示例#1
0
def test_compile_label():
    prog = qf.Program()
    prog += qf.Label('Here')
    prog += qf.Nop()
    prog += qf.Label('There')

    ket = prog.run()

    assert ket.memory[TARGETS] == {'Here': 0, 'There': 2}
示例#2
0
def test_measure_until():

    prog = qf.Program()
    prog += qf.TRUE(('c', 2))
    prog += qf.Label('redo')
    prog += qf.Call('X', [], [0])
    prog += qf.Call('H', [], [0])
    prog += qf.Measure(0, ('c', 2))
    prog += qf.JumpUnless('redo', ('c', 2))

    ket = prog.run()
    assert ket.memory[('c', 2)] == 1
示例#3
0
def test_jump():
    ro = qf.Register()
    prog = qf.Program()
    prog += qf.FALSE(ro[0])
    prog += qf.Jump('There')
    prog += qf.Not(ro[0])
    prog += qf.Label('There')
    prog += qf.Not(ro[0])
    ket = prog.run()
    assert ket.memory[ro[0]] == 1

    prog += qf.JumpWhen('There', ro[0])
    ket = prog.run()
    assert ket.memory[ro[0]] == 0

    prog += qf.Not(ro[0])
    prog += qf.JumpUnless('There', ro[0])
    ket = prog.run()
    assert ket.memory[ro[0]] == 1
示例#4
0
def test_jumps2():
    _test("LABEL @test_1", qf.Label("test_1"))
    _test("JUMP @test_1", qf.Jump("test_1"))
    cb = qf.Register('cb')
    _test("JUMP-WHEN @test_1 cb[0]", qf.JumpWhen("test_1", cb[0]))
    _test("JUMP-UNLESS @test_1 cb[1]", qf.JumpUnless("test_1", cb[1]))