Пример #1
0
def inverterLoopTanh(numInverters, numSolutions="all", a=-5.0):
    epsilon = 1e-14
    start = time.time()
    vs = []
    for i in range(numInverters):
        vs.append(Variable("v" + str(i)))

    allConstraints = []

    # Store rambus oscillator constraints
    for i in range(numInverters):
        allConstraints.append(vs[i] >= -1)
        allConstraints.append(vs[i] <= 1)
        inputInd = i
        outputInd = (i + 1) % numInverters
        allConstraints.append(tanh(a * vs[inputInd]) - vs[outputInd] == 0.0)

    allSolutions = []
    while True:
        if numSolutions != "all" and len(allSolutions) == numSolutions:
            break

        # Store constraints pruning search space so that
        # old hyperrectangles are not considered
        excludingConstraints = []
        for solution in allSolutions:
            singleExcludingConstraints = []
            for i in range(numInverters):
                singleExcludingConstraints.append(vs[i] < solution[i][0])
                singleExcludingConstraints.append(vs[i] > solution[i][1])
            excludingConstraints.append(singleExcludingConstraints)

        # Add all the rambus oscillator constraints
        f_sat = logical_and(*allConstraints)
        # Add constraints so that old hyperrectangles are not considered
        if len(excludingConstraints) > 0:
            for constraints in excludingConstraints:
                f_sat = logical_and(f_sat, logical_or(*constraints))

        #print ("f_sat")
        #print (f_sat)
        result = CheckSatisfiability(f_sat, epsilon)
        #print (result)
        if result is None:
            break
        hyper = np.zeros((numInverters, 2))
        for i in range(numInverters):
            hyper[i, :] = [
                result[vs[i]].lb() - 2 * epsilon,
                result[vs[i]].ub() + 2 * epsilon
            ]

        #print ("hyper", hyper)
        allSolutions.append(hyper)

        print("num solutions found", len(allSolutions))

    end = time.time()
    print("time taken", end - start)
    return allSolutions
Пример #2
0
def inverterTanh(inputVoltage, a=-5.0, numSolutions="all"):
    epsilon = 1e-14
    start = time.time()

    outputVolt = Variable("outputVolt")

    allConstraints = []
    allConstraints.append(outputVolt >= -1.0)
    allConstraints.append(outputVolt <= 1.0)
    allConstraints.append(tanh(a * inputVoltage) - outputVolt == 0)

    allSolutions = []
    while True:
        if numSolutions != "all" and len(allSolutions) == numSolutions:
            break

        # Store constraints pruning search space so that
        # old hyperrectangles are not considered
        excludingConstraints = []
        for solution in allSolutions:
            singleExcludingConstraints = []
            singleExcludingConstraints.append(outputVolt < solution[0][0])
            singleExcludingConstraints.append(outputVolt > solution[0][1])
            excludingConstraints.append(singleExcludingConstraints)

        #print ("allConstraints")
        #print (allConstraints)
        f_sat = logical_and(*allConstraints)
        if len(excludingConstraints) > 0:
            for constraints in excludingConstraints:
                f_sat = logical_and(f_sat, logical_or(*constraints))

        #print ("f_sat")
        #print (f_sat)
        result = CheckSatisfiability(f_sat, epsilon)
        #print (result)
        if result is None:
            break
        hyper = np.zeros((1, 2))
        hyper[0, :] = [
            result[outputVolt].lb() - 2 * epsilon,
            result[outputVolt].ub() + 2 * epsilon
        ]

        #print ("hyper", hyper)
        allSolutions.append(hyper)

        print("num solutions found", len(allSolutions))

    end = time.time()
    print("time taken", end - start)
    return allSolutions
Пример #3
0
 def test_functions_with_expression(self):
     self.assertEqual(str(abs(e_x)), "abs(x)")
     self.assertEqual(str(exp(e_x)), "exp(x)")
     self.assertEqual(str(sqrt(e_x)), "sqrt(x)")
     self.assertEqual(str(pow(e_x, e_y)), "pow(x, y)")
     self.assertEqual(str(sin(e_x)), "sin(x)")
     self.assertEqual(str(cos(e_x)), "cos(x)")
     self.assertEqual(str(tan(e_x)), "tan(x)")
     self.assertEqual(str(asin(e_x)), "asin(x)")
     self.assertEqual(str(acos(e_x)), "acos(x)")
     self.assertEqual(str(atan(e_x)), "atan(x)")
     self.assertEqual(str(atan2(e_x, e_y)), "atan2(x, y)")
     self.assertEqual(str(sinh(e_x)), "sinh(x)")
     self.assertEqual(str(cosh(e_x)), "cosh(x)")
     self.assertEqual(str(tanh(e_x)), "tanh(x)")
     self.assertEqual(str(min(e_x, e_y)), "min(x, y)")
     self.assertEqual(str(max(e_x, e_y)), "max(x, y)")
     self.assertEqual(str(if_then_else(e_x > e_y, e_x, e_y)),
                      "(if (x > y) then x else y)")
Пример #4
0
 def test_functions_with_variable(self):
     self.assertEqual(str(abs(x)), "abs(x)")
     self.assertEqual(str(exp(x)), "exp(x)")
     self.assertEqual(str(sqrt(x)), "sqrt(x)")
     self.assertEqual(str(pow(x, y)), "pow(x, y)")
     self.assertEqual(str(sin(x)), "sin(x)")
     self.assertEqual(str(cos(x)), "cos(x)")
     self.assertEqual(str(tan(x)), "tan(x)")
     self.assertEqual(str(asin(x)), "asin(x)")
     self.assertEqual(str(acos(x)), "acos(x)")
     self.assertEqual(str(atan(x)), "atan(x)")
     self.assertEqual(str(atan2(x, y)), "atan2(x, y)")
     self.assertEqual(str(sinh(x)), "sinh(x)")
     self.assertEqual(str(cosh(x)), "cosh(x)")
     self.assertEqual(str(tanh(x)), "tanh(x)")
     self.assertEqual(str(min(x, y)), "min(x, y)")
     self.assertEqual(str(max(x, y)), "max(x, y)")
     self.assertEqual(str(if_then_else(x > y, x, y)),
                      "(if (x > y) then x else y)")
Пример #5
0
 def test_functions_with_float(self):
     v_x = 1.0
     v_y = 1.0
     self.assertEqual(abs(v_x), math.fabs(v_x))
     self.assertEqual(exp(v_x), math.exp(v_x))
     self.assertEqual(sqrt(v_x), math.sqrt(v_x))
     self.assertEqual(pow(v_x, v_y), v_x**v_y)
     self.assertEqual(sin(v_x), math.sin(v_x))
     self.assertEqual(cos(v_x), math.cos(v_x))
     self.assertEqual(tan(v_x), math.tan(v_x))
     self.assertEqual(asin(v_x), math.asin(v_x))
     self.assertEqual(acos(v_x), math.acos(v_x))
     self.assertEqual(atan(v_x), math.atan(v_x))
     self.assertEqual(atan2(v_x, v_y), math.atan2(v_x, v_y))
     self.assertEqual(sinh(v_x), math.sinh(v_x))
     self.assertEqual(cosh(v_x), math.cosh(v_x))
     self.assertEqual(tanh(v_x), math.tanh(v_x))
     self.assertEqual(min(v_x, v_y), min(v_x, v_y))
     self.assertEqual(max(v_x, v_y), max(v_x, v_y))
     self.assertEqual(
         if_then_else(Expression(v_x) > Expression(v_y), v_x, v_y),
         v_x if v_x > v_y else v_y)
Пример #6
0
def rambusOscillatorTanh(numStages, g_cc=0.5, numSolutions="all", a=-5.0):
    epsilon = 1e-14
    start = time.time()
    g_fwd = 1.0
    lenV = numStages * 2
    vs = []
    vfwds = []
    vccs = []
    for i in range(lenV):
        vs.append(Variable("v" + str(i)))
        vfwds.append(Variable("vfwd" + str(i)))
        vccs.append(Variable("vcc" + str(i)))

    allConstraints = []

    # Store rambus oscillator constraints
    for i in range(lenV):
        allConstraints.append(vs[i] >= -1)
        allConstraints.append(vs[i] <= 1)
        fwdInd = (i - 1) % lenV
        ccInd = (i + lenV // 2) % lenV
        allConstraints.append(vfwds[i] == tanh(a * vs[fwdInd]))
        allConstraints.append(vccs[i] == tanh(a * vs[ccInd]))
        allConstraints.append(g_fwd * vfwds[i] + (-g_fwd - g_cc) * vs[i] +
                              g_cc * vccs[i] == 0)

    allSolutions = []
    while True:
        if numSolutions != "all" and len(allSolutions) == numSolutions:
            break

        # Store constraints pruning search space so that
        # old hyperrectangles are not considered
        excludingConstraints = []
        for solution in allSolutions:
            singleExcludingConstraints = []
            for i in range(lenV):
                singleExcludingConstraints.append(vs[i] < solution[i][0])
                singleExcludingConstraints.append(vs[i] > solution[i][1])
            excludingConstraints.append(singleExcludingConstraints)

        # Add all the rambus oscillator constraints
        f_sat = logical_and(*allConstraints)
        # Add constraints so that old hyperrectangles are not considered
        if len(excludingConstraints) > 0:
            for constraints in excludingConstraints:
                f_sat = logical_and(f_sat, logical_or(*constraints))

        #print ("f_sat")
        #print (f_sat)
        result = CheckSatisfiability(f_sat, epsilon)
        #print (result)
        if result is None:
            break
        hyper = np.zeros((lenV, 2))
        for i in range(lenV):
            hyper[i, :] = [
                result[vs[i]].lb() - 2 * epsilon,
                result[vs[i]].ub() + 2 * epsilon
            ]

        #print ("hyper", hyper)
        allSolutions.append(hyper)

        print("num solutions found", len(allSolutions))

    end = time.time()
    print("time taken", end - start)
    return allSolutions
Пример #7
0
def tanhDer(var, param):
    return (1 - tanh(var * param) * tanh(var * param)) * param