示例#1
0
def test_logic():
    qc = mat_quantum_circuit([3, 3, 2, 2, 2],
                             divisions=[2, 2, 1],
                             name='Test AND')

    b = ops.branch(3)
    qc.add_instruct(b, [0])
    qc.add_instruct(b, [1])

    c32 = ops.copy32(0, 1)
    qc.add_instruct(c32, [0, 2])
    qc.add_instruct(c32, [1, 3])

    qc2 = copy.deepcopy(qc)
    qc2.name = 'Test OR'

    AND = ops.AND([0, 1], 2)
    qc.add_instruct(AND, [2, 3, 4])

    OR = ops.OR([0, 1], 2)
    qc2.add_instruct(OR, [2, 3, 4])

    qc.run()
    print('\n\n\n')
    print('*' * 80)
    print('\n\n\n')
    qc2.run()
示例#2
0
def test_idea2():
    qc = quantum_circuit([3, 3, 2, 2, 2, 2], [2, 2, 2], 'Test idea 2', True)
    qc.special_encoding('null', 0, 1)
    qc.special_encoding('TF', 2, 3)

    #1
    qc.instruct_notes('branch @ 0')
    qc.add_instruct(ops.branch(3), [0])

    #2
    qc.instruct_notes('|null> - |T> swap @ 1')
    swap = ops.swap(3, 0, 2)
    qc.add_instruct(swap, [1])

    #3
    qc.instruct_notes('Copy node info to ancillary memory')
    c32 = ops.copy32()
    apply_to = (0, 2), (1, 3)
    qc.add_instruct(ops.copy32(), *apply_to)

    #4
    qc.instruct_notes('evaluate node @ val')
    qc.add_instruct(ops.SAME(), [2, 3, 4])

    #5
    qc.instruct_notes('copy val to continue')
    qc.add_instruct(ops.gates('cnot'), [4, 5])

    #6
    qc.instruct_notes('CONTINUE CONTROL: load other node')
    # double_swap = ops.gate_concat(ops.swap(3, 2, 1), ops.gates('not'))
    dirs5 = {(0, ): ops.gates('not')}
    ctrl5 = ops.create_control([2, 2], 0, 1, dirs5)
    qc.add_instruct(ctrl5, [5, 3])

    #7
    qc.instruct_notes('CONTINUE CONTROL: evaluate node')
    dirs6 = {(0, ): ops.SAME()}
    ctrl6 = ops.create_control([2, 2, 2, 2], 0, [1, 2, 3], dirs6)
    qc.add_instruct(ctrl6, [5, 2, 3, 4])

    #8
    qc.instruct_notes('Uncopy continue control')
    qc.add_instruct(ops.gates('cnot'), [4, 5])

    #9
    qc.instruct_notes('PREPARE MERGE: unevaluate')
    qc.add_instruct(ops.SAME(), [2, 3, 4])

    # qc.instruct_notes('Move amplitudes up one node on the tree')
    # qc.add_instruct( swap, [1] )

    # #9
    # qc.instruct_notes('Unbranch @ 0')
    # qc.add_instruct( ops.branch(3), [0] )

    qc.run()
    qc.index_aide()
示例#3
0
def test_matrix_check():
    qc = mat_quantum_circuit([2, 3, 2], name='Test matrix check')

    g1 = ops.branch(3)
    qc.add_instruct(g1, [1])
    g2 = ops.goto_state(3)
    qc.add_instruct(g2, [1])

    qc.run()
示例#4
0
def test_diffusion(test=2):
    if test == 1:
        qc = mat_quantum_circuit([4, 4], show_amp=True)
        qc.write_state('10', '20', '30')

        gate1 = ops.goto_state(4, send=1)
        qc.add_instruct(gate1, [0])

        gate2 = ops.branch(4)
        qc.add_instruct(gate2, [1])

        qc.run()

    if test == 2:
        qc = mat_quantum_circuit([3], show_amp=True)
        qc.special_encoding('null', 0)

        b = ops.branch(3)
        qc.add_instruct(b)

        gt2 = ops.goto_state(3, 2)
        qc.add_instruct(gt2)

        qc.run()
示例#5
0
def test_idea():

    qc = quantum_circuit([3, 3, 2, 2, 2, 2, 2, 2],
                         divisions=[2, 3, 3],
                         name='Test idea',
                         show_amp=False)
    qc.special_encoding('null', 0, 1)
    qc.special_encoding('TF', 2, 3, 4)

    b = ops.branch(3)
    qc.add_instruct(b, [0])
    qc.add_instruct(b, [1])

    c32 = ops.copy32(0, 1)
    n32 = ops.not32(0, 1)

    qc.add_instruct(c32, [0, 2])
    qc.add_instruct(c32, [1, 4])
    qc.add_instruct(n32, [0, 3])

    fan = ops.fan_out(2, 0, 1)
    OR = ops.OR([0, 1], 2)
    AND = ops.AND([0, 1], 2)
    qc.add_instruct(fan, [2, 5])
    qc.add_instruct(OR, [3, 4, 6])
    qc.add_instruct(AND, [5, 6, 7])
    # now everything is evaluated

    # reset q5 and q6, use as goto control
    qc.add_instruct(fan, [2, 5])
    qc.add_instruct(OR, [3, 4, 6])

    # target |.F>
    directions = {(1, ): ops.gates('not')}
    ctrl = ops.create_control([2, 3], [1], 0, directions)
    flip_branch = qc.add_instruct(ctrl, [1, 5, 7])

    qc.run()
    qc.index_aide()