Beispiel #1
0
def test_grover():
    qc = mat_quantum_circuit([4, 2],
                             divisions=[1, 1],
                             name='Test grover',
                             show_amp=True)
    # qc.special_encoding( {0:'(FF)', 1:'(FT)', 2:'(TF)', 3:'(TT)'}, 0)

    had4 = ops.gates('hadamard', 4)
    qc.add_instruct(had4, [0])

    AND = ops.AND()
    AND.change_dims([4, 2])
    qc.add_instruct(AND)

    # directions = { (1,): ops.gates('flip') }
    cond_flip = ops.gates('flip')
    qc.add_instruct(cond_flip, [1])

    qc.add_instruct(AND)

    # qc.add_instruct(ops.one_shot_grover(),[0])
    # qc.add_instruct(ops.one_shot_grover(),[0])

    add4 = ops.arith([4], 0, 0)
    qc.add_instruct(add4, [0])
    qc.run()
Beispiel #2
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()
Beispiel #3
0
    def static_getSomeWhere(self, *args, **kw):
        """
        
        """
        andValues=list(args)
        for k, v in kw.items():
            if k not in ('order', 'limit', 'offset'):
                andValues.append(operators.EQ(operators.FIELD(k), v))
        andlen=len(andValues)
        if andlen > 1:
            daOp=operators.AND(*andValues)
        elif andlen==1:
            daOp=andValues[0]
        else:
            daOp=None
        sql=(daOp and daOp.asSQL()) or ''
        
        order=[]
        limit=0
        offset=0
        desc=0

        if kw.get('order'):
            if type(kw['order']) == types.StringType:
                order.append(kw['order'])
            else:
                order.extend(kw['order'])
        if kw.get('limit'):
            limit = kw['limit']
        if kw.get('offset'):
            offset = kw['offset']

        return self.getSQLWhere(sql, order=order, limit=limit, offset=offset)
Beispiel #4
0
 def static_getSomeWhere(self, *args, **kw):
     andValues = list(args)
     for k, v in kw.items():
         andValues.append(operators.EQ(operators.FIELD(k), v))
     andlen = len(andValues)
     if andlen > 1:
         daOp = operators.AND(*andValues)
     elif andlen == 1:
         daOp = andValues[0]
     else:
         daOp = None
     sql = (daOp and daOp.asSQL()) or ''
     return self.getSQLWhere(sql)
Beispiel #5
0
    def class_getSomeWhere(klass, *args, **kw):
        """ Retrieve some objects of this particular class.
        
        Allows you to use the operator objects in PyDO.operators to be
        able to use sql operators other than the implicit AND as
        used by the other static get methods.
        
        The **kw argument is the same as the other static get methods.
        The *args argument however allows you to combine operators to
        do operations like OR, NOT, LIKE, etc. For example, the following
        would get all rows where the last name field was LIKE Ingers%.
        
        obj.getSomeWhere(LIKE(FIELD('last_name'), ('Ingers%')))
        
        """
        kw = klass._convertKW(kw)
        andValues = list(args)
        for k, v in kw.items():
            if k not in ('order', 'offset', 'limit'):
                andValues.append(operators.EQ(operators.FIELD(k), v))
        andlen = len(andValues)
        if andlen > 1:
            daOp = operators.AND(*andValues)
        elif andlen == 1:
            daOp = andValues[0]
        else:
            daOp = None
        sql = (daOp and daOp.asSQL()) or ''

        order = []
        limit = 0
        offset = 0
        if kw.get('order'):
            if type(kw['order']) == types.StringType:
                order.append(kw['order'])
            else:
                order.extend(kw['order'])
        if kw.get('limit'):
            limit = kw['limit']
        if kw.get('offset'):
            offset = kw['offset']

        return klass.getSQLWhere(sql, order=order, limit=limit, offset=offset)
Beispiel #6
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()